use of org.eclipse.swt.widgets.TreeItem in project eclipse.platform.text by eclipse.
the class RetrieverAction method extractSearchTextFromWidget.
protected final String extractSearchTextFromWidget(Control control) {
String sel = null;
if (control instanceof Combo) {
Combo combo = (Combo) control;
sel = combo.getText();
Point selection = combo.getSelection();
sel = sel.substring(selection.x, selection.y);
}
if (control instanceof CCombo) {
CCombo combo = (CCombo) control;
sel = combo.getText();
Point selection = combo.getSelection();
sel = sel.substring(selection.x, selection.y);
} else if (control instanceof Text) {
Text text = (Text) control;
sel = text.getSelectionText();
} else if (control instanceof FormText) {
FormText text = (FormText) control;
sel = text.getSelectionText();
} else if (control instanceof StyledText) {
StyledText text = (StyledText) control;
sel = text.getSelectionText();
} else if (control instanceof Tree) {
Tree tree = (Tree) control;
TreeItem[] s = tree.getSelection();
if (s.length > 0) {
sel = s[0].getText();
}
} else if (control instanceof Table) {
Table tree = (Table) control;
TableItem[] s = tree.getSelection();
if (s.length > 0) {
sel = s[0].getText();
}
} else if (control instanceof List) {
List list = (List) control;
String[] s = list.getSelection();
if (s.length > 0) {
sel = s[0];
}
}
if (sel != null) {
sel = trimSearchString(sel);
}
return sel;
}
use of org.eclipse.swt.widgets.TreeItem in project eclipse.platform.text by eclipse.
the class SelectAllAction method run.
/**
* Selects all resources in the view.
*/
@Override
public void run() {
if (fViewer == null || fViewer.getControl().isDisposed()) {
return;
}
if (fViewer instanceof TreeViewer) {
ArrayList<TreeItem> allVisible = new ArrayList<>();
Tree tree = ((TreeViewer) fViewer).getTree();
collectExpandedAndVisible(tree.getItems(), allVisible);
tree.setSelection(allVisible.toArray(new TreeItem[allVisible.size()]));
} else if (fViewer instanceof TableViewer) {
((TableViewer) fViewer).getTable().selectAll();
// force viewer selection change
fViewer.setSelection(fViewer.getSelection());
}
}
use of org.eclipse.swt.widgets.TreeItem in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method refresh.
/**
* Refreshes the template tree contents.
*/
private void refresh() {
storeCollapseState();
fTreeViewer.getTree().setRedraw(false);
try {
fTreeViewer.refresh();
TreeItem[] items = fTreeViewer.getTree().getItems();
for (int i = 0; i < items.length; i++) {
boolean isExpanded = !fPreferenceStore.getBoolean(CONTEXT_COLLAPSE_PREF_ID + ((TemplateContextType) items[i].getData()).getId());
if (isExpanded)
fTreeViewer.expandToLevel(items[i].getData(), AbstractTreeViewer.ALL_LEVELS);
else
fTreeViewer.collapseToLevel(items[i].getData(), AbstractTreeViewer.ALL_LEVELS);
}
} finally {
fTreeViewer.getTree().setRedraw(true);
}
}
use of org.eclipse.swt.widgets.TreeItem in project linuxtools by eclipse.
the class AbstractSTDataView method fillContextMenu.
/**
* Fills the context menu (mouse right-click)
* <p>
* Subclasses may extend it. don't forget to call <code>super.fillContextMenu(...)</code>
* </p>
*
* @param manager The IMenuManager to fill.
* @since 6.0
*/
protected void fillContextMenu(IMenuManager manager) {
Control control = stViewer.getViewer().getControl();
if (control instanceof Tree) {
Tree tree = (Tree) control;
TreeItem[] selection = tree.getSelection();
if (selection != null && selection.length > 0) {
if (collapseSelectionAction != null) {
manager.add(collapseSelectionAction);
}
if (expandSelectionAction != null) {
manager.add(expandSelectionAction);
}
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
if (copyToAction != null) {
manager.add(copyToAction);
}
}
}
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
use of org.eclipse.swt.widgets.TreeItem in project linuxtools by eclipse.
the class AbstractSTTreeViewer method createColumns.
/**
* Create the columns in the tree.
*/
@Override
protected void createColumns() {
Tree tree = getViewer().getTree();
TableLayout layout = new TableLayout();
tree.setLayout(layout);
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
for (int i = 0; i < getAllFields().length; i++) {
ISTDataViewersField field = getAllFields()[i];
TreeColumn tc = new TreeColumn(tree, field.getAlignment(), i);
tc.setText(field.getColumnHeaderText());
tc.setToolTipText(field.getColumnHeaderTooltip());
tc.setImage(field.getColumnHeaderImage());
tc.setWidth(field.getPreferredWidth());
tc.setResizable(true);
tc.setMoveable(true);
tc.addSelectionListener(createHeaderListener());
tc.setData(field);
// defining the column label provider.
// this has to be done after setting the column's data.
TreeViewerColumn viewerColumn = new TreeViewerColumn(getViewer(), tc);
viewerColumn.setLabelProvider(createColumnLabelProvider(tc));
}
tree.addMouseMoveListener(e -> {
Tree tree1 = (Tree) e.widget;
TreeItem item = tree1.getItem(new Point(e.x, e.y));
if (item == null) {
return;
}
tree1.setCursor(e.display.getSystemCursor(SWT.CURSOR_ARROW));
});
}
Aggregations