/** * Return the tree path that should be used as the parent path for the given * widget and sorter. A <code>null</code> is returned if either the sorter * is not a {@link TreePathViewerSorter} or if the parent widget is not an * {@link Item} (i.e. is the root of the tree). * * @param parent * the parent widget * @param comparator * the sorter * @return the tree path that should be used as the parent path for the * given widget and sorter */ private TreePath internalGetSorterParentPath(Widget parent, ViewerComparator comparator) { TreePath path; if (comparator instanceof TreePathViewerSorter && parent instanceof Item) { Item item = (Item) parent; path = getTreePathFromItem(item); } else { path = null; } return path; }
/** * Return the tree path that should be used as the parent path for the given * widget and sorter. A <code>null</code> is returned if either the sorter * is not a {@link TreePathViewerSorter} or if the parent widget is not an * {@link Item} (i.e. is the root of the tree). * * @param parent * the parent widget * @param comparator * the sorter * @return the tree path that should be used as the parent path for the * given widget and sorter */ private TreePath internalGetSorterParentPath(Widget parent, ViewerComparator comparator) { TreePath path; if (comparator instanceof TreePathViewerSorter && parent instanceof Item) { Item item = (Item) parent; path = getTreePathFromItem(item); } else { path = null; } return path; }
/** * Return the tree path that should be used as the parent path for the given * widget and sorter. A <code>null</code> is returned if either the sorter * is not a {@link TreePathViewerSorter} or if the parent widget is not an * {@link Item} (i.e. is the root of the tree). * * @param parent * the parent widget * @param comparator * the sorter * @return the tree path that should be used as the parent path for the * given widget and sorter */ private TreePath internalGetSorterParentPath(Widget parent, ViewerComparator comparator) { TreePath path; if (comparator instanceof TreePathViewerSorter && parent instanceof Item) { Item item = (Item) parent; path = getTreePathFromItem(item); } else { path = null; } return path; }
/** * Returns a list of tree paths corresponding to expanded nodes in this * viewer's tree, including currently hidden ones that are marked as * expanded but are under a collapsed ancestor. * <p> * This method is typically used when preserving the interesting state of a * viewer; <code>setExpandedElements</code> is used during the restore. * </p> * * @return the array of expanded tree paths * @see #setExpandedElements * * @since 3.2 */ public TreePath[] getExpandedTreePaths() { ArrayList items = new ArrayList(); internalCollectExpandedItems(items, getControl()); ArrayList result = new ArrayList(items.size()); for (Iterator it = items.iterator(); it.hasNext();) { Item item = (Item) it.next(); TreePath treePath = getTreePathFromItem(item); if (treePath != null) { result.add(treePath); } } return (TreePath[]) result.toArray(new TreePath[items.size()]); }
/** * Returns a list of tree paths corresponding to expanded nodes in this * viewer's tree, including currently hidden ones that are marked as * expanded but are under a collapsed ancestor. * <p> * This method is typically used when preserving the interesting state of a * viewer; <code>setExpandedElements</code> is used during the restore. * </p> * * @return the array of expanded tree paths * @see #setExpandedElements * * @since 1.0 */ public TreePath[] getExpandedTreePaths() { ArrayList items = new ArrayList(); internalCollectExpandedItems(items, getControl()); ArrayList result = new ArrayList(items.size()); for (Iterator it = items.iterator(); it.hasNext();) { Item item = (Item) it.next(); TreePath treePath = getTreePathFromItem(item); if (treePath != null) { result.add(treePath); } } return (TreePath[]) result.toArray(new TreePath[items.size()]); }
/** * Returns a list of tree paths corresponding to expanded nodes in this * viewer's tree, including currently hidden ones that are marked as * expanded but are under a collapsed ancestor. * <p> * This method is typically used when preserving the interesting state of a * viewer; <code>setExpandedElements</code> is used during the restore. * </p> * * @return the array of expanded tree paths * @see #setExpandedElements * * @since 3.2 */ public TreePath[] getExpandedTreePaths() { ArrayList<Item> items = new ArrayList<>(); internalCollectExpandedItems(items, getControl()); ArrayList<TreePath> result = new ArrayList<>(items.size()); for (Item item : items) { TreePath treePath = getTreePathFromItem(item); if (treePath != null) { result.add(treePath); } } return result.toArray(new TreePath[items.size()]); }
/** * Return the item at the given path or <code>null</code> * * @param path * the path * @return {@link Widget} the item at that path */ private Widget internalFindItem(TreePath path) { Widget[] widgets = findItems(path.getLastSegment()); for (int i = 0; i < widgets.length; i++) { Widget widget = widgets[i]; if (widget instanceof Item) { Item item = (Item) widget; TreePath p = getTreePathFromItem(item); if (p.equals(path)) { return widget; } } } return null; }
/** * Return the item at the given path or <code>null</code> * * @param path * the path * @return {@link Widget} the item at that path */ private Widget internalFindItem(TreePath path) { Widget[] widgets = findItems(path.getLastSegment()); for (int i = 0; i < widgets.length; i++) { Widget widget = widgets[i]; if (widget instanceof Item) { Item item = (Item) widget; TreePath p = getTreePathFromItem(item); if (p.equals(path)) { return widget; } } } return null; }
/** * Return the item at the given path or <code>null</code> * * @param path * the path * @return {@link Widget} the item at that path */ private Widget internalFindItem(TreePath path) { Widget[] widgets = findItems(path.getLastSegment()); for (Widget widget : widgets) { if (widget instanceof Item) { Item item = (Item) widget; TreePath p = getTreePathFromItem(item); if (p.equals(path)) { return widget; } } } return null; }
/** * Return whether the given element is expandable. * * @param item * the tree item for the element * @param parentPath * the parent path if it is known or <code>null</code> if it * needs to be determines * @param element * the element * @return whether the given element is expandable */ private boolean isExpandable(Item item, TreePath parentPath, Object element) { Object elementOrTreePath = element; if (isTreePathContentProvider()) { if (parentPath != null) { elementOrTreePath = parentPath.createChildPath(element); } else { elementOrTreePath = getTreePathFromItem(item); } } return isExpandable(elementOrTreePath); }
/** * Return whether the given element is expandable. * * @param item * the tree item for the element * @param parentPath * the parent path if it is known or <code>null</code> if it * needs to be determines * @param element * the element * @return whether the given element is expandable */ private boolean isExpandable(Item item, TreePath parentPath, Object element) { Object elementOrTreePath = element; if (isTreePathContentProvider()) { if (parentPath != null) { elementOrTreePath = parentPath.createChildPath(element); } else { elementOrTreePath = getTreePathFromItem(item); } } return isExpandable(elementOrTreePath); }
/** * This implementation of getSelection() returns an instance of * ITreeSelection. * * @since 1.0 */ public ISelection getSelection() { Control control = getControl(); if (control == null || control.isDisposed()) { return TreeSelection.EMPTY; } Widget[] items = getSelection(getControl()); ArrayList list = new ArrayList(items.length); for (int i = 0; i < items.length; i++) { Widget item = items[i]; if (item.getData() != null) { list.add(getTreePathFromItem((Item) item)); } } return new TreeSelection((TreePath[]) list.toArray(new TreePath[list .size()]), getComparer()); }
/** * Return whether the given element is expandable. * * @param item * the tree item for the element * @param parentPath * the parent path if it is known or <code>null</code> if it * needs to be determines * @param element * the element * @return whether the given element is expandable */ private boolean isExpandable(Item item, TreePath parentPath, Object element) { Object elementOrTreePath = element; if (isTreePathContentProvider()) { if (parentPath != null) { elementOrTreePath = parentPath.createChildPath(element); } else { elementOrTreePath = getTreePathFromItem(item); } } return isExpandable(elementOrTreePath); }
/** * The <code>AbstractTreeViewer</code> implementation of this method returns * the result as an <code>ITreeSelection</code>. * <p> * Call {@link #getStructuredSelection()} instead to get an instance of * <code>ITreeSelection</code> directly. * </p> * Subclasses do not typically override this method, but implement * <code>getSelectionFromWidget(List)</code> instead. If they override this * method, they should return an <code>ITreeSelection</code> as well. * * @since 3.2 */ @Override public ISelection getSelection() { Control control = getControl(); if (control == null || control.isDisposed()) { return TreeSelection.EMPTY; } Widget[] items = getSelection(getControl()); ArrayList<TreePath> list = new ArrayList<>(items.length); for (Widget item : items) { if (item.getData() != null) { list.add(getTreePathFromItem((Item) item)); } } return new TreeSelection(list.toArray(new TreePath[list.size()]), getComparer()); }
/** * Returns the widget to be selected for the given element or tree path. * * @param elementOrTreePath * the element or tree path to select * @return the widget to be selected, or <code>null</code> if not found * * @since 3.1 */ protected Widget internalGetWidgetToSelect(Object elementOrTreePath) { if (elementOrTreePath instanceof TreePath) { TreePath treePath = (TreePath) elementOrTreePath; if (treePath.getSegmentCount() == 0) { return getControl(); } Widget[] candidates = findItems(treePath.getLastSegment()); for (Widget candidate : candidates) { if (!(candidate instanceof Item)) { continue; } if (treePath.equals(getTreePathFromItem((Item) candidate), getComparer())) { return candidate; } } return null; } return findItem(elementOrTreePath); }
/** * Returns the widget to be selected for the given element or tree path. * * @param elementOrTreePath * the element or tree path to select * @return the widget to be selected, or <code>null</code> if not found * * @since 3.1 */ protected Widget internalGetWidgetToSelect(Object elementOrTreePath) { if (elementOrTreePath instanceof TreePath) { TreePath treePath = (TreePath) elementOrTreePath; if (treePath.getSegmentCount() == 0) { return getControl(); } Widget[] candidates = findItems(treePath.getLastSegment()); for (int i = 0; i < candidates.length; i++) { Widget candidate = candidates[i]; if (!(candidate instanceof Item)) { continue; } if (treePath.equals(getTreePathFromItem((Item) candidate), getComparer())) { return candidate; } } return null; } return findItem(elementOrTreePath); }
@Override protected void handleDoubleSelect(SelectionEvent event) { // handle case where an earlier selection listener disposed the control. Control control = getControl(); if (control != null && !control.isDisposed()) { // If the double-clicked element can be obtained from the event, use // it // otherwise get it from the control. Some controls like List do // not have the notion of item. // For details, see bug 90161 [Navigator] DefaultSelecting folders // shouldn't always expand first one ISelection selection; if (event.item != null && event.item.getData() != null) { // changes to fix bug 108102 follow TreePath treePath = getTreePathFromItem((Item) event.item); selection = new TreeSelection(treePath); // end of changes } else { selection = getSelection(); updateSelection(selection); } fireDoubleClick(new DoubleClickEvent(this, selection)); } }
@Override protected void handleDoubleSelect(SelectionEvent event) { // handle case where an earlier selection listener disposed the control. Control control = getControl(); if (control != null && !control.isDisposed()) { // If the double-clicked element can be obtained from the event, use // it // otherwise get it from the control. Some controls like List do // not have the notion of item. // For details, see bug 90161 [Navigator] DefaultSelecting folders // shouldn't always expand first one ISelection selection; if (event.item != null && event.item.getData() != null) { // changes to fix bug 108102 follow TreePath treePath = getTreePathFromItem((Item) event.item); selection = new TreeSelection(treePath); // end of changes } else { selection = getSelection(); updateSelection(selection); } fireDoubleClick(new DoubleClickEvent(this, selection)); } }
protected void handleDoubleSelect(SelectionEvent event) { // handle case where an earlier selection listener disposed the control. Control control = getControl(); if (control != null && !control.isDisposed()) { // If the double-clicked element can be obtained from the event, use // it // otherwise get it from the control. Some controls like List do // not have the notion of item. // For details, see bug 90161 [Navigator] DefaultSelecting folders // shouldn't always expand first one ISelection selection; // RAP [if] Add a check for disposed item - see bug 413920 if (event.item != null && !event.item.isDisposed() && event.item.getData() != null) { // if (event.item != null && event.item.getData() != null) { // changes to fix bug 108102 follow TreePath treePath = getTreePathFromItem((Item) event.item); selection = new TreeSelection(treePath); // end of changes } else { selection = getSelection(); updateSelection(selection); } fireDoubleClick(new DoubleClickEvent(this, selection)); } }
public void run() { // fix for PR 1FW89L7: // don't complain and remove all "dummies" ... if (tis != null) { for (int i = 0; i < tis.length; i++) { if (tis[i].getData() != null) { disassociate(tis[i]); Assert.isTrue(tis[i].getData() == null, "Second or later child is non -null");//$NON-NLS-1$ } tis[i].dispose(); } } Object d = widget.getData(); if (d != null) { Object parentElement = d; Object[] children; if (isTreePathContentProvider() && widget instanceof Item) { TreePath path = getTreePathFromItem((Item) widget); children = getSortedChildren(path); } else { children = getSortedChildren(parentElement); } for (int i = 0; i < children.length; i++) { createTreeItem(widget, children[i], -1); } } }