Example usage for org.eclipse.jface.viewers StructuredViewer reveal

List of usage examples for org.eclipse.jface.viewers StructuredViewer reveal

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredViewer reveal.

Prototype

public abstract void reveal(Object element);

Source Link

Document

Ensures that the given element is visible, scrolling the viewer if necessary.

Usage

From source file:net.sf.eclipsensis.viewer.StructuredViewerUpDownMover.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
protected final void updateElements(List<T> elements, List<T> move, boolean isDown) {
    StructuredViewer viewer = getViewer();
    updateStructuredViewerInput((S) viewer.getInput(), elements, move, isDown);
    refreshViewer(viewer, elements, move, isDown);
    if (!Common.isEmptyCollection(move)) {
        viewer.setSelection(new StructuredSelection(move));
        viewer.reveal(move.get(isDown ? move.size() - 1 : 0));
    }//  www  .j a  v a  2 s  .  co m
}

From source file:org.eclipse.debug.internal.ui.views.variables.VariablesView.java

License:Open Source License

/**
 * Make sure the currently selected item in the tree is visible.
 *///from   w w w  .  j a  v  a2 s  .c o  m
protected void revealTreeSelection() {
    StructuredViewer viewer = (StructuredViewer) getViewer();
    if (viewer != null) {
        ISelection selection = viewer.getSelection();
        if (selection instanceof IStructuredSelection) {
            Object selected = ((IStructuredSelection) selection).getFirstElement();
            if (selected != null) {
                viewer.reveal(selected);
            }
        }
    }
}

From source file:org.eclipse.net4j.util.ui.views.MultiViewersView.java

License:Open Source License

public void revealElement(final Object element) {
    try {/*from w  w  w  .  j  av a2 s  . c o m*/
        final StructuredViewer viewer = getCurrentViewer();
        if (viewer != null) {
            getDisplay().asyncExec(new Runnable() {
                public void run() {
                    try {
                        viewer.reveal(element);
                    } catch (RuntimeException ignore) {
                    }
                }
            });
        }
    } catch (RuntimeException ignore) {
    }
}

From source file:org.ejs.gui.common.SwtDialogUtils.java

License:Open Source License

/**
 * Sometimes a viewer does not get populated until
 * some time after its input is set, making {@link StructuredViewer#reveal(Object)}
 * useless.  This routine reveals a selection only after
 * the viewer is actually populated.//from   w  ww .  j a v a  2s  .co m
 */
public static void revealOncePopulated(final Timer timer, int initialDelayMs, final StructuredViewer viewer,
        final Object selection) {
    // workaround: GTK does not realize the elements for a while
    final Control control = viewer.getControl();
    final TimerTask task = new TimerTask() {
        TimerTask xx = this;

        /* (non-Javadoc)
         * @see java.util.TimerTask#run()
         */
        @Override
        public void run() {
            if (control.isDisposed()) {
                xx.cancel();
                return;
            }

            control.getDisplay().asyncExec(new Runnable() {
                public void run() {
                    boolean cancel = false;
                    if (control.isDisposed()) {
                        cancel = true;
                    } else {
                        boolean populated = false;
                        if (control instanceof Tree && ((Tree) control).getItemCount() > 0
                                && ((Tree) control).getItem(0).getBounds().height > 0)
                            populated = true;
                        else if (control instanceof Table && ((Table) control).getItemCount() > 0
                                && ((Table) control).getItem(0).getBounds().height > 0)
                            populated = true;

                        if (populated) {
                            viewer.reveal(selection);
                            cancel = true;
                        }
                    }

                    if (cancel) {
                        xx.cancel();
                    }
                }
            });
        }
    };
    timer.scheduleAtFixedRate(task, initialDelayMs, 500);
}

From source file:org.fusesource.ide.foundation.ui.util.Viewers.java

License:Open Source License

/**
 * Reveals the given element in the view t
 *///from   w ww .j av a  2s .c o  m
public static void reveal(Viewer viewer, Object element) {
    if (viewer instanceof StructuredViewer) {
        StructuredViewer sv = (StructuredViewer) viewer;
        sv.reveal(element);
    }
}

From source file:v9t9.gui.client.swt.shells.DemoSelector.java

License:Open Source License

/**
 * @param viewer//from w w w .j  av a 2  s.co m
 * @param control
 * @param realModules
 */
protected void addIterativeSearch(final StructuredViewer viewer, Control control) {
    control.addKeyListener(new KeyAdapter() {
        StringBuilder search = new StringBuilder();
        int index = 0;
        IDemo[] demos;

        @Override
        public void keyPressed(KeyEvent e) {
            int direction = 1;
            if (demos == null) {
                demos = demoManager.getDemos();
            }
            if (e.keyCode == '\b') {
                search.setLength(0);
                index = 0;
                e.doit = e.keyCode != '\b';
                demos = demoManager.getDemos();
            } else if (e.keyCode == SWT.ARROW_DOWN) {
                direction = 1;
                e.doit = false;
            } else if (e.keyCode == SWT.ARROW_UP) {
                direction = -1;
                e.doit = false;
            } else if (e.character >= 32 && e.character < 127) {
                search.append(e.character);
                e.doit = false;
            } else {
                return;
            }

            int end = (index + demos.length - 1) % demos.length;
            String searchString = search.toString().toLowerCase();
            if (searchString.length() > 0) {
                for (int i = index; i != end; i = (i + 1) % demos.length) {
                    IDemo m = demos[i];
                    if (m.getName().toLowerCase().contains(searchString)) {
                        viewer.setSelection(new StructuredSelection(m), true);
                        viewer.reveal(m);
                        index = i;
                        break;
                    }
                }
            } else {
                int count = demos.length;
                if (getDisplay().getFocusControl() != filterText) {
                    // not yet in tree
                    index += direction;
                }
                do {
                    index = (index + demos.length) % demos.length;
                    IDemo m = demos[index];
                    viewer.setSelection(new StructuredSelection(m), true);
                    viewer.reveal(m);
                    if (viewer.testFindItem(m) != null) // TODO: cleaner way to see what's not filtered
                        break;
                    index += direction;
                } while (count-- > 0);
            }
        }
    });
}