List of usage examples for org.eclipse.jface.viewers ITreeContentProvider getParent
public Object getParent(Object element);
null indicating that the parent can't be computed. From source file:ca.uvic.chisel.javasketch.ui.internal.views.TraceNavigatorEventListener.java
License:Open Source License
@Override public void handleSketchEvent(SketchEvent event) { ITreeContentProvider provider = (ITreeContentProvider) viewer.getContentProvider(); Object parent = null;/*from w ww . j a v a2 s .co m*/ Object root = null; IProgramSketch sketch = event.getSketch(); switch (event.getType()) { case SketchAnalysisStarted: case SketchAnalysisEnded: case SketchAnalysisInterrupted: parent = provider.getParent(sketch); root = provider.getParent(sketch.getTracedLaunchConfiguration()); case SketchDeleted: if (sketch != null) { //the sketch is already in the viewer, just update it. if (parent != null) { new UIJobExtension("Refreshing Sketches", new Object[] { sketch }).schedule(); } else if (root != null) { //the sketch is not in the viewer, must update its project new UIJobExtension("Refreshing Sketches", new Object[] { sketch.getTracedLaunchConfiguration() }).schedule(); } else { refreshJob.schedule(); } } break; case SketchRefreshed: refreshJob.schedule(); } }
From source file:com.android.sdkuilib.internal.repository.sdkman2.PackagesPage.java
License:Apache License
private void checkAndExpandItem(Object elem, boolean checked, boolean fixChildren, boolean fixParent) { ITreeContentProvider provider = (ITreeContentProvider) mTreeViewer.getContentProvider(); // fix the item itself if (checked != mTreeViewer.getChecked(elem)) { mTreeViewer.setChecked(elem, checked); }/*from w ww . jav a 2 s . c om*/ if (elem instanceof PkgItem) { // update the PkgItem to reflect the selection ((PkgItem) elem).setChecked(checked); } if (!checked) { if (fixChildren) { // when de-selecting, we deselect all children too mTreeViewer.setSubtreeChecked(elem, checked); for (Object child : provider.getChildren(elem)) { checkAndExpandItem(child, checked, fixChildren, false/*fixParent*/); } } // fix the parent when deselecting if (fixParent) { Object parent = provider.getParent(elem); if (parent != null && mTreeViewer.getChecked(parent)) { mTreeViewer.setChecked(parent, false); } } return; } // When selecting, we also select sub-items (for a category) if (fixChildren) { if (elem instanceof PkgCategory || elem instanceof PkgItem) { Object[] children = provider.getChildren(elem); for (Object child : children) { checkAndExpandItem(child, true, fixChildren, false/*fixParent*/); } // only fix the parent once the last sub-item is set if (elem instanceof PkgCategory) { if (children.length > 0) { checkAndExpandItem(children[0], true, false/*fixChildren*/, true/*fixParent*/); } else { mTreeViewer.setChecked(elem, false); } } } else if (elem instanceof Package) { // in details mode, we auto-select compatible packages selectCompatibleArchives(elem, provider); } } if (fixParent && checked && elem instanceof PkgItem) { Object parent = provider.getParent(elem); if (!mTreeViewer.getChecked(parent)) { Object[] children = provider.getChildren(parent); boolean allChecked = children.length > 0; for (Object e : children) { if (!mTreeViewer.getChecked(e)) { allChecked = false; break; } } if (allChecked) { mTreeViewer.setChecked(parent, true); } } } }
From source file:com.aptana.ide.views.outline.UnifiedOutlineProvider.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) *///w ww.java 2 s .co m public Object getParent(Object element) { Object result = null; switchLanguage(element); if (this._currentProviders != null) { ITreeContentProvider contentProvider = this._currentProviders.contentProvider; if (contentProvider != null) { result = contentProvider.getParent(element); } } return result; }
From source file:com.google.gwt.eclipse.oophm.breadcrumbs.BreadcrumbViewer.java
License:Open Source License
/** * Generates the parent chain of the given element. * /*from w w w. j av a 2s . c o m*/ * @param element element to build the parent chain for * @return the first index of an item in fBreadcrumbItems which is not part of * the chain */ private int buildItemChain(Object element) { if (element == null) return 0; ITreeContentProvider contentProvider = (ITreeContentProvider) getContentProvider(); Object parent = contentProvider.getParent(element); int index = buildItemChain(parent); BreadcrumbItem item; if (index < fBreadcrumbItems.size()) { item = (BreadcrumbItem) fBreadcrumbItems.get(index); if (item.getData() != null) unmapElement(item.getData()); } else { item = createItem(); fBreadcrumbItems.add(item); } if (equals(element, item.getData())) { update(element, null); } else { item.setData(element); item.refresh(); } if (parent == null) { // don't show the models root item.setDetailsVisible(false); } mapElement(element, item); return index + 1; }
From source file:com.mentor.nucleus.bp.core.ui.tree.ModelCheckedTreeViewer.java
License:Open Source License
public void setGrayCheckedForParents(Object element, boolean state) { ITreeContentProvider provider = (ITreeContentProvider) getContentProvider(); Object parent = provider.getParent(element); while (parent != null) { setGrayChecked(parent, state);/*from www. j a v a2s.com*/ parent = provider.getParent(parent); } }
From source file:com.mentor.nucleus.bp.model.compare.ModelMergeProcessor.java
License:Open Source License
/** * This method will move the element to the same location as * determined by the difference/* ww w .j a va2 s . com*/ * * @param difference * @return boolean, true if a change was made */ private static boolean handlePositionChange(TreeDifference difference, ITreeContentProvider contentProvider) { ComparableTreeObject comparable = (ComparableTreeObject) difference.getElement(); Object destinationElement = difference.getMatchingDifference().getElement(); Object destinationParent = contentProvider.getParent(destinationElement); Object localParent = contentProvider.getParent(comparable); int location = TreeDifferencer.getLocationOfElement(localParent, comparable, (ITreeDifferencerProvider) contentProvider); int destinationLocation = TreeDifferencer.getLocationOfElement(destinationParent, destinationElement, (ITreeDifferencerProvider) contentProvider); if (location == destinationLocation) { // another difference has already handled this return false; } // if this is a change that does not have user ordering // then modify the persistence ordering NonRootModelElement element = (NonRootModelElement) comparable.getRealElement(); if (!MetadataSortingManager.isOrderedElement(element)) { IPersistableElementParentDetails parentDetails = PersistenceManager.getHierarchyMetaData() .getParentDetails(element); Object[] localDetails = new Object[] { parentDetails.getParent(), parentDetails.getChild(), parentDetails.getAssociationNumber(), parentDetails.getAssociationPhrase(), parentDetails.getChildKeyLetters() }; callSetOrderOperation(location, localDetails); return true; } boolean up = location < destinationLocation; if (up) { insertElementAt(location, difference, contentProvider, true); } else { insertElementAt(location, difference, contentProvider, false); } return true; }
From source file:com.mentor.nucleus.bp.model.compare.ModelMergeProcessor.java
License:Open Source License
private static void insertElementAt(int location, TreeDifference difference, ITreeContentProvider contentProvider, boolean moveUp) { NonRootModelElementComparable comparable = null; if (difference.getMatchingDifference().getElement() instanceof EmptyElement) { // find the newly copied over comparable NonRootModelElementComparable remoteComparable = (NonRootModelElementComparable) difference .getElement();// w ww . j av a2 s. c o m NonRootModelElement remoteElement = (NonRootModelElement) remoteComparable.getRealElement(); EmptyElement localEmptyElement = ((EmptyElement) difference.getMatchingDifference().getElement()); NonRootModelElement parent = (NonRootModelElement) localEmptyElement.getParent(); Object newElementInDestination = findObjectInDestination(parent.getModelRoot(), remoteElement); comparable = (NonRootModelElementComparable) ComparableProvider .getComparableTreeObject(newElementInDestination); } else { comparable = (NonRootModelElementComparable) difference.getMatchingDifference().getElement(); } NonRootModelElement element = (NonRootModelElement) comparable.getRealElement(); Object[] existingChildren = ((ITreeDifferencerProvider) contentProvider) .getChildren(contentProvider.getParent(element)); if (!moveUp && location >= existingChildren.length) { location = existingChildren.length - 1; } Object existingElementAtNewLocation = existingChildren[location]; if (existingElementAtNewLocation != null) { existingElementAtNewLocation = ((ComparableTreeObject) existingElementAtNewLocation).getRealElement(); } String associationNumber = MetadataSortingManager.getAssociationNumber(element); String associationPhrase = MetadataSortingManager.getAssociationPhrase(element); if (moveUp) { NonRootModelElement previousElementToExisting = (NonRootModelElement) MetadataSortingManager .getPreviousElement((NonRootModelElement) existingElementAtNewLocation); if (previousElementToExisting != null) { Method unrelate = findMethod("unrelateAcrossR" + associationNumber + "From" + associationPhrase, existingElementAtNewLocation.getClass(), new Class[] { existingElementAtNewLocation.getClass() }); invokeMethod(unrelate, existingElementAtNewLocation, new Object[] { previousElementToExisting }); } NonRootModelElement previousToSelf = (NonRootModelElement) MetadataSortingManager .getPreviousElement(element); if (previousToSelf != null) { Method unrelate = findMethod("unrelateAcrossR" + associationNumber + "From" + associationPhrase, element.getClass(), new Class[] { element.getClass() }); invokeMethod(unrelate, element, new Object[] { previousToSelf }); } NonRootModelElement nextToSelf = (NonRootModelElement) MetadataSortingManager.getNextElement(element); if (nextToSelf != null) { Method unrelate = findMethod("unrelateAcrossR" + associationNumber + "From" + associationPhrase, nextToSelf.getClass(), new Class[] { nextToSelf.getClass() }); invokeMethod(unrelate, nextToSelf, new Object[] { element }); Method relate = findMethod("relateAcrossR" + associationNumber + "To" + associationPhrase, nextToSelf.getClass(), new Class[] { nextToSelf.getClass() }); invokeMethod(relate, nextToSelf, new Object[] { previousToSelf }); } Method relate = findMethod("relateAcrossR" + associationNumber + "To" + associationPhrase, existingElementAtNewLocation.getClass(), new Class[] { existingElementAtNewLocation.getClass() }); invokeMethod(relate, existingElementAtNewLocation, new Object[] { element }); if (previousElementToExisting != null) { relate = findMethod("relateAcrossR" + associationNumber + "To" + associationPhrase, element.getClass(), new Class[] { element.getClass() }); invokeMethod(relate, element, new Object[] { previousElementToExisting }); } } else { NonRootModelElement nextElementToExisting = (NonRootModelElement) MetadataSortingManager .getNextElement((NonRootModelElement) existingElementAtNewLocation); if (nextElementToExisting != null) { Method unrelate = findMethod("unrelateAcrossR" + associationNumber + "From" + associationPhrase, nextElementToExisting.getClass(), new Class[] { nextElementToExisting.getClass() }); invokeMethod(unrelate, nextElementToExisting, new Object[] { existingElementAtNewLocation }); } NonRootModelElement nextToSelf = (NonRootModelElement) MetadataSortingManager.getNextElement(element); if (nextToSelf != null) { Method unrelate = findMethod("unrelateAcrossR" + associationNumber + "From" + associationPhrase, nextToSelf.getClass(), new Class[] { nextToSelf.getClass() }); invokeMethod(unrelate, nextToSelf, new Object[] { element }); } NonRootModelElement previousToSelf = (NonRootModelElement) MetadataSortingManager .getPreviousElement(element); if (previousToSelf != null) { Method unrelate = findMethod("unrelateAcrossR" + associationNumber + "From" + associationPhrase, element.getClass(), new Class[] { element.getClass() }); invokeMethod(unrelate, element, new Object[] { previousToSelf }); } if (nextToSelf != null && previousToSelf != null) { Method relate = findMethod("relateAcrossR" + associationNumber + "To" + associationPhrase, nextToSelf.getClass(), new Class[] { nextToSelf.getClass() }); invokeMethod(relate, nextToSelf, new Object[] { previousToSelf }); } Method relate = findMethod("relateAcrossR" + associationNumber + "To" + associationPhrase, element.getClass(), new Class[] { element.getClass() }); invokeMethod(relate, element, new Object[] { existingElementAtNewLocation }); if (nextElementToExisting != null) { relate = findMethod("relateAcrossR" + associationNumber + "To" + associationPhrase, nextElementToExisting.getClass(), new Class[] { nextElementToExisting.getClass() }); invokeMethod(relate, nextElementToExisting, new Object[] { element }); } } }
From source file:com.nokia.carbide.cpp.internal.project.ui.mmpEditor.SourceSelectionViewer.java
License:Open Source License
public void checkStateChanged(CheckStateChangedEvent event) { Object element = event.getElement(); ITreeContentProvider tcp = contentProvider(); if (element instanceof IFile) { Object parent = tcp.getParent(element); if (parent instanceof IContainer) { updateContainerCheckState((IContainer) parent); }//w ww . j a v a 2 s .c o m } else if (element instanceof IContainer) { setGrayed(element, false); updateChildrenCheckState((IContainer) element, event.getChecked()); } }
From source file:com.nokia.carbide.cpp.internal.project.ui.mmpEditor.SourceSelectionViewer.java
License:Open Source License
public void updateContainerCheckStates(List elements) { // this is brute force, potentially traversing the tree multiple times // either the tree must be updated bottom up, or we do brute force HashSet<IContainer> containers = new HashSet<IContainer>(); ITreeContentProvider tcp = contentProvider(); for (Object object : elements) { Object parent = tcp.getParent(object); if (parent instanceof IContainer) { containers.add((IContainer) parent); }//from w w w .j a v a2 s . c om } for (IContainer container : containers) { updateContainerCheckState(container); } }
From source file:com.nokia.carbide.cpp.internal.project.ui.mmpEditor.SourceSelectionViewer.java
License:Open Source License
/** Update check checked/grayed state of the container * and its parents//from w w w. j a v a2 s. c om */ private void updateContainerCheckState(IContainer container) { ITreeContentProvider tcp = contentProvider(); Object[] children = filter(tcp.getChildren(container)); boolean anyChecked = false; boolean anyUnchecked = false; boolean anyGrayed = false; for (Object child : children) { boolean checked = getChecked(child); anyChecked |= checked; anyUnchecked |= !checked; anyGrayed |= getGrayed(child); } setGrayed(container, anyGrayed || (anyChecked && anyUnchecked)); setChecked(container, anyChecked); Object containerParent = tcp.getParent(container); if (containerParent instanceof IContainer) { updateContainerCheckState((IContainer) containerParent); } }