List of usage examples for org.eclipse.jface.viewers ITreePathContentProvider getElements
@Override
public Object[] getElements(Object inputElement);
From source file:com.jointlogic.breadcrumbs.sampleapp.api.BreadcrumbViewer.java
License:Open Source License
/** * Generates the parent chain of the given element. * //from w w w . j a v a 2 s.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 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:org.eclipse.debug.internal.ui.viewers.breadcrumb.BreadcrumbViewer.java
License:Open Source License
/** * Generates the parent chain of the given element. * @param input element to build the parent chain for *///from ww w. jav a 2 s .com private void buildItemChain(Object input) { if (fBreadcrumbItems.size() > 0) { BreadcrumbItem last = (BreadcrumbItem) fBreadcrumbItems.get(fBreadcrumbItems.size() - 1); last.setIsLastItem(false); } int index = 0; boolean updateLayout = false; if (input != null) { 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 <= fBreadcrumbItems.size()) { last = ((BreadcrumbItem) fBreadcrumbItems.get(index - 1)); last.setIsLastItem(true); } while (index < fBreadcrumbItems.size()) { updateLayout = true; BreadcrumbItem item = (BreadcrumbItem) fBreadcrumbItems.remove(fBreadcrumbItems.size() - 1); if (item.hasFocus() && last != null) { last.setFocus(true); } if (item == fSelectedItem) { selectItem(null); } if (item.getData() != null) unmapElement(item.getData()); item.dispose(); } if (updateLayout) { updateSize(); fContainer.layout(true, true); } }
From source file:org.eclipse.swt.nebula.nebface.ctabletreeviewer.CTableTreeViewer.java
License:Open Source License
protected Object[] getRawChildren(Object parent) { Object[] result = null;/* w ww . ja v a 2 s. co m*/ TreePath path; if (parent instanceof TreePath) { path = (TreePath) parent; parent = path.getLastSegment(); } else { path = null; } if (parent != null) { IStructuredContentProvider cp = (IStructuredContentProvider) getContentProvider(); if (cp != null) { if (cp instanceof ITreeContentProvider) { ITreeContentProvider tcp = (ITreeContentProvider) cp; // if Flat, must iteratively get all children and return them as one array // so that the filters and sorters hit every element // if NOT Flat (Hierarchical) then only return the direct elements or children // requested - the getSortedChildren method will compile all branches after // being filtered if (getCTableTree().isFlat()) { Object[] oa; if (equals(parent, getRoot())) { oa = tcp.getElements(parent); } else { oa = tcp.getChildren(parent); } Set s = new HashSet(oa.length); for (int i = 0; i < oa.length; i++) { s.add(oa[i]); s.addAll(Arrays.asList(getRawChildren(oa[i]))); } result = s.isEmpty() ? new Object[0] : s.toArray(); } else { if (equals(parent, getRoot())) { result = tcp.getElements(parent); } else { result = tcp.getChildren(parent); } } } else if (cp instanceof ITreePathContentProvider) { ITreePathContentProvider tpcp = (ITreePathContentProvider) cp; // if Flat, must iteratively get all children and return them as one array // so that the filters and sorters hit every element // if NOT Flat (Hierarchical) then only return the direct elements or children // requested - the getSortedChildren method will compile all branches after // being filtered if (getCTableTree().isFlat()) { Object[] oa; if (equals(parent, getRoot())) { oa = tpcp.getElements(parent); } else { if (path == null) { // A path was not provided so try and find one Widget w = findItem(parent); if (w instanceof Item) { Item item = (Item) w; path = getTreePathFromItem(item); } if (path == null) { path = new TreePath(new Object[] { parent }); } } oa = tpcp.getChildren(path); } Set s = new HashSet(oa.length); for (int i = 0; i < oa.length; i++) { s.add(oa[i]); s.addAll(Arrays.asList(getRawChildren(oa[i]))); } result = s.isEmpty() ? new Object[0] : s.toArray(); } else { if (equals(parent, getRoot())) { result = tpcp.getElements(parent); } else { if (path == null) { // A path was not provided so try and find one Widget w = findItem(parent); if (w instanceof Item) { Item item = (Item) w; path = getTreePathFromItem(item); } if (path == null) { path = new TreePath(new Object[] { parent }); } } result = tpcp.getChildren(path); } } } else { result = cp.getElements(parent); } assertElementsNotNull(result); } } return (result != null) ? result : new Object[0]; }
From source file:org.neuro4j.studio.debug.ui.views.BreadcrumbViewer.java
License:Apache License
/** * Generates the parent chain of the given element. * //from w ww . java 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 void buildItemChain(Object input) { if (fBreadcrumbItems.size() > 0) { BreadcrumbItem last = (BreadcrumbItem) fBreadcrumbItems.get(fBreadcrumbItems.size() - 1); last.setIsLastItem(false); } int index = 0; boolean updateLayout = false; if (input != null) { 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 <= fBreadcrumbItems.size()) { last = ((BreadcrumbItem) fBreadcrumbItems.get(index - 1)); last.setIsLastItem(true); } while (index < fBreadcrumbItems.size()) { updateLayout = true; BreadcrumbItem item = (BreadcrumbItem) fBreadcrumbItems.remove(fBreadcrumbItems.size() - 1); if (item.hasFocus() && last != null) { last.setFocus(true); } if (item == fSelectedItem) { selectItem(null); } if (item.getData() != null) unmapElement(item.getData()); item.dispose(); } if (updateLayout) { updateSize(); fContainer.layout(true, true); } }
From source file:org.openscada.ui.breadcrumbs.BreadcrumbViewer.java
License:Open Source License
/** * Generates the parent chain of the given element. * //from ww w . ja v a 2 s . c om * @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:rabbit.ui.internal.viewers.FilterableTreePathContentProviderTest.java
License:Apache License
private final ForwardingTreePathContentProvider create() { ITreePathContentProvider p = mock(ITreePathContentProvider.class); given(p.getChildren(Mockito.<TreePath>any())).willReturn(EMPTY_ARRAY); given(p.getElements(Mockito.any())).willReturn(EMPTY_ARRAY); given(p.hasChildren(Mockito.<TreePath>any())).willReturn(Boolean.FALSE); return create(p); }
From source file:rabbit.ui.internal.viewers.FilterableTreePathContentProviderTest.java
License:Apache License
private FilterableTreePathContentProvider create(Object input, Object[] elements) { ITreePathContentProvider mock = mock(ITreePathContentProvider.class); given(mock.getElements(input)).willReturn(elements); return create(mock); }