@SuppressWarnings({"unchecked", "rawtypes"}) private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) { if (!(selection instanceof ITreeSelection)) return EMPTY_WORKING_SET_ARRAY; ITreeSelection treeSelection = (ITreeSelection) selection; if (treeSelection.isEmpty()) return EMPTY_WORKING_SET_ARRAY; List elements = treeSelection.toList(); if (elements.size() == 1) { Object element = elements.get(0); TreePath[] paths = treeSelection.getPathsFor(element); if (paths.length != 1) return EMPTY_WORKING_SET_ARRAY; TreePath path = paths[0]; if (path.getSegmentCount() == 0) return EMPTY_WORKING_SET_ARRAY; Object candidate = path.getSegment(0); if (!(candidate instanceof IWorkingSet)) return EMPTY_WORKING_SET_ARRAY; IWorkingSet workingSetCandidate = (IWorkingSet) candidate; if (isValidWorkingSet(workingSetCandidate)) return new IWorkingSet[] {workingSetCandidate}; return EMPTY_WORKING_SET_ARRAY; } ArrayList result = new ArrayList(); for (Iterator iterator = elements.iterator(); iterator.hasNext(); ) { Object element = iterator.next(); if (element instanceof IWorkingSet && isValidWorkingSet((IWorkingSet) element)) { result.add(element); } } return (IWorkingSet[]) result.toArray(new IWorkingSet[result.size()]); }
/** * Changes the state of the TransformationView according to the currently selected shape * * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent event) */ @Override public void selectionChanged(SelectionChangedEvent event) { // Get the TransformationView if it is open TransformationView transformationView = (TransformationView) workbenchPage.findView(TransformationView.ID); // Return if not if (transformationView == null) { return; } // Get the tree paths ITreeSelection selection = (ITreeSelection) event.getSelection(); TreePath[] paths = selection.getPaths(); // Remove the "selected" value from previously selected shapes for (IShape shape : selectedShapes) { shape.removeProperty("selected"); } selectedShapes.clear(); // Set the "selected" value to true for newly selected shapes for (TreePath path : paths) { Object selectedObject = path.getLastSegment(); // Only perform the action for selected IShapes // (rather than GeometryComponents or null) if (selectedObject instanceof IShape) { IShape selectedShape = (IShape) selectedObject; selectedShape.setProperty("selected", "true"); selectedShapes.add(selectedShape); } } // Set the TransformationView shape to null if nothing is selected // or there are multiple selections if (paths.length != 1) { transformationView.setShape(null); return; } Object selectedObject = paths[0].getLastSegment(); // Determine if the shape of the TransformationView should be set if (selectedObject instanceof IShape) { transformationView.setShape((IShape) selectedObject); } else { transformationView.setShape(null); } }
/** * Returns a valid instance selection for the current selection of the tree viewer. Returns <code> * null</code> if there is none. * * @return a valid instance selection for the current selection of the tree viewer or <code>null * </code> */ private InstanceSelection getValidSelection() { ISelection viewerSelection = treeViewer.getSelection(); if (!(viewerSelection instanceof ITreeSelection) || viewerSelection.isEmpty()) return null; ITreeSelection treeSelection = (ITreeSelection) treeViewer.getSelection(); TreePath firstPath = treeSelection.getPaths()[0]; // XXX use all paths // instead of first // only? InstanceValidationMessage firstMessage; Iterator<InstanceValidationMessage> restIter; if (firstPath.getLastSegment() instanceof InstanceValidationMessage) { firstMessage = (InstanceValidationMessage) firstPath.getLastSegment(); restIter = Iterators.emptyIterator(); } else { Collection<InstanceValidationMessage> messages = contentProvider.getMessages(treeSelection.getPaths()[0]); if (messages.isEmpty()) return null; // shouldn't happen, but doesn't really matter restIter = messages.iterator(); firstMessage = restIter.next(); } InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class); // check first message for valid instance reference if (firstMessage.getInstanceReference() == null || is.getInstance(firstMessage.getInstanceReference()) == null) return null; Set<InstanceReference> references = new HashSet<InstanceReference>(); references.add(firstMessage.getInstanceReference()); while (restIter.hasNext()) references.add(restIter.next().getInstanceReference()); return new DefaultInstanceSelection(references.toArray()); }
private void addCompareActionOrNot(IMenuManager manager) { if (fViewer.getSelection() instanceof ITreeSelection) { ITreeSelection treeSelection = (ITreeSelection) fViewer.getSelection(); if (treeSelection.getPaths().length == 2) { manager.add(fCompareAction); } } }
public void selectionChanged(final IAction action, final ISelection selection) { if (selection instanceof ITreeSelection) { ITreeSelection treeSelection = (ITreeSelection) selection; Object selectedObject = treeSelection.getFirstElement(); if (selectedObject instanceof IMethod) { this.selecteMethod = (IMethod) selectedObject; } System.out.println( "CreateSequenceDiagram.selectionChanged() : " + treeSelection.getFirstElement().getClass()); } }
public void run() { ITreeSelection selectedElem = (ITreeSelection) view.getViewSite().getSelectionProvider().getSelection(); ModelElement selectedModelElement = (ModelElement) selectedElem.getFirstElement(); // TODO: should work also for fileElements... + filename Thread test = new Thread( new FeatureEditorRunable( selectedModelElement.getPathName() + selectedModelElement.getFileName())); test.start(); }
/** * @param activePart the active {@link IWorkbenchPart} * @return the selected {@link IDockerImage} in the given active part of <code>null</code> if none * was selected */ public static IDockerImage getSelectedImage(final IWorkbenchPart activePart) { if (activePart instanceof DockerExplorerView) { final ITreeSelection selection = (ITreeSelection) ((DockerExplorerView) activePart).getCommonViewer().getSelection(); return (IDockerImage) selection.getFirstElement(); } else if (activePart instanceof DockerImagesView) { final IStructuredSelection selection = (IStructuredSelection) (((DockerImagesView) activePart).getSelection()); if (!selection.isEmpty()) { return (IDockerImage) selection.getFirstElement(); } } return null; }
private IStructuredSelection mapToStructuredSelection(ITreeSelection treeSelection) { Object object = treeSelection.getFirstElement(); if (object instanceof EObject) { return buildStructuredSelection((EObject) object); } return new StructuredSelection(); }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { JoomlaGenModel genModel = null; ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof ITreeSelection) { ITreeSelection tree = (ITreeSelection) selection; if (!tree.isEmpty()) { Object element = tree.getFirstElement(); if (element instanceof JoomlaGenModel) { genModel = (JoomlaGenModel) element; JComponentGenerator.generate(genModel); } } } return null; }
protected void initGui(Composite parent) { final int gdMinimumWidth = 550; final int gdHeightHint = 200; createFilterPanel(parent); group = new Group(parent, SWT.NONE); if (getTitle() != null) { group.setText(getTitle()); } GridLayout groupOrganizationLayout = new GridLayout(1, true); group.setLayout(groupOrganizationLayout); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.minimumWidth = gdMinimumWidth; gd.heightHint = gdHeightHint; group.setLayoutData(gd); scrolledComposite = new ScrolledComposite(group, SWT.V_SCROLL); scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); scrolledComposite.setExpandHorizontal(true); innerComposite = new Composite(scrolledComposite, SWT.NONE); scrolledComposite.setContent(innerComposite); innerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); innerComposite.setLayout(new GridLayout(1, false)); if (selection != null && !selection.isEmpty()) { Iterator<T> iter = selection.iterator(); while (iter.hasNext()) { preSelectedElements.add(iter.next()); } } else if (selectedElement != null) { preSelectedElements.add(selectedElement); } checkboxMap = new HashMap<T, Button>(); addCheckboxes(); }
@SuppressWarnings("static-access") public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPage page = Workbench.getWorkbenchPage(); if (page == null) { return null; } IPerspectiveDescriptor perspective = page.getPerspective(); if (perspective != null & perspective.getLabel().equals("PyDev")) { Global.FileList.clear(); ISelection selection = page.getSelection(); // Console.println(selection.toString()); if (selection instanceof ITreeSelection) { ITreeSelection treeSelection = (ITreeSelection) selection; TreePath[] paths = treeSelection.getPaths(); if (paths.length == 1) { if (paths[0] != null) { Object object = paths[0].getLastSegment(); if (object instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) object; IResource resource = (IResource) adaptable.getAdapter(IResource.class); if (resource != null) { if (resource.getType() == resource.FILE) { OpenExplorerFile(resource.getLocation().toOSString()); } else if (resource.getType() == resource.PROJECT || resource.getType() == resource.FOLDER) { OpenExplorerPath(resource.getLocation().toOSString()); } } } } } } } return null; }