List of usage examples for org.eclipse.jface.viewers ITreeSelection getFirstElement
public Object getFirstElement();
null if the selection is empty. From source file:com.android.ide.eclipse.adt.internal.editors.ui.tree.UiElementDetail.java
License:Open Source License
@Override public void selectionChanged(IFormPart part, ISelection selection) { if (part == mMasterPart && !selection.isEmpty() && selection instanceof ITreeSelection) { ITreeSelection tree_selection = (ITreeSelection) selection; Object first = tree_selection.getFirstElement(); if (first instanceof UiElementNode) { UiElementNode ui_node = (UiElementNode) first; createUiAttributeControls(mManagedForm, ui_node); }/* ww w . jav a2 s .co m*/ } }
From source file:com.android.ide.eclipse.adt.internal.editors.ui.tree.UiTreeBlock.java
License:Open Source License
/** * Called when the "Add..." button next to the tree view is selected. * * Displays a selection dialog that lets the user select which kind of node * to create, depending on the current selection. *//* w w w . ja v a 2 s . c om*/ private void doTreeAdd() { UiElementNode ui_node = mUiRootNode; ISelection selection = mTreeViewer.getSelection(); if (!selection.isEmpty() && selection instanceof ITreeSelection) { ITreeSelection tree_selection = (ITreeSelection) selection; Object first = tree_selection.getFirstElement(); if (first != null && first instanceof UiElementNode) { ui_node = (UiElementNode) first; } } mUiTreeActions.doAdd(ui_node, mDescriptorFilters, mTreeViewer.getControl().getShell(), (ILabelProvider) mTreeViewer.getLabelProvider()); }
From source file:com.android.ide.eclipse.editors.ui.tree.UiElementDetail.java
License:Open Source License
public void selectionChanged(IFormPart part, ISelection selection) { if (part == mMasterPart && !selection.isEmpty() && selection instanceof ITreeSelection) { ITreeSelection tree_selection = (ITreeSelection) selection; Object first = tree_selection.getFirstElement(); if (first instanceof UiElementNode) { UiElementNode ui_node = (UiElementNode) first; createUiAttributeControls(mManagedForm, ui_node); }//from ww w . j a v a 2s .c o m } }
From source file:com.android.sdkuilib.internal.repository.sdkman2.PackagesPage.java
License:Apache License
private void onTreeDoubleClick(DoubleClickEvent event) { assert event.getSource() == mTreeViewer; ISelection sel = event.getSelection(); if (sel.isEmpty() || !(sel instanceof ITreeSelection)) { return;/* w w w .jav a2 s .co m*/ } ITreeSelection tsel = (ITreeSelection) sel; Object elem = tsel.getFirstElement(); if (elem == null) { return; } ITreeContentProvider provider = (ITreeContentProvider) mTreeViewer.getContentProvider(); Object[] children = provider.getElements(elem); if (children == null) { return; } if (children.length > 0) { // If the element has children, expand/collapse it. if (mTreeViewer.getExpandedState(elem)) { mTreeViewer.collapseToLevel(elem, 1); } else { mTreeViewer.expandToLevel(elem, 1); } } else { // If the element is a terminal one, select/deselect it. checkAndExpandItem(elem, !mTreeViewer.getChecked(elem), false /*fixChildren*/, true /*fixParent*/); updateButtonsState(); } }
From source file:com.buildml.eclipse.packages.handlers.MoveToPackageDialog.java
License:Open Source License
@Override protected void okPressed() { ITreeSelection selection = (ITreeSelection) viewer.getSelection(); Object selectedNode = selection.getFirstElement(); if (selectedNode instanceof UIPackage) { savedPackageId = ((UIPackage) selectedNode).getId(); }//from w w w. j a v a2 s. com /* now dispose the window */ super.okPressed(); }
From source file:com.buildml.eclipse.utils.dialogs.VFSTreeSelectionDialog.java
License:Open Source License
@Override protected Control createContents(Composite parent) { Control contents = super.createContents(parent); /* customize the dialog box, before it's opened */ final TreeViewer viewer = getTreeViewer(); viewer.expandToLevel(5);/*from w w w . j av a2 s . c o m*/ /* * Unless the user is allowed to select directories, disable the OK button if * a directory is selected. */ if (!allowDirs) { viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ITreeSelection selection = (ITreeSelection) viewer.getSelection(); Object element = selection.getFirstElement(); getButton(OK).setEnabled(!(element instanceof UIDirectory)); } }); } return contents; }
From source file:com.google.devtools.depan.resource_doc.eclipse.ui.widgets.ProjectResourceControl.java
License:Apache License
public IContainer getSelectedContainer() { ITreeSelection blix = containerViewer.getStructuredSelection(); Object item = blix.getFirstElement(); if (item instanceof IContainer) { return (IContainer) item; }/* w ww .j a v a 2 s. com*/ return null; }
From source file:com.google.devtools.depan.resource_doc.eclipse.ui.widgets.ProjectResourceControl.java
License:Apache License
@SuppressWarnings("unchecked") public T getSelectedResource() { ITreeSelection blix = containerViewer.getStructuredSelection(); Object item = blix.getFirstElement(); if (item instanceof PropertyDocument<?>) { return (T) item; }/*from w w w .j a va 2 s .co m*/ return null; }
From source file:com.google.devtools.depan.resource_doc.eclipse.ui.widgets.ProjectResourceControl.java
License:Apache License
public IFile getSelectedDocument() { ITreeSelection blix = containerViewer.getStructuredSelection(); Object item = blix.getFirstElement(); if (item instanceof IFile) { return (IFile) item; }//from w ww. j ava2s .c om return null; }
From source file:com.google.gapid.widgets.Widgets.java
License:Apache License
public static TreeViewer createTreeViewer(Tree tree) { TreeViewer viewer = new VisibilityTrackingTreeViewer(tree); viewer.setUseHashlookup(true);/*www .j a va 2 s . c o m*/ tree.addListener(SWT.KeyDown, e -> { switch (e.keyCode) { case SWT.ARROW_LEFT: case SWT.ARROW_RIGHT: ITreeSelection selection = viewer.getStructuredSelection(); if (selection.size() == 1) { viewer.setExpandedState(selection.getFirstElement(), e.keyCode == SWT.ARROW_RIGHT); } break; } }); viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.size() == 1) { Object element = selection.getFirstElement(); viewer.setExpandedState(element, !viewer.getExpandedState(element)); } } }); return viewer; }