List of usage examples for org.eclipse.jface.viewers TreePath createChildPath
public TreePath createChildPath(Object newSegment)
From source file:com.jointlogic.breadcrumbs.sampleapp.api.BreadcrumbViewer.java
License:Open Source License
/** * Generates the parent chain of the given element. * /* w w w .j a va 2 s .co 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 void buildItemChain(final Object input) { if (this.fBreadcrumbItems.size() > 0) { final BreadcrumbItem last = (BreadcrumbItem) this.fBreadcrumbItems .get(this.fBreadcrumbItems.size() - 1); last.setIsLastItem(false); } int index = 0; boolean updateLayout = false; if (input != null) { final ITreePathContentProvider contentProvider = (ITreePathContentProvider) getContentProvider(); TreePath path = new TreePath(new Object[0]); // Top level elements need to be retrieved using getElements(), rest // using getChildren(). Object[] children = contentProvider.getElements(input); Object element = children != null && children.length != 0 ? children[0] : null; while (element != null) { path = path.createChildPath(element); // All but last item are hidden if the viewer is in a vertical // toolbar. children = contentProvider.getChildren(path); if ((getStyle() & SWT.VERTICAL) == 0 || children == null || children.length == 0) { updateLayout = updateOrCreateItem(index++, path, element) || updateLayout; } if (children != null && children.length != 0) { element = children[0]; } else { break; } } } BreadcrumbItem last = null; if (index <= this.fBreadcrumbItems.size()) { last = (BreadcrumbItem) this.fBreadcrumbItems.get(index - 1); last.setIsLastItem(true); } while (index < this.fBreadcrumbItems.size()) { updateLayout = true; final BreadcrumbItem item = (BreadcrumbItem) this.fBreadcrumbItems .remove(this.fBreadcrumbItems.size() - 1); if (item.hasFocus() && last != null) { last.setFocus(true); } if (item == this.fSelectedItem) { selectItem(null); } if (item.getData() != null) { unmapElement(item.getData()); } item.dispose(); } if (updateLayout) { updateSize(); this.fContainer.layout(true, true); } }
From source file:com.openMap1.mapper.views.ClassModelView.java
/** * recursive descent of a tree of mapped LabelledEClasses, * looking for a class with the required class name and subset * @param className//www . j ava 2 s . com * @param subset * @param path */ private TreePath findLabelledPath(String className, String subset, TreePath path) { if (path == null) return null; LabelledEClass lc = (LabelledEClass) path.getLastSegment(); // find out if the class is mapped, and if so, set its subset getObjectMappingText(lc); /* only try mapped classes and their mapped descendants * (usually any mapped class has all mapped ancestors) */ if (lc.getMappedSubset() != null) { String cName = ModelUtil.getQualifiedClassName(lc.eClass()); if ((subset.equals(lc.getMappedSubset())) && (className.equals(cName))) return path; else for (Iterator<LabelledEClass> it = lc.getChildren().iterator(); it.hasNext();) { TreePath childPath = path.createChildPath(it.next()); TreePath targetPath = findLabelledPath(className, subset, childPath); if (targetPath != null) return targetPath; } } return null; }
From source file:com.openMap1.mapper.views.ClassModelView.java
/** * @param startPath a TreePath with one step - the entry class of the RMIM * @param parameterClassName name of the parameter class of the mapping set * @return a TreePath to one example of the parameter class (there may be several) * found by a tree search cut off at repeated class names *///from w w w . j a va 2 s .c om private TreePath extendToParameterClass(TreePath startPath, String parameterClassName) { TreePath currentPath = startPath; // from parents of each class, find a path of parent classes to the top class Vector<String> parentsToRoot = new Vector<String>(); parentsToRoot.add(parameterClassName); String topClassName = ModelUtil.getQualifiedClassName(topLabelledEClass.eClass()); parentsToRoot = extendToAncestorClass(parentsToRoot, topClassName); // use these to construct a TreePath of LabelledEClass objects if (parentsToRoot != null) { for (int i = 1; i < parentsToRoot.size(); i++) { LabelledEClass current = (LabelledEClass) currentPath.getLastSegment(); boolean found = false; for (Iterator<LabelledEClass> ic = current.getChildren().iterator(); ic.hasNext();) { LabelledEClass child = ic.next(); if (ModelUtil.getQualifiedClassName(child.eClass()).equals(parentsToRoot.get(i))) { found = true; currentPath = currentPath.createChildPath(child); } } if (!found) return null; } return currentPath; } return null; }
From source file:com.openMap1.mapper.views.ClassModelView.java
/** * /*www .j a v a 2 s .c o m*/ * @param path * @return the treePath of LabelledEClasses got by following a string path, * or null if it cannot be followed */ private TreePath getLabelledTreePath(String path) { TreePath result = null; if (path != null) { StringTokenizer steps = new StringTokenizer(path, "/"); String topName = steps.nextToken(); // check the first step, which should be the name of the top class if (topName.equals(topLabelledEClass.eClass().getName())) { result = TreePath.EMPTY.createChildPath(topLabelledEClass); LabelledEClass currentClass = topLabelledEClass; while ((steps.hasMoreTokens()) && (currentClass != null)) { String step = steps.nextToken(); currentClass = currentClass.getNamedAssocChild(step); if (currentClass != null) result = result.createChildPath(currentClass); else result = null; } } } return result; }
From source file:com.palantir.typescript.text.OutlinePage.java
License:Apache License
private List<TreePath> mapTreePaths(List<NavigationBarItem> lexicalStructure) { ImmutableList.Builder<TreePath> treePaths = ImmutableList.builder(); for (TreePath treePath : this.getTreeViewer().getExpandedTreePaths()) { TreePath newTreePath = TreePath.EMPTY; for (int i = 0; i < treePath.getSegmentCount(); i++) { NavigationBarItem segment = (NavigationBarItem) treePath.getSegment(i); NavigationBarItem newSegment = mapSegment(lexicalStructure, segment); if (newSegment != null) { newTreePath = newTreePath.createChildPath(newSegment); }//from w w w. j a v a 2 s . com } treePaths.add(newTreePath); } return treePaths.build(); }
From source file:de.jcup.egradle.eclipse.ui.AbstractTreeViewerFilter.java
License:Apache License
private boolean hasUnfilteredChild(TreeViewer viewer, TreePath parentPath, Object element) { TreePath elementPath = parentPath.createChildPath(element); IContentProvider contentProvider = viewer.getContentProvider(); Object[] children = contentProvider instanceof ITreePathContentProvider ? ((ITreePathContentProvider) contentProvider).getChildren(elementPath) : ((ITreeContentProvider) contentProvider).getChildren(element); for (int i = 0; i < children.length; i++) { if (selectTreePath(viewer, elementPath, children[i])) { return true; }//from w ww . j a v a2s . com } return false; }
From source file:eu.esdihumboldt.hale.ui.instancevalidation.report.InstanceValidationReportDetailsContentProvider.java
License:Open Source License
/** * @see ITreePathContentProvider#getChildren(TreePath) *//* www. j a v a 2 s.co m*/ @Override public Object[] getChildren(TreePath parentPath) { Set<Object> children = childCache.get(parentPath); if (children == null) { Collection<InstanceValidationMessage> ivms = messages.get(parentPath); if (!ivms.isEmpty()) { children = new HashSet<Object>(); // count of added messages int messageCount = 0; for (InstanceValidationMessage message : ivms) { if (message.getPath().size() > parentPath.getSegmentCount() - 1) { // path not done, add next segment QName name = message.getPath().get(parentPath.getSegmentCount() - 1); Object child = name; Object parent = parentPath.getLastSegment(); if (parent instanceof Definition<?>) { ChildDefinition<?> childDef = DefinitionUtil.getChild((Definition<?>) parent, name); if (childDef != null) child = childDef; } children.add(child); messages.put(parentPath.createChildPath(child), message); } else if (message.getPath().size() == parentPath.getSegmentCount() - 1) { // path done, go by category String category = message.getCategory(); children.add(category); messages.put(parentPath.createChildPath(category), message); } else { // all done, add as child if (messageCount < LIMIT) { children.add(message); messageCount++; } else { limitedPaths.add(parentPath); } } } } else children = Collections.emptySet(); childCache.put(parentPath, children); } return children.toArray(); }
From source file:net.sourceforge.tagsea.core.ui.tags.TagsView.java
License:Open Source License
/** * @param tag/* w w w . j av a2 s. co m*/ * @return */ private TreePath createTreePath(ITag tag) { String[] segments = tag.getName().split("\\."); boolean flat = !TagSEAPlugin.getDefault().getPreferenceStore() .getBoolean(ITagSEAPreferences.TAGS_VIEW_TREE); TagTreeItem parent = null; String parentName = ""; TreePath path = TreePath.EMPTY; for (String segment : segments) { TagTreeItem item = new TagTreeItem(parentName + segment, parent, flat); parentName = item.getName() + "."; path = path.createChildPath(item); parent = item; } return path; }
From source file:org.eclipe.debug.tests.viewer.model.DeltaTests.java
License:Open Source License
public void testExpandAndSelect() throws InterruptedException { TestModel model = TestModel.simpleMultiLevel(); // Create the listener fListener.reset(TreePath.EMPTY, model.getRootElement(), 1, true, false); // Set the input into the view and update the view. fViewer.setInput(model.getRootElement()); while (!fListener.isFinished()) if (!fDisplay.readAndDispatch()) Thread.sleep(0);/*from www .j a v a 2s.c om*/ model.validateData(fViewer, TreePath.EMPTY, true); // Create the delta fListener.reset(); // TODO Investigate: there seem to be unnecessary updates being issued // by the viewer. These include the updates that are commented out: // For now disable checking for extra updates. fListener.setFailOnRedundantUpdates(false); TestElement element = model.getRootElement(); TreePath path_root = TreePath.EMPTY; ModelDelta delta = new ModelDelta(model.getRootElement(), -1, IModelDelta.EXPAND, element.getChildren().length); ModelDelta deltaRoot = delta; element = element.getChildren()[2]; TreePath path_root_3 = path_root.createChildPath(element); delta = delta.addNode(element, 2, IModelDelta.EXPAND, element.fChildren.length); fListener.addChildreUpdate(path_root_3, 0); TreePath path_root_3_1 = path_root_3.createChildPath(element.getChildren()[0]); fListener.addHasChildrenUpdate(path_root_3_1); fListener.addLabelUpdate(path_root_3_1); TreePath path_root_3_3 = path_root_3.createChildPath(element.getChildren()[2]); fListener.addHasChildrenUpdate(path_root_3_3); fListener.addLabelUpdate(path_root_3_3); //TODO unnecessary update: fListener.addChildreUpdate(path1, 1); fListener.addChildreUpdate(path_root_3, 2); element = element.getChildren()[1]; TreePath path_root_3_2 = path_root_3.createChildPath(element); delta = delta.addNode(element, 1, IModelDelta.EXPAND, element.fChildren.length); fListener.addLabelUpdate(path_root_3_2); TreePath path_root_3_2_1 = path_root_3_2.createChildPath(element.getChildren()[0]); fListener.addHasChildrenUpdate(path_root_3_2_1); fListener.addLabelUpdate(path_root_3_2_1); TreePath path_root_3_2_3 = path_root_3_2.createChildPath(element.getChildren()[2]); fListener.addHasChildrenUpdate(path_root_3_2_3); fListener.addLabelUpdate(path_root_3_2_3); // TODO unnecessary update: fListener.addChildreCountUpdate(path2); fListener.addChildreUpdate(path_root_3_2, 0); // TODO unnecessary update: fListener.addChildreUpdate(path2, 1); fListener.addChildreUpdate(path_root_3_2, 2); element = element.getChildren()[1]; TreePath path_root_3_2_2 = path_root_3_2.createChildPath(element); delta = delta.addNode(element, 1, IModelDelta.SELECT, element.fChildren.length); fListener.addLabelUpdate(path_root_3_2_2); fListener.addHasChildrenUpdate(path_root_3_2_2); // Validate the expansion state BEFORE posting the delta. IInternalTreeModelViewer contentProviderViewer = (IInternalTreeModelViewer) fViewer; Assert.assertFalse(contentProviderViewer.getExpandedState(path_root_3)); Assert.assertFalse(contentProviderViewer.getExpandedState(path_root_3_2)); Assert.assertFalse(contentProviderViewer.getExpandedState(path_root_3_2_2)); model.postDelta(deltaRoot); while (!fListener.isFinished(ALL_UPDATES_COMPLETE | MODEL_CHANGED_COMPLETE)) if (!fDisplay.readAndDispatch()) Thread.sleep(0); model.validateData(fViewer, TreePath.EMPTY, true); // Validate the expansion state AFTER posting the delta. Assert.assertTrue(contentProviderViewer.getExpandedState(path_root_3)); Assert.assertTrue(contentProviderViewer.getExpandedState(path_root_3_2)); Assert.assertFalse(contentProviderViewer.getExpandedState(path_root_3_2_2)); // Verify selection ISelection selection = fViewer.getSelection(); if (selection instanceof ITreeSelection) { List selectionPathsList = Arrays.asList(((ITreeSelection) selection).getPaths()); Assert.assertTrue(selectionPathsList.contains(path_root_3_2_2)); } else { Assert.fail("Not a tree selection"); } }
From source file:org.eclipe.debug.tests.viewer.model.DeltaTests.java
License:Open Source License
/** * This test verifies that expand and select updates are being ignored. */// w ww. j a v a 2 s .c o m public void testExpandAndSelect_simple() throws InterruptedException { TestModel model = TestModel.simpleMultiLevel(); // Create the listener fListener.reset(TreePath.EMPTY, model.getRootElement(), 1, true, false); // Set the input into the view and update the view. fViewer.setInput(model.getRootElement()); while (!fListener.isFinished()) if (!fDisplay.readAndDispatch()) Thread.sleep(0); model.validateData(fViewer, TreePath.EMPTY, true); // Create the delta fListener.reset(); // TODO Investigate: there seem to be unnecessary updates being issued // by the viewer. These include the updates that are commented out: // For now disable checking for extra updates. fListener.setFailOnRedundantUpdates(false); TestElement element = model.getRootElement(); TreePath path_root = TreePath.EMPTY; ModelDelta delta = new ModelDelta(model.getRootElement(), -1, IModelDelta.EXPAND, element.getChildren().length); ModelDelta deltaRoot = delta; element = element.getChildren()[2]; TreePath path_root_3 = path_root.createChildPath(element); delta.addNode(element, 2, IModelDelta.SELECT | IModelDelta.EXPAND, element.fChildren.length); // Validate the expansion state BEFORE posting the delta. IInternalTreeModelViewer contentProviderViewer = (IInternalTreeModelViewer) fViewer; Assert.assertFalse(contentProviderViewer.getExpandedState(path_root_3)); model.postDelta(deltaRoot); while (true) { if (fListener.isFinished(MODEL_CHANGED_COMPLETE)) { if (fListener.isFinished(CONTENT_SEQUENCE_COMPLETE | LABEL_SEQUENCE_COMPLETE)) { break; } } if (!fDisplay.readAndDispatch()) Thread.sleep(0); } model.validateData(fViewer, TreePath.EMPTY, true); // Validate the expansion state AFTER posting the delta. Assert.assertTrue(contentProviderViewer.getExpandedState(path_root_3)); // Verify selection ISelection selection = fViewer.getSelection(); if (selection instanceof ITreeSelection) { List selectionPathsList = Arrays.asList(((ITreeSelection) selection).getPaths()); Assert.assertTrue(selectionPathsList.contains(path_root_3)); } else { Assert.fail("Not a tree selection"); } }