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());
}
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);
}
}
}
}
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);
}
}
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);
}
}
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());
}
});
}
Aggregations