Search in sources :

Example 16 with TreeViewerColumn

use of org.eclipse.jface.viewers.TreeViewerColumn in project linuxtools by eclipse.

the class CachegrindViewPart method createPartControl.

@Override
public void createPartControl(Composite parent) {
    Composite top = new Composite(parent, SWT.NONE);
    GridLayout topLayout = new GridLayout();
    topLayout.marginHeight = topLayout.marginWidth = 0;
    top.setLayout(topLayout);
    top.setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer = new TreeViewer(top, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    labelProvider = new CachegrindLabelProvider();
    ColumnViewerToolTipSupport.enableFor(viewer);
    Tree tree = viewer.getTree();
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);
    // $NON-NLS-1$
    column.getColumn().setText(Messages.getString("CachegrindViewPart.Location"));
    column.getColumn().setWidth(COLUMN_SIZE * 4);
    column.getColumn().setResizable(true);
    column.getColumn().addSelectionListener(getHeaderListener());
    column.setLabelProvider(labelProvider);
    contentProvider = new CachegrindTreeContentProvider();
    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(labelProvider);
    viewer.setAutoExpandLevel(2);
    doubleClickListener = event -> {
        Object selection = ((StructuredSelection) event.getSelection()).getFirstElement();
        String path = null;
        int line = 0;
        if (selection instanceof CachegrindFile) {
            path = ((CachegrindFile) selection).getPath();
        } else if (selection instanceof CachegrindLine) {
            CachegrindLine element = (CachegrindLine) selection;
            CachegrindFile file = (CachegrindFile) element.getParent().getParent();
            path = file.getPath();
            line = element.getLine();
        } else if (selection instanceof CachegrindFunction) {
            CachegrindFunction function = (CachegrindFunction) selection;
            path = ((CachegrindFile) function.getParent()).getPath();
            if (function.getModel() instanceof ISourceReference) {
                ISourceReference model = (ISourceReference) function.getModel();
                try {
                    ISourceRange sr = model.getSourceRange();
                    if (sr != null) {
                        line = sr.getStartLine();
                    }
                } catch (CModelException e1) {
                    e1.printStackTrace();
                }
            }
        }
        if (path != null) {
            try {
                ProfileUIUtils.openEditorAndSelect(path, line, ValgrindUIPlugin.getDefault().getProfiledProject());
            } catch (BadLocationException | CoreException e2) {
                e2.printStackTrace();
            }
        }
    };
    viewer.addDoubleClickListener(doubleClickListener);
    expandAction = new ExpandAction(viewer);
    collapseAction = new CollapseAction(viewer);
    MenuManager manager = new MenuManager();
    manager.addMenuListener(manager1 -> {
        ITreeSelection selection = (ITreeSelection) viewer.getSelection();
        ICachegrindElement element = (ICachegrindElement) selection.getFirstElement();
        if (contentProvider.hasChildren(element)) {
            manager1.add(expandAction);
            manager1.add(collapseAction);
        }
    });
    manager.setRemoveAllWhenShown(true);
    Menu contextMenu = manager.createContextMenu(viewer.getTree());
    viewer.getControl().setMenu(contextMenu);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) CachegrindFunction(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction) CModelException(org.eclipse.cdt.core.model.CModelException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) CachegrindFile(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile) Tree(org.eclipse.swt.widgets.Tree) CachegrindLine(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine) Menu(org.eclipse.swt.widgets.Menu) ISourceRange(org.eclipse.cdt.core.model.ISourceRange) ICachegrindElement(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement) Composite(org.eclipse.swt.widgets.Composite) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) CoreException(org.eclipse.core.runtime.CoreException) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) ExpandAction(org.eclipse.linuxtools.valgrind.ui.ExpandAction) ISourceReference(org.eclipse.cdt.core.model.ISourceReference) CollapseAction(org.eclipse.linuxtools.valgrind.ui.CollapseAction) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 17 with TreeViewerColumn

use of org.eclipse.jface.viewers.TreeViewerColumn in project linuxtools by eclipse.

the class BasePropertySection method createTableTreeViewer.

private TreeViewer createTableTreeViewer(final Composite container) {
    final TreeViewer treeViewer = new TreeViewer(container, SWT.V_SCROLL | SWT.H_SCROLL);
    final Tree tree = treeViewer.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    final TreeViewerColumn propertyColumn = new TreeViewerColumn(treeViewer, SWT.BORDER);
    propertyColumn.getColumn().setWidth(150);
    propertyColumn.getColumn().setText("Property");
    propertyColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof Object[]) {
                final Object property = ((Object[]) element)[0];
                return property.toString();
            }
            return super.getText(element);
        }
    });
    final TreeViewerColumn valueColumn = new TreeViewerColumn(treeViewer, SWT.BORDER);
    valueColumn.getColumn().setWidth(500);
    valueColumn.getColumn().setText("Value");
    valueColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof Object[]) {
                final Object value = ((Object[]) element)[1];
                // do not show values of a collection. There will be nested elements in the treeview for them.
                if (value instanceof Collection) {
                    return "";
                } else if (value instanceof String || value instanceof Boolean || value instanceof Integer) {
                    return value.toString();
                }
                return "";
            }
            return super.getText(element);
        }
    });
    return treeViewer;
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Tree(org.eclipse.swt.widgets.Tree) Collection(java.util.Collection) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn)

Aggregations

TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)17 Composite (org.eclipse.swt.widgets.Composite)10 TreeViewer (org.eclipse.jface.viewers.TreeViewer)9 GridLayout (org.eclipse.swt.layout.GridLayout)8 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)7 GridData (org.eclipse.swt.layout.GridData)7 TreeColumn (org.eclipse.swt.widgets.TreeColumn)7 Tree (org.eclipse.swt.widgets.Tree)6 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)5 ArrayList (java.util.ArrayList)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 CellEditor (org.eclipse.jface.viewers.CellEditor)3 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)3 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)3 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)3 EditingSupport (org.eclipse.jface.viewers.EditingSupport)3 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3