Example usage for org.eclipse.jface.viewers ITreeSelection getPaths

List of usage examples for org.eclipse.jface.viewers ITreeSelection getPaths

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ITreeSelection getPaths.

Prototype

public TreePath[] getPaths();

Source Link

Document

Returns the paths in this selection

Usage

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage.java

License:Open Source License

/**
 * Sets the outline selection./*from  w  ww .  j a  v  a  2  s.com*/
 *
 * @param selection Only {@link ITreeSelection} will be used, otherwise the
 *   selection will be cleared (including a null selection).
 */
@Override
public void setSelection(ISelection selection) {
    // TreeViewer should be able to deal with a null selection, but let's make it safe
    if (selection == null) {
        selection = TreeSelection.EMPTY;
    }
    if (selection.equals(TreeSelection.EMPTY)) {
        return;
    }

    super.setSelection(selection);

    TreeViewer tv = getTreeViewer();
    if (tv == null || !(selection instanceof ITreeSelection) || selection.isEmpty()) {
        return;
    }

    // auto-reveal the selection
    ITreeSelection treeSel = (ITreeSelection) selection;
    for (TreePath p : treeSel.getPaths()) {
        tv.expandToLevel(p, 1);
    }
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage2.java

License:Open Source License

/**
 * Sets the outline selection.//from   w w w . ja  v  a  2  s. c  o m
 *
 * @param selection Only {@link ITreeSelection} will be used, otherwise the
 *   selection will be cleared (including a null selection).
 */
@Override
public void setSelection(ISelection selection) {
    // TreeViewer should be able to deal with a null selection, but let's make it safe
    if (selection == null) {
        selection = TreeSelection.EMPTY;
    }

    super.setSelection(selection);

    TreeViewer tv = getTreeViewer();
    if (tv == null || !(selection instanceof ITreeSelection) || selection.isEmpty()) {
        return;
    }

    // auto-reveal the selection
    ITreeSelection treeSel = (ITreeSelection) selection;
    for (TreePath p : treeSel.getPaths()) {
        tv.expandToLevel(p, 1);
    }
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.SelectionManager.java

License:Open Source License

/**
 * Sets the selection. It must be an {@link ITreeSelection} where each segment
 * of the tree path is a {@link CanvasViewInfo}. A null selection is considered
 * as an empty selection./*  w w w.j  a v a  2s . co  m*/
 * <p/>
 * This method is invoked by {@link LayoutCanvasViewer#setSelection(ISelection)}
 * in response to an <em>outside</em> selection (compatible with ours) that has
 * changed. Typically it means the outline selection has changed and we're
 * synchronizing ours to match.
 */
@Override
public void setSelection(ISelection selection) {
    if (mInsideUpdateSelection) {
        return;
    }

    boolean changed = false;
    try {
        mInsideUpdateSelection = true;

        if (selection == null) {
            selection = TreeSelection.EMPTY;
        }

        if (selection instanceof ITreeSelection) {
            ITreeSelection treeSel = (ITreeSelection) selection;

            if (treeSel.isEmpty()) {
                // Clear existing selection, if any
                if (!mSelections.isEmpty()) {
                    mSelections.clear();
                    mAltSelection = null;
                    updateActionsFromSelection();
                    redraw();
                }
                return;
            }

            boolean redoLayout = false;

            // Create a list of all currently selected view infos
            Set<CanvasViewInfo> oldSelected = new HashSet<CanvasViewInfo>();
            for (SelectionItem cs : mSelections) {
                oldSelected.add(cs.getViewInfo());
            }

            // Go thru new selection and take care of selecting new items
            // or marking those which are the same as in the current selection
            for (TreePath path : treeSel.getPaths()) {
                Object seg = path.getLastSegment();
                if (seg instanceof CanvasViewInfo) {
                    CanvasViewInfo newVi = (CanvasViewInfo) seg;
                    if (oldSelected.contains(newVi)) {
                        // This view info is already selected. Remove it from the
                        // oldSelected list so that we don't deselect it later.
                        oldSelected.remove(newVi);
                    } else {
                        // This view info is not already selected. Select it now.

                        // reset alternate selection if any
                        mAltSelection = null;
                        // otherwise add it.
                        mSelections.add(createSelection(newVi));
                        changed = true;
                    }
                    if (newVi.isInvisible()) {
                        redoLayout = true;
                    }
                } else {
                    // Unrelated selection (e.g. user clicked in the Project Explorer
                    // or something) -- just ignore these
                    return;
                }
            }

            // Deselect old selected items that are not in the new one
            for (CanvasViewInfo vi : oldSelected) {
                if (vi.isExploded()) {
                    redoLayout = true;
                }
                deselect(vi);
                changed = true;
            }

            if (redoLayout) {
                mCanvas.getEditorDelegate().recomputeLayout();
            }
        }
    } finally {
        mInsideUpdateSelection = false;
    }

    if (changed) {
        redraw();
        fireSelectionChanged();
        updateActionsFromSelection();
    }
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.refactoring.VisualRefactoring.java

License:Open Source License

public VisualRefactoring(IFile file, LayoutEditorDelegate editor, ITextSelection selection,
        ITreeSelection treeSelection) {
    mFile = file;//from w  w w. j a v a2  s .c  om
    mDelegate = editor;
    mProject = file.getProject();
    mSelection = selection;
    mTreeSelection = treeSelection;

    // Initialize mSelectionStart and mSelectionEnd based on the selection context, which
    // is either a treeSelection (when invoked from the layout editor or the outline), or
    // a selection (when invoked from an XML editor)
    if (treeSelection != null) {
        int end = Integer.MIN_VALUE;
        int start = Integer.MAX_VALUE;
        for (TreePath path : treeSelection.getPaths()) {
            Object lastSegment = path.getLastSegment();
            if (lastSegment instanceof CanvasViewInfo) {
                CanvasViewInfo viewInfo = (CanvasViewInfo) lastSegment;
                UiViewElementNode uiNode = viewInfo.getUiViewNode();
                if (uiNode == null) {
                    continue;
                }
                Node xmlNode = uiNode.getXmlNode();
                if (xmlNode instanceof IndexedRegion) {
                    IndexedRegion region = (IndexedRegion) xmlNode;

                    start = Math.min(start, region.getStartOffset());
                    end = Math.max(end, region.getEndOffset());
                }
            }
        }
        if (start >= 0) {
            mSelectionStart = start;
            mSelectionEnd = end;
            mOriginalSelectionStart = mSelectionStart;
            mOriginalSelectionEnd = mSelectionEnd;
        }
        if (selection != null) {
            mOriginalSelectionStart = selection.getOffset();
            mOriginalSelectionEnd = mOriginalSelectionStart + selection.getLength();
        }
    } else if (selection != null) {
        // TODO: update selection to boundaries!
        mSelectionStart = selection.getOffset();
        mSelectionEnd = mSelectionStart + selection.getLength();
        mOriginalSelectionStart = mSelectionStart;
        mOriginalSelectionEnd = mSelectionEnd;
    }

    mElements = initElements();
}

From source file:com.aptana.ide.syncing.ui.views.ConnectionPointComposite.java

License:Open Source License

public void drop(DropTargetEvent event) {
    IFileStore targetStore = null;//from w w w .j ava2  s  .co  m
    if (event.item == null) {
        targetStore = Utils.getFileStore((IAdaptable) fTreeViewer.getInput());
    } else {
        TreeItem target = (TreeItem) event.item;
        targetStore = getFolderStore((IAdaptable) target.getData());
    }
    if (targetStore == null) {
        return;
    }

    if (event.data instanceof ITreeSelection) {
        ITreeSelection selection = (ITreeSelection) event.data;
        TreePath[] paths = selection.getPaths();
        if (paths.length > 0) {
            List<IAdaptable> elements = new ArrayList<IAdaptable>();
            for (TreePath path : paths) {
                boolean alreadyIn = false;
                for (TreePath path2 : paths) {
                    if (!path.equals(path2) && path.startsWith(path2, null)) {
                        alreadyIn = true;
                        break;
                    }
                }
                if (!alreadyIn) {
                    elements.add((IAdaptable) path.getLastSegment());
                }
            }

            CopyFilesOperation operation = new CopyFilesOperation(getControl().getShell());
            operation.copyFiles(elements.toArray(new IAdaptable[elements.size()]), targetStore,
                    new JobChangeAdapter() {

                        @Override
                        public void done(IJobChangeEvent event) {
                            IOUIPlugin.refreshNavigatorView(fTreeViewer.getInput());
                            UIUtils.getDisplay().asyncExec(new Runnable() {

                                public void run() {
                                    refresh();
                                }
                            });
                        }
                    });
        }
    }
}

From source file:com.google.gwt.eclipse.oophm.views.hierarchical.LogContent.java

License:Open Source License

private void copyTreeSelectionToClipboard() {
    ITreeSelection selection = (ITreeSelection) treeViewer.getSelection();
    TreePath[] paths = selection.getPaths();

    StringBuffer buf = new StringBuffer();

    for (TreePath path : paths) {
        LogEntry<?> entry = (LogEntry<?>) path.getLastSegment();
        buf.append(createTabString(path.getSegmentCount() - 1));
        buf.append(entry.toString());//from w  w w  .java2  s. c om
        buf.append("\n");
    }

    if (buf.length() > 0) {
        buf.deleteCharAt(buf.length() - 1); // take off last \n
    }

    copyToClipboard(buf.toString());
}

From source file:com.mercatis.lighthouse3.security.ui.editors.pages.AbstractAccessorBasedPermissionEditorPage.java

License:Apache License

/**
 * Opens a {@link com.mercatis.lighthouse3.security.ui.editors.pages.AbstractPermissionEditorPage.SelectionDialog}
 *//*w w  w .  ja  va 2s .  c o m*/
public void addContext() {
    SelectionDialog selectContext = new SelectionDialog("Select Context");
    if (selectContext.open() == IDialogConstants.OK_ID) {
        ITreeSelection treeSelection = (ITreeSelection) selectContext.getSelection();
        String context = null;
        for (TreePath treePath : treeSelection.getPaths()) {
            context = treePathToString(treePath);
            selectedAccessor.addContext(context);

            // Default Roles
            List<Role> viewRoles = Role.getViewRoles();
            for (Role role : viewRoles) {
                selectedAccessor.addRole(role.roleAsString(), context);
            }
        }
        contextViewer.setInput(selectedAccessor.getContexts());
        contextViewer.refresh();
        if (context != null) {
            contextViewer.setSelection(new StructuredSelection(context), true);
        }
        getEditor().editorDirtyStateChanged();
    }
}

From source file:com.mercatis.lighthouse3.security.ui.editors.pages.AbstractContextBasedPermissionEditorPage.java

License:Apache License

@Override
protected void createLeftSection(ScrolledForm form, FormToolkit toolkit) {
    Section section = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
    section.clientVerticalSpacing = 5;/*  ww  w .j a  v a 2s. c  om*/
    section.marginHeight = 3;
    section.marginWidth = 3;
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    section.setLayoutData(gd);
    section.setText("Context Path");

    Composite client = toolkit.createComposite(section);
    toolkit.paintBordersFor(client);
    client.setLayout(new FillLayout());

    final TreeViewer contextViewer = new TreeViewer(toolkit.createTree(client, SWT.SINGLE | SWT.BORDER));
    contextViewer.setContentProvider(new ContextContentProvider());
    contextViewer.setLabelProvider(new WorkbenchLabelProvider());
    contextViewer.setInput(lighthouseDomain);
    contextViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("unchecked")
        public void selectionChanged(SelectionChangedEvent event) {
            ITreeSelection selection = (ITreeSelection) event.getSelection();
            for (TreePath treePath : selection.getPaths()) {
                selectedContext = treePathToString(treePath);

                IStructuredSelection currentAccessorSelection = (IStructuredSelection) getAccessorViewer()
                        .getSelection();
                getAccessorViewer().setInput(getAccessorsForContext(selectedContext));
                getAccessorViewer().setSelection(currentAccessorSelection, true);
                selectedAccessor = (Accessor) ((IStructuredSelection) getAccessorViewer().getSelection())
                        .getFirstElement();
                refreshRolesForSelectedAccessorAndContext();
            }
            getEditor().editorDirtyStateChanged();
        }
    });

    section.setClient(client);
}

From source file:com.mercatis.lighthouse3.ui.environment.handlers.RemoveDeploymentHandler.java

License:Apache License

public Object execute(ExecutionEvent event) throws ExecutionException {
    preExecution(event);//from w  w w  . j ava2 s .com

    boolean selectedDeploymentPartOfStatus = false;
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof TreeSelection) {
        ITreeSelection treeSelection = (ITreeSelection) selection;
        List<TreePath> paths = new ArrayList<TreePath>(Arrays.asList(treeSelection.getPaths()));

        // remove all paths that do not end in a deployment..
        for (Iterator<TreePath> it = paths.iterator(); it.hasNext();) {
            if (!(it.next().getLastSegment() instanceof Deployment)) {
                it.remove();
            }
        }

        // remove all paths where the selected deployment is part of a status..
        for (Iterator<TreePath> it = paths.iterator(); it.hasNext();) {
            TreePath path = it.next();
            Deployment deployment = (Deployment) path.getLastSegment();
            path = path.getParentPath();
            while (path != null) {
                Object element = path.getLastSegment();
                if (element instanceof StatusCarrier) {
                    StatusCarrier carrier = (StatusCarrier) element;
                    StatusRegistry registry = RegistryFactoryServiceUtil.getRegistryFactoryService(
                            StatusRegistryFactoryService.class, deployment.getLighthouseDomain(), this);
                    List<Status> statuus = registry.getStatusForCarrier(carrier);
                    for (Status status : statuus) {
                        if (contextContainsDeployment(status.getOkTemplate(), deployment)) {
                            selectedDeploymentPartOfStatus = true;
                            it.remove();
                            break;
                        }

                        if (contextContainsDeployment(status.getErrorTemplate(), deployment)) {
                            selectedDeploymentPartOfStatus = true;
                            it.remove();
                            break;
                        }
                    }
                }
                path = path.getParentPath();
            }
        }

        // detach remaining deployments..
        for (Iterator<TreePath> it = paths.iterator(); it.hasNext();) {
            TreePath path = it.next();
            Deployment deployment = (Deployment) path.getLastSegment();
            DeploymentCarryingDomainModelEntity<?> carrier = (DeploymentCarryingDomainModelEntity<?>) path
                    .getParentPath().getLastSegment();
            carrier.detachDeployment(deployment);

            if (carrier instanceof Environment) {
                EnvironmentRegistry registry = RegistryFactoryServiceUtil.getRegistryFactoryService(
                        EnvironmentRegistryFactoryService.class, carrier.getLighthouseDomain(), this);
                registry.update((Environment) carrier);
            }
            if (carrier instanceof ProcessTask) {
                ProcessTaskRegistry registry = RegistryFactoryServiceUtil.getRegistryFactoryService(
                        ProcessTaskRegistryFactoryService.class, carrier.getLighthouseDomain(), this);
                registry.update((ProcessTask) carrier);
            }
            containers.add(domainService.getLighthouseDomainByEntity(carrier).getContainerFor(carrier));
        }

        // notify user on deployments that were not detached..
        if (selectedDeploymentPartOfStatus) {
            Shell shell = HandlerUtil.getActiveShell(event);
            MessageDialog.openWarning(shell, "Deployments not detached",
                    "One or more deployments were not detached because they are part of a status.");
        }
    }

    postExecution(event);
    return null;
}

From source file:com.metaaps.eoclipse.common.Util.java

License:Open Source License

public static Object scanTreePath(ITreeSelection selection, Class clazz) {
    TreePath[] treepaths = selection.getPaths();
    TreePath path = treepaths[0];
    for (int i = 0; i < path.getSegmentCount(); i++) {
        Object obj = path.getSegment(i);
        if (clazz.isInstance(obj)) {
            return obj;
        }// w  ww  .  ja  v a  2 s. c o  m
    }

    return null;
}