/** * Returns the <code>ITreeSelection</code> of this viewer. * <p> * Subclasses whose {@link #getSelection()} specifies to return a more * specific type should also override this method and return that type. * </p> * * @return ITreeSelection * @throws ClassCastException * if the selection of the viewer is not an instance of * ITreeSelection * @since 3.11 */ @Override public ITreeSelection getStructuredSelection() throws ClassCastException { ISelection selection = getSelection(); if (selection instanceof ITreeSelection) { return (ITreeSelection) selection; } throw new ClassCastException("AbstractTreeViewer should return an instance of ITreeSelection from its getSelection() method."); //$NON-NLS-1$ }
/** * Returns the <code>ITreeSelection</code> of this viewer. * <p> * Subclasses whose {@link #getSelection()} specifies to return a more * specific type should also override this method and return that type. * </p> * * @return ITreeSelection * @throws ClassCastException * if the selection of the viewer is not an instance of * ITreeSelection * @since 3.5 */ @Override public ITreeSelection getStructuredSelection() throws ClassCastException { ISelection selection = getSelection(); if (selection instanceof ITreeSelection) { return (ITreeSelection) selection; } throw new ClassCastException( getClass().getName() + " should return an instance of ITreeSelection from its getSelection() method."); //$NON-NLS-1$ }
/** * Returns the <code>ITreeSelection</code> of this viewer. * <p> * Subclasses whose {@link #getSelection()} specifies to return a more * specific type should also override this method and return that type. * </p> * * @return ITreeSelection * @throws ClassCastException * if the selection of the viewer is not an instance of * ITreeSelection * @since 3.11 */ @Override public ITreeSelection getStructuredSelection() throws ClassCastException { ISelection selection = getSelection(); if (selection instanceof ITreeSelection) { return (ITreeSelection) selection; } throw new ClassCastException( getClass().getName() + " should return an instance of ITreeSelection from its getSelection() method."); //$NON-NLS-1$ }
protected List getSelectionFromWidget() { Widget[] items = getSelection(getControl()); ArrayList list = new ArrayList(items.length); for (int i = 0; i < items.length; i++) { Widget item = items[i]; Object e = item.getData(); if (e != null) { list.add(e); } } return list; }
@Override protected List getSelectionFromWidget() { Widget[] items = getSelection(getControl()); ArrayList list = new ArrayList(items.length); for (Widget item : items) { Object e = item.getData(); if (e != null) { list.add(e); } } return list; }
@Override protected List getSelectionFromWidget() { Widget[] items = getSelection(getControl()); ArrayList list = new ArrayList(items.length); for (int i = 0; i < items.length; i++) { Widget item = items[i]; Object e = item.getData(); if (e != null) { list.add(e); } } return list; }
/** * 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()); }
/** * Returns the frame for the selection, or <code>null</code> if there is no * frame for the selection. * * @param flags a bit-wise OR of the frame source flag constants * @return the selection frame, or <code>null</code> */ protected Frame getSelectionFrame(int flags) { IStructuredSelection sel = (IStructuredSelection) viewer.getSelection(); if (sel.size() == 1) { Object o = sel.getFirstElement(); if (viewer.isExpandable(o)) { TreeFrame frame = createFrame(o); if ((flags & IFrameSource.FULL_CONTEXT) != 0) { frame.setSelection(viewer.getSelection()); frame.setExpandedElements(viewer.getExpandedElements()); } return frame; } } return null; }
protected void expandAllFromSelection() { AbstractTreeViewer tree = viewer; if (tree == null) return; ISelection selection = tree.getSelection(); if(! selection.isEmpty()) { Iterator elements = ((IStructuredSelection)selection).iterator(); try { tree.getControl().setRedraw(false); while (elements.hasNext()) { Object next = elements.next(); tree.expandToLevel(next, AbstractTreeViewer.ALL_LEVELS); } } finally { tree.getControl().setRedraw(true); } } } /* (non-Javadoc)
/** * Returns the current frame. * * @param flags a bit-wise OR of the frame source flag constants * @return the current frame */ protected Frame getCurrentFrame(int flags) { Object input = viewer.getInput(); TreeFrame frame = createFrame(input); if ((flags & IFrameSource.FULL_CONTEXT) != 0) { frame.setSelection(viewer.getSelection()); frame.setExpandedElements(viewer.getExpandedElements()); } return frame; }
/** * Returns the parent frame, or <code>null</code> if there is no parent frame. * * @param flags a bit-wise OR of the frame source flag constants * @return the parent frame, or <code>null</code> */ protected Frame getParentFrame(int flags) { Object input = viewer.getInput(); ITreeContentProvider provider = (ITreeContentProvider) viewer .getContentProvider(); Object parent = provider.getParent(input); if (parent == null) { return null; } TreeFrame frame = createFrame(parent); if ((flags & IFrameSource.FULL_CONTEXT) != 0) { frame.setSelection(viewer.getSelection()); // include current input in expanded set Object[] expanded = viewer.getExpandedElements(); Object[] newExpanded = new Object[expanded.length + 1]; System.arraycopy(expanded, 0, newExpanded, 0, expanded.length); newExpanded[newExpanded.length - 1] = input; frame.setExpandedElements(newExpanded); } return frame; }
/** * Moves the specified element from the specified old position to the * specified new position, whenever it appears as a child of the specified * parent element. No action is taken if the viewer has a sorter or * filter(s). * * @param parent * the parent of the element being moved * @param element * the element being moved * @param oldPosition * the position of the element before it is moved * @param newPosition * the position of the element after it is moved */ public void move(Object parent, Object element, int oldPosition, int newPosition) { if (isElementOrderPreserved()) { ITreeSelection selection = (ITreeSelection) viewer.getSelection(); remove(parent, element, oldPosition); insert(parent, element, newPosition); // If the moved element is selected (or is an ancestor of a selected // element), restore the selection. if (selectionContains(selection, getPathParent(parent), element)) viewer.setSelection(selection); } }
@Override public void dragStart(DragSourceEvent event) { ISelection selection = fViewer.getSelection(); LocalSelectionTransfer.getTransfer().setSelection(selection); LocalSelectionTransfer.getTransfer().setSelectionSetTime(event.time & 0xFFFFFFFFL); if (fViewer instanceof BreakpointsViewer) { BreakpointsViewer viewer = (BreakpointsViewer)fViewer; fItems = viewer.getSelectedItems(); event.doit = viewer.canDrag(fItems); } else { if (selection instanceof ITreeSelection) { fTreePaths = ((ITreeSelection) selection).getPaths(); } else { fTreePaths = new TreePath[0]; } event.doit = fView.canDrag(fTreePaths); } }
@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)); } }