Example usage for org.eclipse.jface.viewers TreePath equals

List of usage examples for org.eclipse.jface.viewers TreePath equals

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TreePath equals.

Prototype

@Override
    public boolean equals(Object other) 

Source Link

Usage

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  a  va  2 s.  c  o 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.nokia.s60ct.search.gui.SearchPane.java

License:Open Source License

public SelectReturn singleSelect(Object object) {

    try {// w w  w. j av a2 s . c o  m
        activatingUi = true;
        Iterator<IObjectView> views = ObjectViewRegistry.getInstance().getViewsFor(object).iterator();

        if (views.hasNext()) {
            IObjectView view = views.next();
            if (view instanceof EObjectFocusDomain) {
                EObjectFocusDomain focusDomain = (EObjectFocusDomain) view;
                TreePath shown = focusDomain.canFocusUpTo(object);
                if (shown.equals(lastShown)) {
                    return SelectReturn.SHOWS_SAME_AS_BEFORE;
                }
                focusDomain.focus(shown, true); // quite heavy operation, do only if it makes difference
                lastShown = shown;
                return SelectReturn.SHOWS_NEW;
            } else {
                view.show(object, true);
                return SelectReturn.SHOWS_NEW; // we hope
            }
        }
    } finally {
        activatingUi = false;
    }
    return SelectReturn.CANNOT_SHOW;
}

From source file:com.nokia.s60ct.search.gui.SearchPane.java

License:Open Source License

private SelectReturn select(Object object) {
    if (search != null) {
        try {//from   www .  jav  a2s .c  o  m
            activatingUi = true;
            Iterator<IObjectView> views = ObjectViewRegistry.getInstance().getViewsFor(object).iterator();

            if (views.hasNext()) {
                IObjectView view = views.next();
                if (view instanceof EObjectFocusDomain) {
                    EObjectFocusDomain focusDomain = (EObjectFocusDomain) view;
                    TreePath shown = focusDomain.canFocusUpTo(object);
                    if (shown.equals(lastShown)) {
                        return SelectReturn.SHOWS_SAME_AS_BEFORE;
                    }
                    focusDomain.focus(shown, true); // quite heavy operation, do only if it makes difference
                    queryText.setFocus();
                    lastShown = shown;
                    return SelectReturn.SHOWS_NEW;
                } else {
                    view.show(object, true);
                    queryText.setFocus();
                    return SelectReturn.SHOWS_NEW; // we hope
                }
            }
        } finally {
            activatingUi = false;
        }
    }
    return SelectReturn.CANNOT_SHOW;
}

From source file:org.eclipe.debug.tests.viewer.model.TestModelUpdatesListener.java

License:Open Source License

public boolean checkCoalesced(TreePath path, int offset, int length) {
    for (Iterator itr = fChildrenUpdatesCompleted.iterator(); itr.hasNext();) {
        IChildrenUpdate update = (IChildrenUpdate) itr.next();
        if (path.equals(update.getElementPath()) && offset == update.getOffset()
                && length == update.getLength()) {
            return true;
        }//from   w  ww  . j a v a 2s . c o m
    }
    return false;
}

From source file:org.eclipe.debug.tests.viewer.model.TestModelUpdatesListener.java

License:Open Source License

public void addUpdates(IInternalTreeModelViewer viewer, TreePath path, TestElement element,
        ViewerFilter[] filters, int levels, int flags) {
    if (isFiltered(path.getLastSegment(), filters)) {
        return;//from   www .  j  a  v  a  2  s  .c  om
    }

    if (!path.equals(TreePath.EMPTY)) {
        if ((flags & LABEL_UPDATES) != 0) {
            fLabelUpdates.add(path);
        }
        if ((flags & HAS_CHILDREN_UPDATES) != 0) {
            fHasChildrenUpdatesScheduled.add(path);
        }

        if ((flags & STATE_UPDATES) != 0) {
            fStateUpdates.add(path);
        }
    }

    if (levels-- != 0) {
        TestElement[] children = element.getChildren();
        if (children.length > 0
                && (viewer == null || path.getSegmentCount() == 0 || viewer.getExpandedState(path))) {
            if ((flags & CHILD_COUNT_UPDATES) != 0) {
                fChildCountUpdatesScheduled.add(path);
            }
            if ((flags & CHILDREN_UPDATES) != 0) {
                Set childrenIndexes = new HashSet();
                for (int i = 0; i < children.length; i++) {
                    if (!isFiltered(children[i], filters)) {
                        childrenIndexes.add(new Integer(i));
                    }
                }
                fChildrenUpdatesScheduled.put(path, childrenIndexes);
            }

            for (int i = 0; i < children.length; i++) {
                addUpdates(viewer, path.createChildPath(children[i]), children[i], filters, levels, flags);
            }
        }

    }
}

From source file:org.eclipe.debug.tests.viewer.model.TreeModelViewerAutopopulateAgent.java

License:Open Source License

public void updateComplete(IViewerUpdate update) {
    if (update instanceof IChildrenCountUpdate) {
        TreePath path = update.getElementPath();
        ILazyTreePathContentProvider contentProvider = (ILazyTreePathContentProvider) fViewer
                .getContentProvider();/*from ww  w .  j a  va2s.c o m*/

        Widget[] items = fViewer.testFindItems(update.getElement());
        for (int i = 0; i < items.length; i++) {
            if (path.equals(getTreePath(items[i]))) {
                int itemCount = getItemChildCount(items[i]);
                for (int j = 0; j < itemCount; j++) {
                    contentProvider.updateElement(path, j);
                }
            }
        }
    }
}

From source file:org.eclipse.cdt.tests.dsf.vm.TestModelUpdatesListener.java

License:Open Source License

public void addUpdates(IInternalTreeModelViewer viewer, TreePath path, TestElement element, int levels,
        int flags) {
    if (!path.equals(TreePath.EMPTY)) {
        if ((flags & LABEL_UPDATES) != 0) {
            addLabelUpdate(path);/*from www. ja  v  a 2 s  .c o m*/
        }
        if ((flags & PROPERTY_UPDATES) != 0) {
            addPropertiesUpdate(path);
        }
        if ((flags & HAS_CHILDREN_UPDATES) != 0) {
            addHasChildrenUpdate(path);
        }
    }

    if (levels-- != 0) {
        TestElement[] children = element.getChildren();
        if (children.length > 0
                && (viewer == null || path.getSegmentCount() == 0 || viewer.getExpandedState(path))) {
            if ((flags & CHILD_COUNT_UPDATES) != 0) {
                addChildCountUpdate(path);
            }
            if ((flags & CHILDREN_UPDATES) != 0) {
                for (int i = 0; i < children.length; i++) {
                    addChildreUpdate(path, i);
                }
            }

            if ((flags & STATE_UPDATES) != 0 && viewer != null) {
                addStateUpdate(path);
            }

            for (int i = 0; i < children.length; i++) {
                addUpdates(viewer, path.createChildPath(children[i]), children[i], levels, flags);
            }
        }

    }
}

From source file:org.eclipse.debug.internal.ui.viewers.model.TreeModelLabelProvider.java

License:Open Source License

/**
  * Cancel any outstanding updates that are running for this element. 
 * @param elementPath Element to cancel updates for.
  *//*w ww. ja va  2s  . co  m*/
private void cancelPathUpdates(TreePath elementPath) {
    Assert.isTrue(fViewer.getDisplay().getThread() == Thread.currentThread());

    Iterator updatesInProgress = fUpdatesInProgress.iterator();
    while (updatesInProgress.hasNext()) {
        ILabelUpdate currentUpdate = (ILabelUpdate) updatesInProgress.next();
        if (elementPath.equals(currentUpdate.getElementPath())) {
            currentUpdate.cancel();
        }
    }
}

From source file:org.eclipse.debug.internal.ui.viewers.model.ViewerStateTracker.java

License:Open Source License

public void cancelRestore(final TreePath path, final int flags) {
    if (fInStateRestore) {
        // If we are currently processing pending state already, ignore 
        // cancelRestore requests.  These requests may be triggered in the viewer
        // by changes to the tree state (Bug 295585).
        return;/*ww  w  .j a v a  2s.  c om*/
    }

    if ((flags & IModelDelta.REVEAL) != 0 && fPendingSetTopItem != null) {
        fPendingSetTopItem.dispose();
        return;
    }

    // Nothing else to do 
    if (fPendingState == null) {
        return;
    }

    if ((flags & (IModelDelta.SELECT | IModelDelta.REVEAL)) != 0) {
        // If we're canceling reveal and this is waiting for updates to complete
        // then just cancel it and return

        // If we're canceling select or reveal, cancel it for all of pending deltas
        final int mask = flags & (IModelDelta.SELECT | IModelDelta.REVEAL);
        fPendingState.accept(new IModelDeltaVisitor() {
            public boolean visit(IModelDelta delta, int depth) {
                int deltaFlags = delta.getFlags();
                int newFlags = deltaFlags & ~mask;
                if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider
                        .DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) {
                    if (deltaFlags != newFlags) {
                        System.out.println("\tCANCEL: " + delta.getElement() + "(" //$NON-NLS-1$//$NON-NLS-2$
                                + Integer.toHexString(deltaFlags & mask) + ")"); //$NON-NLS-1$
                    }
                }
                ((ModelDelta) delta).setFlags(newFlags);
                return true;
            }
        });
    }
    if ((flags & ~(IModelDelta.SELECT | IModelDelta.REVEAL)) != 0) {
        final int mask = flags & ~(IModelDelta.SELECT | IModelDelta.REVEAL);
        // For other flags (EXPAND/COLLAPSE), cancel only from the matching path.
        fPendingState.accept(new IModelDeltaVisitor() {
            public boolean visit(IModelDelta delta, int depth) {
                if (depth < path.getSegmentCount()) {
                    // Descend until we reach a matching depth.
                    TreePath deltaPath = fContentProvider.getViewerTreePath(delta);
                    if (path.startsWith(deltaPath, null)) {
                        return true;
                    } else {
                        return false;
                    }
                } else if (depth == path.getSegmentCount()) {
                    TreePath deltaPath = fContentProvider.getViewerTreePath(delta);
                    if (deltaPath.equals(path)) {
                        int deltaFlags = delta.getFlags();
                        int newFlags = deltaFlags & ~mask;
                        if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider
                                .DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) {
                            if (deltaFlags != newFlags) {
                                System.out.println("\tCANCEL: " + delta.getElement() + "(" //$NON-NLS-1$//$NON-NLS-2$
                                        + Integer.toHexString(deltaFlags & mask) + ")"); //$NON-NLS-1$
                            }
                        }
                        ((ModelDelta) delta).setFlags(newFlags);
                        if ((flags & IModelDelta.EXPAND) != 0) {
                            // Descend delta to clear the EXPAND flags of a canceled expand
                            return true;
                        }
                    }
                    return false;
                } else {
                    // We're clearing out flags of a matching sub-tree
                    // assert (flags & IModelDelta.EXPAND) != 0;

                    if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider
                            .DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) {
                        if (delta.getFlags() != IModelDelta.NO_CHANGE) {
                            System.out.println("\tCANCEL: " + delta.getElement() + "(" //$NON-NLS-1$//$NON-NLS-2$
                                    + Integer.toHexString(delta.getFlags()) + ")"); //$NON-NLS-1$
                        }
                    }
                    ((ModelDelta) delta).setFlags(IModelDelta.NO_CHANGE);
                    return true;
                }
            }
        });
    }
}

From source file:org.eclipse.debug.internal.ui.views.launch.LaunchViewBreadcrumb.java

License:Open Source License

public Control createDropDownControl(Composite parent, final IBreadcrumbDropDownSite site, TreePath paramPath) {

    TreeViewerDropDown dropDownTreeViewer = new TreeViewerDropDown() {

        SubTreeModelViewer fDropDownViewer;

        protected TreeViewer createTreeViewer(Composite composite, int style, final TreePath path) {
            fDropDownViewer = new SubTreeModelViewer(composite,
                    SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL | SWT.POP_UP,
                    fTreeViewer.getPresentationContext());

            Object launchViewInput = fTreeViewer.getInput();
            fDropDownViewer.setInput(launchViewInput, path.getParentPath());

            ViewerFilter[] filters = fTreeViewer.getFilters();
            fDropDownViewer.setFilters(filters);

            ModelDelta stateDelta = new ModelDelta(launchViewInput, IModelDelta.NO_CHANGE);
            fTreeViewer.saveElementState(TreePath.EMPTY, stateDelta, IModelDelta.EXPAND | IModelDelta.SELECT);

            // If we do not want to expand the elements in the drop-down.
            // Prune the delta to only select the element in the 
            // top-most list.
            if (!fView.getBreadcrumbDropDownAutoExpand()) {
                final ModelDelta prunedDelta = new ModelDelta(launchViewInput, IModelDelta.NO_CHANGE);
                stateDelta.accept(new IModelDeltaVisitor() {
                    ModelDelta copy = prunedDelta;

                    public boolean visit(IModelDelta delta, int depth) {
                        TreePath deltaPath = getViewerTreePath(delta);
                        if (deltaPath.getSegmentCount() == 0) {
                            // skip copying the root element, only copy it's child count
                            copy.setChildCount(delta.getChildCount());
                        } else if (deltaPath.getSegmentCount() != 0 && path.startsWith(deltaPath, null)) {
                            // Build up the delta copy along the path of the drop-down element.
                            copy = copy.addNode(delta.getElement(), delta.getIndex(), delta.getFlags(),
                                    delta.getChildCount());
                        }/*w  w w.  j  a v a  2 s .c o m*/

                        // If the delta is for the drop-down element, set its select flag and stop traversing 
                        // the delta..
                        if (deltaPath.equals(path)) {
                            copy.setFlags(IModelDelta.SELECT | IModelDelta.REVEAL);
                            return false;
                        }

                        // Continue traversing the delta.
                        return true;
                    }

                    private TreePath getViewerTreePath(IModelDelta node) {
                        ArrayList list = new ArrayList();
                        IModelDelta parentDelta = node.getParentDelta();
                        while (parentDelta != null) {
                            list.add(0, node.getElement());
                            node = parentDelta;
                            parentDelta = node.getParentDelta();
                        }
                        return new TreePath(list.toArray());
                    }
                });
                stateDelta = prunedDelta;
            }

            fDropDownViewer.updateViewer(stateDelta);

            fDropDownViewer.addLabelUpdateListener(new ILabelUpdateListener() {
                public void labelUpdateComplete(ILabelUpdate update) {
                }

                public void labelUpdatesBegin() {
                }

                public void labelUpdateStarted(ILabelUpdate update) {
                }

                public void labelUpdatesComplete() {
                    new UIJob(fViewer.getControl().getDisplay(), "resize breadcrub dropdown") { //$NON-NLS-1$
                        {
                            setSystem(true);
                        }

                        public IStatus runInUIThread(IProgressMonitor monitor) {
                            site.updateSize();
                            return Status.OK_STATUS;
                        }
                    }.schedule();
                }
            });

            return fDropDownViewer;
        }

        protected void openElement(ISelection selection) {
            if (fTreeViewer.getControl().isDisposed()) {
                return;
            }

            if (selection != null && (selection instanceof ITreeSelection) && !selection.isEmpty()) {
                // Create the path to the root element of the drop-down viewer.  Need to calcualte
                // indexes and counts for the delta in order for the selection from the drop-down 
                // viewer to work properly.
                TreeModelContentProvider contentProvider = (TreeModelContentProvider) fTreeViewer
                        .getContentProvider();
                TreePath path = TreePath.EMPTY;
                int count = fTreeViewer.getChildCount(path);
                count = contentProvider.viewToModelCount(path, count);
                ModelDelta rootDelta = new ModelDelta(fTreeViewer.getInput(), -1, IModelDelta.NO_CHANGE, count);
                TreePath rootPath = fDropDownViewer.getRootPath();
                ModelDelta delta = rootDelta;
                for (int i = 0; i < rootPath.getSegmentCount(); i++) {
                    Object element = rootPath.getSegment(i);
                    int index = fTreeViewer.findElementIndex(path, element);
                    index = contentProvider.viewToModelIndex(path, index);
                    path = path.createChildPath(element);
                    count = fTreeViewer.getChildCount(path);
                    count = contentProvider.viewToModelCount(path, count);
                    delta = delta.addNode(rootPath.getSegment(i), index, IModelDelta.NO_CHANGE, count);
                }

                // Create the delta and save the drop-down viewer's state to it.
                fDropDownViewer.saveElementState(TreePath.EMPTY, delta,
                        IModelDelta.EXPAND | IModelDelta.SELECT);

                // Add the IModelDelta.FORCE flag to override the current selection in view.
                rootDelta.accept(new IModelDeltaVisitor() {
                    public boolean visit(IModelDelta paramDelta, int depth) {
                        if ((paramDelta.getFlags() & IModelDelta.SELECT) != 0) {
                            ((ModelDelta) paramDelta).setFlags(paramDelta.getFlags() | IModelDelta.FORCE);
                        }
                        return true;
                    }
                });

                // If elements in the drop-down were auto-expanded, then collapse the drop-down's sub tree in the 
                // full viewer.  After the drop-down's full expansion state is saved out to the tree viewer, the
                // tree viewer will accurately reflect the state changes made by the user. 
                if (fView.getBreadcrumbDropDownAutoExpand()) {
                    fTreeViewer.collapseToLevel(rootPath, AbstractTreeViewer.ALL_LEVELS);
                }

                // Save the state of the drop-down out into the tree viewer.
                fTreeViewer.updateViewer(rootDelta);
                fViewer.setSelection(StructuredSelection.EMPTY);
                site.close();
            }

            super.openElement(selection);
        }
    };

    return dropDownTreeViewer.createDropDown(parent, site, paramPath);
}