List of usage examples for org.eclipse.jface.viewers TreePath getLastSegment
public Object getLastSegment()
null if this path has no segments. From source file:ac.soton.eventb.classdiagrams.diagram.navigator.ClassdiagramsNavigatorLabelProvider.java
License:Open Source License
/** * @generated/* w w w .ja va2 s . c o m*/ */ public void updateLabel(ViewerLabel label, TreePath elementPath) { Object element = elementPath.getLastSegment(); if (element instanceof ClassdiagramsNavigatorItem && !isOwnView(((ClassdiagramsNavigatorItem) element).getView())) { return; } label.setText(getText(element)); label.setImage(getImage(element)); }
From source file:ac.soton.eventb.statemachines.diagram.navigator.StatemachinesNavigatorLabelProvider.java
License:Open Source License
/** * @generated// w ww .j a v a 2 s . c o m */ public void updateLabel(ViewerLabel label, TreePath elementPath) { Object element = elementPath.getLastSegment(); if (element instanceof StatemachinesNavigatorItem && !isOwnView(((StatemachinesNavigatorItem) element).getView())) { return; } label.setText(getText(element)); label.setImage(getImage(element)); }
From source file:ac.soton.fmusim.components.diagram.navigator.ComponentsNavigatorLabelProvider.java
License:Open Source License
/** * @generated/*from w w w .j a v a 2s . c o m*/ */ public void updateLabel(ViewerLabel label, TreePath elementPath) { Object element = elementPath.getLastSegment(); if (element instanceof ComponentsNavigatorItem && !isOwnView(((ComponentsNavigatorItem) element).getView())) { return; } label.setText(getText(element)); label.setImage(getImage(element)); }
From source file:ac.soton.multisim.diagram.navigator.MultisimNavigatorLabelProvider.java
License:Open Source License
/** * @generated/*from w w w . j a v a 2 s .c o m*/ */ public void updateLabel(ViewerLabel label, TreePath elementPath) { Object element = elementPath.getLastSegment(); if (element instanceof MultisimNavigatorItem && !isOwnView(((MultisimNavigatorItem) element).getView())) { return; } label.setText(getText(element)); label.setImage(getImage(element)); }
From source file:ar.com.tadp.prolog.core.actions.ConsultInConsoleAction.java
License:Open Source License
@Override public void run(final IAction action) { final PluginAction pAction = (PluginAction) action; final StructuredSelection selection = (StructuredSelection) pAction.getSelection(); final List<String> files = new LinkedList<String>(); IScriptProject project = null;//from w w w.j a v a 2 s . co m if (selection instanceof TreeSelection) { final TreeSelection treeSelection = (TreeSelection) selection; for (final TreePath path : treeSelection.getPaths()) { final Object segment = path.getLastSegment(); if (segment instanceof SourceModule) { final SourceModule sourceModule = (SourceModule) segment; files.add(sourceModule.getResource().getLocation().toPortableString()); project = sourceModule.getScriptProject(); } } } else { final FileEditorInput firstElement = (FileEditorInput) selection.getFirstElement(); files.add(firstElement.getFile().getLocation().toPortableString()); project = getProject(); } final PrologConsoleFactory consoleFactory = new PrologConsoleFactory(); consoleFactory.openConsole(files, project); }
From source file:com.amalto.workbench.providers.XSDTreeLabelProvider.java
License:Open Source License
public void updateLabel(ViewerLabel label, TreePath elementPath) { if (elementPath.getFirstSegment() instanceof XSDElementDeclaration) { entity = (XSDElementDeclaration) elementPath.getFirstSegment(); }//w ww . j a v a2s. c o m Object lastSegment = elementPath.getLastSegment(); label.setText(getText(lastSegment)); label.setImage(getImage(lastSegment)); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigManagerDialog.java
License:Open Source License
/** * Returns a {@link DeviceSelection} object representing the selected path in the * {@link TreeViewer}//from w w w. j av a 2 s.co m */ private DeviceSelection getSelection() { // get the selection paths TreeSelection selection = (TreeSelection) mTreeViewer.getSelection(); TreePath[] paths = selection.getPaths(); if (paths.length == 0) { return null; } TreePath pathSelection = paths[0]; DeviceType type = (DeviceType) pathSelection.getFirstSegment(); LayoutDevice device = null; DeviceConfig config = null; switch (pathSelection.getSegmentCount()) { case 2: // layout device is selected device = (LayoutDevice) pathSelection.getLastSegment(); break; case 3: // config is selected device = (LayoutDevice) pathSelection.getSegment(1); config = (DeviceConfig) pathSelection.getLastSegment(); } return new DeviceSelection(type, device, config); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.SelectionManager.java
License:Open Source License
/** * Sets the selection. It must be an {@link ITreeSelection} where each segment * of the tree path is a {@link CanvasViewInfo}. A null selection is considered * as an empty selection.//from w w w . j av a 2 s . c o m * <p/> * This method is invoked by {@link LayoutCanvasViewer#setSelection(ISelection)} * in response to an <em>outside</em> selection (compatible with ours) that has * changed. Typically it means the outline selection has changed and we're * synchronizing ours to match. */ @Override public void setSelection(ISelection selection) { if (mInsideUpdateSelection) { return; } boolean changed = false; try { mInsideUpdateSelection = true; if (selection == null) { selection = TreeSelection.EMPTY; } if (selection instanceof ITreeSelection) { ITreeSelection treeSel = (ITreeSelection) selection; if (treeSel.isEmpty()) { // Clear existing selection, if any if (!mSelections.isEmpty()) { mSelections.clear(); mAltSelection = null; updateActionsFromSelection(); redraw(); } return; } boolean redoLayout = false; // Create a list of all currently selected view infos Set<CanvasViewInfo> oldSelected = new HashSet<CanvasViewInfo>(); for (SelectionItem cs : mSelections) { oldSelected.add(cs.getViewInfo()); } // Go thru new selection and take care of selecting new items // or marking those which are the same as in the current selection for (TreePath path : treeSel.getPaths()) { Object seg = path.getLastSegment(); if (seg instanceof CanvasViewInfo) { CanvasViewInfo newVi = (CanvasViewInfo) seg; if (oldSelected.contains(newVi)) { // This view info is already selected. Remove it from the // oldSelected list so that we don't deselect it later. oldSelected.remove(newVi); } else { // This view info is not already selected. Select it now. // reset alternate selection if any mAltSelection = null; // otherwise add it. mSelections.add(createSelection(newVi)); changed = true; } if (newVi.isInvisible()) { redoLayout = true; } } else { // Unrelated selection (e.g. user clicked in the Project Explorer // or something) -- just ignore these return; } } // Deselect old selected items that are not in the new one for (CanvasViewInfo vi : oldSelected) { if (vi.isExploded()) { redoLayout = true; } deselect(vi); changed = true; } if (redoLayout) { mCanvas.getEditorDelegate().recomputeLayout(); } } } finally { mInsideUpdateSelection = false; } if (changed) { redraw(); fireSelectionChanged(); updateActionsFromSelection(); } }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.refactoring.VisualRefactoring.java
License:Open Source License
public VisualRefactoring(IFile file, LayoutEditorDelegate editor, ITextSelection selection, ITreeSelection treeSelection) {/*from w w w . j a v a 2s. co m*/ mFile = file; mDelegate = editor; mProject = file.getProject(); mSelection = selection; mTreeSelection = treeSelection; // Initialize mSelectionStart and mSelectionEnd based on the selection context, which // is either a treeSelection (when invoked from the layout editor or the outline), or // a selection (when invoked from an XML editor) if (treeSelection != null) { int end = Integer.MIN_VALUE; int start = Integer.MAX_VALUE; for (TreePath path : treeSelection.getPaths()) { Object lastSegment = path.getLastSegment(); if (lastSegment instanceof CanvasViewInfo) { CanvasViewInfo viewInfo = (CanvasViewInfo) lastSegment; UiViewElementNode uiNode = viewInfo.getUiViewNode(); if (uiNode == null) { continue; } Node xmlNode = uiNode.getXmlNode(); if (xmlNode instanceof IndexedRegion) { IndexedRegion region = (IndexedRegion) xmlNode; start = Math.min(start, region.getStartOffset()); end = Math.max(end, region.getEndOffset()); } } } if (start >= 0) { mSelectionStart = start; mSelectionEnd = end; mOriginalSelectionStart = mSelectionStart; mOriginalSelectionEnd = mSelectionEnd; } if (selection != null) { mOriginalSelectionStart = selection.getOffset(); mOriginalSelectionEnd = mOriginalSelectionStart + selection.getLength(); } } else if (selection != null) { // TODO: update selection to boundaries! mSelectionStart = selection.getOffset(); mSelectionEnd = mSelectionStart + selection.getLength(); mOriginalSelectionStart = mSelectionStart; mOriginalSelectionEnd = mSelectionEnd; } mElements = initElements(); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.refactoring.VisualRefactoring.java
License:Open Source License
protected List<Element> initElements() { List<Element> nodes = new ArrayList<Element>(); assert mTreeSelection == null || mSelection == null : "treeSel= " + mTreeSelection + ", sel=" + mSelection; // Initialize mSelectionStart and mSelectionEnd based on the selection context, which // is either a treeSelection (when invoked from the layout editor or the outline), or // a selection (when invoked from an XML editor) if (mTreeSelection != null) { int end = Integer.MIN_VALUE; int start = Integer.MAX_VALUE; for (TreePath path : mTreeSelection.getPaths()) { Object lastSegment = path.getLastSegment(); if (lastSegment instanceof CanvasViewInfo) { CanvasViewInfo viewInfo = (CanvasViewInfo) lastSegment; UiViewElementNode uiNode = viewInfo.getUiViewNode(); if (uiNode == null) { continue; }// w w w . j av a 2 s . co m Node xmlNode = uiNode.getXmlNode(); if (xmlNode instanceof Element) { Element element = (Element) xmlNode; nodes.add(element); IndexedRegion region = getRegion(element); start = Math.min(start, region.getStartOffset()); end = Math.max(end, region.getEndOffset()); } } } if (start >= 0) { mSelectionStart = start; mSelectionEnd = end; } } else if (mSelection != null) { mSelectionStart = mSelection.getOffset(); mSelectionEnd = mSelectionStart + mSelection.getLength(); mOriginalSelectionStart = mSelectionStart; mOriginalSelectionEnd = mSelectionEnd; // Figure out the range of selected nodes from the document offsets IStructuredDocument doc = mDelegate.getEditor().getStructuredDocument(); Pair<Element, Element> range = DomUtilities.getElementRange(doc, mSelectionStart, mSelectionEnd); if (range != null) { Element first = range.getFirst(); Element last = range.getSecond(); // Adjust offsets to get rid of surrounding text nodes (if you happened // to select a text range and included whitespace on either end etc) mSelectionStart = getRegion(first).getStartOffset(); mSelectionEnd = getRegion(last).getEndOffset(); if (mSelectionStart > mSelectionEnd) { int tmp = mSelectionStart; mSelectionStart = mSelectionEnd; mSelectionEnd = tmp; } if (first == last) { nodes.add(first); } else if (first.getParentNode() == last.getParentNode()) { // Add the range Node node = first; while (node != null) { if (node instanceof Element) { nodes.add((Element) node); } if (node == last) { break; } node = node.getNextSibling(); } } else { // Different parents: this means we have an uneven selection, selecting // elements from different levels. We can't extract ranges like that. } } } else { assert false; } // Make sure that the list of elements is unique //Set<Element> seen = new HashSet<Element>(); //for (Element element : nodes) { // assert !seen.contains(element) : element; // seen.add(element); //} return nodes; }