Search in sources :

Example 76 with TreeItem

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;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) TreeItem(org.eclipse.swt.widgets.TreeItem) FormText(org.eclipse.ui.forms.widgets.FormText) CCombo(org.eclipse.swt.custom.CCombo) Combo(org.eclipse.swt.widgets.Combo) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) FormText(org.eclipse.ui.forms.widgets.FormText) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) Tree(org.eclipse.swt.widgets.Tree) List(org.eclipse.swt.widgets.List)

Example 77 with TreeItem

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());
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) Tree(org.eclipse.swt.widgets.Tree) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 78 with TreeItem

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);
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Point(org.eclipse.swt.graphics.Point)

Example 79 with TreeItem

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));
}
Also used : Control(org.eclipse.swt.widgets.Control) TreeItem(org.eclipse.swt.widgets.TreeItem) Tree(org.eclipse.swt.widgets.Tree) Separator(org.eclipse.jface.action.Separator)

Example 80 with TreeItem

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));
    });
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) Point(org.eclipse.swt.graphics.Point) TableLayout(org.eclipse.jface.viewers.TableLayout) Point(org.eclipse.swt.graphics.Point) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn)

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