Search in sources :

Example 81 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project linuxtools by eclipse.

the class CModelLabelsTest method checkLabelProvider.

private static void checkLabelProvider(TreeViewer viewer, TreePath path, ICachegrindElement element) {
    // expand only the interesting item
    viewer.expandToLevel(element, AbstractTreeViewer.ALL_LEVELS);
    TreeSelection selection = new TreeSelection(path);
    viewer.setSelection(selection);
    TreeItem item = viewer.getTree().getSelection()[0];
    // ensure the CElementLabelProvider is called correctly
    CElementLabelProvider provider = ((CachegrindLabelProvider) viewer.getLabelProvider(0)).getCLabelProvider();
    assertEquals(provider.getText(element.getModel()), item.getText());
    assertEquals(provider.getImage(element.getModel()), item.getImage());
}
Also used : CachegrindLabelProvider(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindLabelProvider) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeSelection(org.eclipse.jface.viewers.TreeSelection) CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider)

Example 82 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project linuxtools by eclipse.

the class MetadataPage method refreshTree.

/**
 * Refresh the tree. This includes removing the expand button of a
 * category if there are no tags placed under it.
 */
private void refreshTree() {
    // expand categories with no tags under them to remove expand button
    for (TreeItem treeItem : tagsTree.getItems()) {
        if (treeItem.getData() instanceof CreaterepoTreeCategory) {
            CreaterepoTreeCategory category = (CreaterepoTreeCategory) treeItem.getData();
            if (category.getTags().isEmpty()) {
                tagsTreeViewer.expandToLevel(category, 1);
                tagsTreeViewer.update(category, null);
            }
        }
    }
}
Also used : CreaterepoTreeCategory(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory) TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 83 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project knime-core by knime.

the class TreeViewerUpdater method update.

/**
 * Updates and filters the tree
 *
 * @param shouldExpand whether the tree should be expanded
 * @param scrollToRoot if the viewer should be scrolled to the root element on update
 */
static void update(final TreeViewer viewer, final boolean shouldExpand, final boolean scrollToRoot) {
    Point backup = null;
    if (IS_OS_WINDOWS) {
        Rectangle bounds = viewer.getTree().getParent().getShell().getBounds();
        // Bug 2809 -
        // on windows the search is much slower if the cursor is within the KNIME window.
        // so we just set it somewhere outside and restore it afterwards
        backup = Display.getCurrent().getCursorLocation();
        Display.getCurrent().setCursorLocation(new Point(bounds.x - 2, bounds.y - 2));
    }
    viewer.getControl().setRedraw(false);
    try {
        viewer.refresh();
        if (shouldExpand) {
            viewer.expandAll();
        }
        // scroll to root
        if (viewer.getTree().getItemCount() > 0 && scrollToRoot) {
            TreeItem item = viewer.getTree().getItem(0);
            viewer.getTree().showItem(item);
        }
    } finally {
        if (backup != null) {
            Display.getCurrent().setCursorLocation(backup);
        }
        viewer.getControl().setRedraw(true);
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 84 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project knime-core by knime.

the class TreeViewerUpdater method collapseAndUpdate.

/**
 * Optionally collapses, updates and filters and again expands the tree.
 *
 * @param shouldExpand whether the tree should be expanded
 * @param update whether the tree should be updated (live update)
 * @param collapse whether the tree should be collapsed completely before updating it
 */
static void collapseAndUpdate(final TreeViewer viewer, final boolean update, final boolean collapse, final boolean shouldExpand) {
    Point backup = null;
    if (IS_OS_WINDOWS) {
        Rectangle bounds = viewer.getTree().getParent().getShell().getBounds();
        // Bug 2809 -
        // on windows the search is much slower if the cursor is within the KNIME window.
        // so we just set it somewhere outside and restore it afterwards
        backup = Display.getCurrent().getCursorLocation();
        Display.getCurrent().setCursorLocation(new Point(bounds.x - 2, bounds.y - 2));
    }
    viewer.getControl().setRedraw(false);
    try {
        if (collapse) {
            viewer.collapseAll();
        }
        if (update) {
            viewer.refresh();
            if (shouldExpand) {
                viewer.expandAll();
            }
            // scroll to root
            if (viewer.getTree().getItemCount() > 0) {
                TreeItem item = viewer.getTree().getItem(0);
                viewer.getTree().showItem(item);
            }
        }
    } finally {
        if (backup != null) {
            Display.getCurrent().setCursorLocation(backup);
        }
        viewer.getControl().setRedraw(true);
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 85 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project eclipse.platform.swt by eclipse.

the class GraphicsExample method createTabList.

void createTabList(Composite parent) {
    tabList = new Tree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    Arrays.sort(tabs, (tab0, tab1) -> tab0.getText().compareTo(tab1.getText()));
    HashSet<String> set = new HashSet<>();
    for (GraphicsTab tab : tabs) {
        set.add(tab.getCategory());
    }
    String[] categories = new String[set.size()];
    set.toArray(categories);
    Arrays.sort(categories);
    for (String text : categories) {
        TreeItem item = new TreeItem(tabList, SWT.NONE);
        item.setText(text);
    }
    tabs_in_order = new ArrayList<>();
    TreeItem[] items = tabList.getItems();
    for (TreeItem item : items) {
        for (GraphicsTab tab : tabs) {
            if (item.getText().equals(tab.getCategory())) {
                TreeItem item1 = new TreeItem(item, SWT.NONE);
                item1.setText(tab.getText());
                item1.setData(tab);
                tabs_in_order.add(tab);
            }
        }
    }
    tabList.addListener(SWT.Selection, event -> {
        TreeItem item = (TreeItem) event.item;
        if (item != null) {
            GraphicsTab gt = (GraphicsTab) item.getData();
            if (gt == tab)
                return;
            setTab((GraphicsTab) item.getData());
        }
    });
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Tree(org.eclipse.swt.widgets.Tree) HashSet(java.util.HashSet)

Aggregations

TreeItem (org.eclipse.swt.widgets.TreeItem)226 Tree (org.eclipse.swt.widgets.Tree)71 Point (org.eclipse.swt.graphics.Point)56 TreeColumn (org.eclipse.swt.widgets.TreeColumn)30 GridData (org.eclipse.swt.layout.GridData)29 Test (org.junit.Test)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)27 ArrayList (java.util.ArrayList)24 GridLayout (org.eclipse.swt.layout.GridLayout)23 Composite (org.eclipse.swt.widgets.Composite)22 TableItem (org.eclipse.swt.widgets.TableItem)21 Button (org.eclipse.swt.widgets.Button)20 Table (org.eclipse.swt.widgets.Table)20 TreeViewer (org.eclipse.jface.viewers.TreeViewer)19 FillLayout (org.eclipse.swt.layout.FillLayout)19 Label (org.eclipse.swt.widgets.Label)18 Group (org.eclipse.swt.widgets.Group)17 Text (org.eclipse.swt.widgets.Text)17 SelectionListener (org.eclipse.swt.events.SelectionListener)16 Rectangle (org.eclipse.swt.graphics.Rectangle)16