Search in sources :

Example 26 with ITreeSelection

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

the class NewProjectCreationPage method getSelectedWorkingSet.

/**
 * Try our best to set the working sets field to something sensible based on the
 * current selection.
 */
private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) {
    if (!(selection instanceof ITreeSelection)) {
        return EMPTY_WORKING_SET_ARRAY;
    }
    ITreeSelection treeSelection = (ITreeSelection) selection;
    if (treeSelection.isEmpty()) {
        return EMPTY_WORKING_SET_ARRAY;
    }
    List<?> elements = treeSelection.toList();
    if (elements.size() == 1) {
        Object element = elements.get(0);
        TreePath[] paths = treeSelection.getPathsFor(element);
        if (paths.length != 1 || paths[0].getSegmentCount() == 0) {
            return EMPTY_WORKING_SET_ARRAY;
        }
        Object candidate = paths[0].getSegment(0);
        if (!(candidate instanceof IWorkingSet)) {
            return EMPTY_WORKING_SET_ARRAY;
        }
        IWorkingSet workingSetCandidate = (IWorkingSet) candidate;
        if (!workingSetCandidate.isAggregateWorkingSet()) {
            return new IWorkingSet[] { workingSetCandidate };
        }
        return EMPTY_WORKING_SET_ARRAY;
    }
    ArrayList<IWorkingSet> result = new ArrayList<>();
    for (Object element : elements) {
        if (element instanceof IWorkingSet && !((IWorkingSet) element).isAggregateWorkingSet()) {
            result.add((IWorkingSet) element);
        }
    }
    if (!result.isEmpty()) {
        return result.toArray(new IWorkingSet[result.size()]);
    } else {
        return EMPTY_WORKING_SET_ARRAY;
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) ArrayList(java.util.ArrayList) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 27 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection 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 28 with ITreeSelection

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

the class ConnectionSettingsPropertySection method setInput.

@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
    super.setInput(part, selection);
    Assert.isTrue(selection instanceof ITreeSelection);
    Object input = ((ITreeSelection) selection).getFirstElement();
    Assert.isTrue(input instanceof IDockerConnection);
    IDockerConnection connection = (IDockerConnection) input;
    if (getTreeViewer() != null) {
        getTreeViewer().setInput(connection);
        getTreeViewer().expandAll();
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Example 29 with ITreeSelection

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

the class DockerExplorerView method refresh.

private void refresh(final IDockerConnection connection) {
    Display.getDefault().asyncExec(() -> {
        if (getCommonViewer().getTree() != null && !getCommonViewer().getTree().isDisposed()) {
            ITreeSelection old = (ITreeSelection) getCommonViewer().getSelection();
            getCommonViewer().refresh(connection, true);
            // Bug 499919 - Deselected connection after deleted tag
            // if we had an old selection and now we don't, assume that
            // operation in another view removed the item we had selected
            // so reset the connection so the Images and Containers views
            // don't reset to no connection.
            ITreeSelection current = (ITreeSelection) getCommonViewer().getSelection();
            if (!old.isEmpty() && current.isEmpty()) {
                getCommonViewer().setSelection(new StructuredSelection(connection));
            }
        }
    });
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 30 with ITreeSelection

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

the class DockerConnectionWatcher method selectionChanged.

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    final ITreeSelection treeSelection = (ITreeSelection) selection;
    if (treeSelection.isEmpty()) {
        setConnection(null);
        return;
    }
    final Object firstSegment = treeSelection.getPaths()[0].getFirstSegment();
    if (firstSegment instanceof IDockerConnection) {
        setConnection((IDockerConnection) firstSegment);
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Aggregations

ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)56 TreePath (org.eclipse.jface.viewers.TreePath)17 ISelection (org.eclipse.jface.viewers.ISelection)16 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 ArrayList (java.util.ArrayList)7 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)7 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)7 IFile (org.eclipse.core.resources.IFile)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)5 IProject (org.eclipse.core.resources.IProject)4 IStatus (org.eclipse.core.runtime.IStatus)4 TreeViewer (org.eclipse.jface.viewers.TreeViewer)4 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 TracePattern (org.erlide.tracing.core.mvc.model.TracePattern)4 Test (org.junit.Test)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)3 URL (java.net.URL)3 HashSet (java.util.HashSet)3