/** * 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()); }
/** * 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()); }
/** * 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 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()); }
/** * TODO: if the oldElement was expanded and no child element selected, the * newElement will appear collapsed, but selected */ private void replaceElementInSelection(final Object parent, final Object oldElement, final Object newElement, final ITreeSelection selection) { IElementComparer comparer = viewer.getComparer(); TreePath[] paths = selection.getPaths(); for (int i = 0; i < paths.length; i++) { TreePath path = paths[i]; Object[] segments = new Object[path.getSegmentCount()]; boolean replacePath = false; for (int j = 0; j < path.getSegmentCount(); j++) { segments[j] = path.getSegment(j); Object pathParent = j > 0 ? path.getSegment(j - 1) : null; Object pathElement = path.getSegment(j); if (!replacePath && eq(comparer, parent, pathParent) && eq(comparer, oldElement, pathElement)) { segments[j] = newElement; replacePath = true; } } if (replacePath) { paths[i] = new TreePath(segments); } } viewer.setSelection(new TreeSelection(paths, viewer.getComparer())); }
private boolean selectionContains(ITreeSelection selection, Object parent, Object element) { if (!selection.isEmpty()) { IElementComparer comparer = viewer.getComparer(); TreePath[] paths = selection.getPaths(); for (TreePath path : paths) { for (int j = 0; j < path.getSegmentCount() - 1; j++) { Object pathParent = path.getSegment(j); Object pathElement = path.getSegment(j + 1); if (eq(comparer, parent, pathParent) && eq(comparer, element, pathElement)) { return true; } } } } return false; }
/** * 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); }
/** * 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 1.0 */ 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); }
if (checkBusy()) return; final IElementComparer comparer = getComparer(); IElementComparer treePathComparer = new IElementComparer() {
if (checkBusy()) return; final IElementComparer comparer = getComparer(); IElementComparer treePathComparer = new IElementComparer() {
if (checkBusy()) return; final IElementComparer comparer = getComparer(); IElementComparer treePathComparer = new IElementComparer() {
CustomHashtable toRemove = new CustomHashtable(getComparer()); for (Object element : elements) { toRemove.put(element, element);
CustomHashtable toRemove = new CustomHashtable(getComparer()); for (int i = 0; i < elements.length; i++) { toRemove.put(elements[i], elements[i]);
CustomHashtable toRemove = new CustomHashtable(getComparer()); for (int i = 0; i < elements.length; i++) { toRemove.put(elements[i], elements[i]);