List of usage examples for org.eclipse.jface.viewers TreePath startsWith
public boolean startsWith(TreePath treePath, IElementComparer comparer)
From source file:com.aptana.ide.syncing.ui.views.ConnectionPointComposite.java
License:Open Source License
public void drop(DropTargetEvent event) { IFileStore targetStore = null;// w w w .j a v a2s. 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:net.sourceforge.tagsea.core.ui.internal.tags.TagsDragListener.java
License:Open Source License
/** * @param selection//w w w . j a va2 s . com */ private List<TagTreeItem> pruneSelection(ITreeSelection selection) { TreePath[] paths = selection.getPaths(); List<TreePath> pathList = new LinkedList<TreePath>(Arrays.asList(paths)); TreeItemComparer comparer = new TreeItemComparer(); for (int i = 0; i < pathList.size(); i++) { TreePath path = pathList.remove(0); //check to see if the tree path has a parent in the list. //if yes, take it off. boolean hasParent = false; for (TreePath possibleParent : pathList) { if (path.startsWith(possibleParent, comparer)) { hasParent = true; break; } } if (!hasParent) pathList.add(path); } List<TagTreeItem> itemList = new LinkedList<TagTreeItem>(); for (TreePath path : pathList) { itemList.add((TagTreeItem) path.getLastSegment()); } return itemList; }
From source file:org.eclipe.debug.tests.viewer.model.TestModel.java
License:Open Source License
public ModelDelta appendElementLabel(TreePath path, String labelAppendix) { Assert.assertTrue(path.startsWith(fRootPath, null)); ModelDelta rootDelta = new ModelDelta(fInput, IModelDelta.NO_CHANGE); ModelDelta baseDelta = getBaseDelta(rootDelta); TreePath relativePath = getRelativePath(path); TestElement element = getElement(relativePath); ModelDelta delta = getElementDelta(baseDelta, relativePath, false); element.setLabelAppendix(labelAppendix); delta.setFlags(delta.getFlags() | IModelDelta.STATE); return rootDelta; }
From source file:org.eclipe.debug.tests.viewer.model.TestModel.java
License:Open Source License
public ModelDelta setElementChecked(TreePath path, boolean checked, boolean grayed) { Assert.assertTrue(path.startsWith(fRootPath, null)); ModelDelta rootDelta = new ModelDelta(fInput, IModelDelta.NO_CHANGE); ModelDelta baseDelta = getBaseDelta(rootDelta); TreePath relativePath = getRelativePath(path); TestElement element = getElement(relativePath); ModelDelta delta = getElementDelta(baseDelta, relativePath, false); element.setChecked(checked, grayed); delta.setFlags(delta.getFlags() | IModelDelta.STATE); return rootDelta; }
From source file:org.eclipe.debug.tests.viewer.model.TestModel.java
License:Open Source License
public ModelDelta setElementChildren(TreePath path, TestElement[] children) { Assert.assertTrue(path.startsWith(fRootPath, null)); ModelDelta rootDelta = new ModelDelta(fInput, IModelDelta.NO_CHANGE); ModelDelta baseDelta = getBaseDelta(rootDelta); TreePath relativePath = getRelativePath(path); // Find the parent element and generate the delta node for it. TestElement element = getElement(relativePath); ModelDelta delta = getElementDelta(baseDelta, relativePath, false); // Set the new children array element.fChildren = children;/*www. j a va 2s . c o m*/ // Add the delta flag and update the child count in the parent delta. delta.setFlags(delta.getFlags() | IModelDelta.CONTENT); delta.setChildCount(children.length); return rootDelta; }
From source file:org.eclipse.debug.internal.ui.viewers.model.InternalVirtualTreeModelViewer.java
License:Open Source License
public void remove(final Object parentOrTreePath, final int index) { final List oldSelection = new LinkedList(Arrays.asList(((TreeSelection) getSelection()).getPaths())); preservingSelection(new Runnable() { public void run() { TreePath removedPath = null; VirtualItem[] parentItems = findItems(parentOrTreePath); for (int i = 0; i < parentItems.length; i++) { VirtualItem parentItem = parentItems[i]; if (parentItem.isDisposed()) continue; // Parent item is not expanded so just update its contents so that // the plus sign gets refreshed. if (!parentItem.getExpanded()) { parentItem.setNeedsCountUpdate(); parentItem.setItemCount(-1); virtualLazyUpdateHasChildren(parentItem); }//from w w w . ja v a 2 s .c o m if (index < parentItem.getItemCount()) { VirtualItem item = parentItem.getItem(new VirtualItem.Index(index)); if (item.getData() != null) { removedPath = getTreePathFromItem(item); disassociate(item); } parentItem.remove(item.getIndex()); } } if (removedPath != null) { boolean removed = false; for (Iterator it = oldSelection.iterator(); it.hasNext();) { TreePath path = (TreePath) it.next(); if (path.startsWith(removedPath, null)) { it.remove(); removed = true; } } if (removed) { setSelection( new TreeSelection( (TreePath[]) oldSelection.toArray(new TreePath[oldSelection.size()])), false); } } } }); }
From source file:org.eclipse.debug.internal.ui.viewers.model.TreeModelContentProvider.java
License:Open Source License
/** * Cancels outstanding updates for the element at given path and its * children./*from www .j a va2s . co m*/ * @param path Path of element. */ private void cancelSubtreeUpdates(TreePath path) { Assert.isTrue(getViewer().getDisplay().getThread() == Thread.currentThread()); Iterator iterator = fRequestsInProgress.entrySet().iterator(); while (iterator.hasNext()) { Entry entry = (Entry) iterator.next(); TreePath entryPath = (TreePath) entry.getKey(); if (entryPath.startsWith(path, null)) { List requests = (List) entry.getValue(); Iterator reqIter = requests.iterator(); while (reqIter.hasNext()) { // Cancel update and remove from requests list. Removing from // fRequestsInProgress ensures that isRequestBlocked() won't be triggered // by a canceled update. ((IRequest) reqIter.next()).cancel(); reqIter.remove(); } } } List purge = new ArrayList(); iterator = fWaitingRequests.keySet().iterator(); while (iterator.hasNext()) { TreePath entryPath = (TreePath) iterator.next(); if (entryPath.startsWith(path, null)) { purge.add(entryPath); } } iterator = purge.iterator(); while (iterator.hasNext()) { fWaitingRequests.remove(iterator.next()); } fStateTracker.cancelStateSubtreeUpdates(path); }
From source file:org.eclipse.debug.internal.ui.viewers.model.ViewerStateTracker.java
License:Open Source License
/** * Appends the state of the given subtree to the current pending delta. * @param path Path to subtree to restore. *//*from w ww .j a v a 2 s. co m*/ void appendToPendingStateDelta(final TreePath path) { if (fContentProvider.getViewer() == null) return; // Not initialized yet. if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider.DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) { System.out.println("STATE APPEND BEGIN: " + path.getLastSegment()); //$NON-NLS-1$ } // build a model delta representing expansion and selection state final ModelDelta appendDeltaRoot = new ModelDelta(fContentProvider.getViewer().getInput(), IModelDelta.NO_CHANGE); ModelDelta delta = appendDeltaRoot; for (int i = 0; i < path.getSegmentCount(); i++) { delta = delta.addNode(path.getSegment(i), IModelDelta.NO_CHANGE); } if (!fContentProvider.getViewer().saveElementState(path, delta, IModelDelta.COLLAPSE | IModelDelta.EXPAND | IModelDelta.SELECT)) { // Path to save the state was not found or there was no // (expansion) state to save! Abort. if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider .DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) { System.out.println("STATE APPEND CANCEL: Element " + path.getLastSegment() + " not found."); //$NON-NLS-1$ //$NON-NLS-2$ } return; } // Append a marker CONTENT flag to all the delta nodes that contain the // EXPAND node. These // markers are used by the restore logic to know when a delta node can // be removed. delta.accept(new IModelDeltaVisitor() { public boolean visit(IModelDelta d, int depth) { if ((d.getFlags() & IModelDelta.EXPAND) != 0) { ((ModelDelta) d).setFlags(d.getFlags() | IModelDelta.CONTENT); } return true; } }); if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider.DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) { System.out.println("\tAPPEND DELTA: " + appendDeltaRoot); //$NON-NLS-1$ } if (fPendingState != null) { // If the restore for the current input was never completed, // preserve // that restore along with the restore that was completed. if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider .DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) { System.out.println("\tAPPEND OUTSTANDING RESTORE: " + fPendingState); //$NON-NLS-1$ } // If the append delta is generated for a sub-tree, copy the pending dela // attributes into the pending delta. if (path.getSegmentCount() > 0) { fPendingState.accept(new IModelDeltaVisitor() { public boolean visit(IModelDelta pendingDeltaNode, int depth) { TreePath pendingDeltaPath = fContentProvider.getViewerTreePath(pendingDeltaNode); if (path.startsWith(pendingDeltaPath, null)) { ModelDelta appendDelta = findDeltaForPath(appendDeltaRoot, pendingDeltaPath); appendDelta.setFlags(pendingDeltaNode.getFlags()); appendDelta.setChildCount(pendingDeltaNode.getChildCount()); appendDelta.setIndex(pendingDeltaNode.getIndex()); return true; } return false; } }); } // Copy the pending state into the new appended state. fPendingState.accept(new IModelDeltaVisitor() { public boolean visit(IModelDelta pendingDeltaNode, int depth) { // Skip the top element if (pendingDeltaNode.getParentDelta() == null) { return true; } // Find the node in the save delta which is the parent // of to the current pending delta node. // If the parent node cannot be found, it means that // most likely the user collapsed the parent node before // the children were ever expanded. // If the pending state node already exists in the parent // node, it is already processed and we can skip it. // If the pending state node does not contain any flags, // we can also skip it. ModelDelta saveDeltaNode = findSubDeltaParent(appendDeltaRoot, pendingDeltaNode); if (saveDeltaNode != null && !isDeltaInParent(pendingDeltaNode, saveDeltaNode) && pendingDeltaNode.getFlags() != IModelDelta.NO_CHANGE) { saveDeltaNode.setChildCount(pendingDeltaNode.getParentDelta().getChildCount()); copyIntoDelta(pendingDeltaNode, saveDeltaNode); } else { if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider .DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) { System.out.println("\tSKIPPED: " + pendingDeltaNode.getElement()); //$NON-NLS-1$ } } // If the pending delta node has a memento element, its // children should also be mementos therefore the copy // delta operation should have added all the children // of this pending delta node into the save delta. if (pendingDeltaNode.getElement() instanceof IMemento) { return false; } else { return pendingDeltaNode.getChildCount() > 0; } } }); } if (appendDeltaRoot.getChildDeltas().length > 0) { // Set the new delta root as the pending state delta. if (fPendingState == null) { notifyStateUpdate(appendDeltaRoot.getElement(), STATE_RESTORE_SEQUENCE_BEGINS, null); } fPendingState = appendDeltaRoot; if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider .DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) { System.out.println("STATE APPEND COMPLETE " + fPendingState); //$NON-NLS-1$ } } else { if (DEBUG_STATE_SAVE_RESTORE && TreeModelContentProvider .DEBUG_TEST_PRESENTATION_ID(fContentProvider.getPresentationContext())) { System.out.println("STATE APPEND CANCELED: No Data"); //$NON-NLS-1$ } } }
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;// w ww.j av a 2s . c o m } 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()); }//from www . j a v a2s. c om // 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); }