/** * Extrait l'objet de déclaration KSP d'un événement de sélection de l'arboresence. * * @param event Evénement de sélection. * @return Déclaration KSP. */ private TreeKspDeclaration getTreeKspDeclaration(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection == null) { return null; } if (!(selection instanceof ITreeSelection)) { return null; } ITreeSelection treeSelection = (ITreeSelection) selection; Object firstElement = treeSelection.getFirstElement(); if (!(firstElement instanceof TreeKspDeclaration)) { return null; } return (TreeKspDeclaration) firstElement; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = MarkerFactory.getSelection(); if (selection instanceof ITreeSelection) { ITreeSelection treeSelection = (ITreeSelection) selection; if (treeSelection.getFirstElement() instanceof IOpenable || treeSelection.getFirstElement() instanceof IFile) { IResource resource = ((IAdaptable) treeSelection.getFirstElement()).getAdapter(IResource.class); List<IMarker> markers = MarkerFactory.findMarkers(resource); MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Marker Count", null, markers.size() + " marker(s)", MessageDialog.INFORMATION, new String[] {"OK"}, 0); dialog.open(); } } return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection sel = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow() .getSelectionService().getSelection(); if (sel instanceof ITreeSelection) { ITreeSelection treeSel = (ITreeSelection) sel; if (treeSel.getFirstElement() instanceof IFile) { IFile file = (IFile) treeSel.getFirstElement(); List<IMarker> markers = MarkerFactory.findMarkers(file); MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Marker Count", null, markers.size() + " marker(s)", MessageDialog.INFORMATION, new String[] {"OK"}, 0); dialog.open(); } } return null; }
/** * Finds a marker for given selection on the tree * * @param treeSelection * @param resource * @return */ public static IMarker findMarkerByTreeSelection(final ITreeSelection treeSelection, final IResource resource) { final Object o = treeSelection.getFirstElement(); if (o != null && o instanceof EObject) { final String uri = EcoreUtil.getURI((EObject) o).toString(); final List<IMarker> markers = MarkerFactory.findMarkers(resource); for (final IMarker iMarker : markers) { if (uri.equals(MarkUtilities.getUri(iMarker))) { return iMarker; } } } return null; }
public static IJavaProject[] getJavaProjects(final ITreeSelection treeSelection) { if (treeSelection == null) { return new IJavaProject[0]; } final List<IJavaProject> projects = new ArrayList<>(); final TreePath[] paths = treeSelection.getPaths(); for (final TreePath treePath : paths) { if (treePath.equals(TreePath.EMPTY)) { continue; } for (int i = 0; i < treePath.getSegmentCount(); i++) { final Object segment = treePath.getSegment(i); if ((segment instanceof IJavaProject)) { projects.add((IJavaProject) segment); break; } } } return projects.toArray(new IJavaProject[projects.size()]); }
public static IJavaElement[] getJavaElements(final ITreeSelection selection) { if (selection == null) { return new IJavaProject[0]; } final List<IJavaElement> projects = new ArrayList<>(); for (final TreePath treePath : selection.getPaths()) { if (treePath.equals(TreePath.EMPTY)) { continue; } final Object lastSegment = treePath.getLastSegment(); if (!(lastSegment instanceof IJavaElement)) { continue; } projects.add((IJavaElement) lastSegment); } return projects.toArray(new IJavaElement[projects.size()]); }
private Collection<IPackageFragmentRoot> getSelectedClasspathEntries(ISelection selection) { if (!(selection instanceof ITreeSelection)) { return Collections.emptyList(); } ITreeSelection structuredSelection = (ITreeSelection) selection; Set<IPackageFragmentRoot> fragments = new LinkedHashSet<>(structuredSelection.size()); for (Object o : structuredSelection.toList()) { if (o instanceof IPackageFragmentRoot) { IPackageFragmentRoot pfr = (IPackageFragmentRoot) o; if (ClasspathUtils.isBinaryFragment(pfr) && belongsToPluginContainer(structuredSelection, pfr)) { fragments.add(pfr); } } else if (isPluginContainer(o)) { IAdaptable adaptable = (IAdaptable) o; IWorkbenchAdapter wa = adaptable.getAdapter(IWorkbenchAdapter.class); if (wa != null) { Object[] children = wa.getChildren(o); if (children instanceof IAdaptable[]) { IAdaptable[] adaptables = (IAdaptable[]) children; fragments.addAll(filterPackageFragmentRoots(adaptables)); } } } } return fragments; }
@Override protected boolean computeEnablement(final IStructuredSelection selection) { if (selection.size() != 1) { return false; } // For VS 2010 the content provider is a TreeContentProvider. Only // enable this action for history items at the root level. For // versions prior to 2010 the condition for enablement conditions // are unchanged. boolean isRootItemSelected = true; if (selection instanceof ITreeSelection) { final ITreeSelection treeSelection = (ITreeSelection) selection; final TreePath[] treePaths = treeSelection.getPaths(); if (treePaths.length == 1) { isRootItemSelected = treePaths[0].getSegmentCount() == 1; } } final String item = historyInput.getHistoryItem(); return !ServerPath.isServerPath(item) && isRootItemSelected; }
private void copyTreeSelectionToClipboard() { ITreeSelection selection = (ITreeSelection) treeViewer.getSelection(); TreePath[] paths = selection.getPaths(); StringBuffer buf = new StringBuffer(); for (TreePath path : paths) { LogEntry<?> entry = (LogEntry<?>) path.getLastSegment(); buf.append(createTabString(path.getSegmentCount() - 1)); buf.append(entry.toString()); buf.append("\n"); } if (buf.length() > 0) { buf.deleteCharAt(buf.length() - 1); // take off last \n } copyToClipboard(buf.toString()); }
protected void handleSelection() { ITreeSelection selection = (ITreeSelection) treeViewer.getSelection(); if (selection != null) { Object element = selection.getFirstElement(); if (element instanceof AbstractNode) { Model model = ((AbstractNode) element).getModel(); if (model.getPath() != null) { DocumentUtils.openAndReveal(model.getPath(), selection); } else { editor.show(new ShowInContext(null, selection)); } } } }
private void performElementRearrange(int eventDetail) { // only move if target isn't the other working set. If this is the case // the move will happenn automatically by refreshing the other working set if (!isOthersWorkingSet(fWorkingSet)) { List<Object> elements= new ArrayList<Object>(Arrays.asList(fWorkingSet.getElements())); elements.addAll(Arrays.asList(fElementsToAdds)); fWorkingSet.setElements(elements.toArray(new IAdaptable[elements.size()])); } if (eventDetail == DND.DROP_MOVE) { ITreeSelection treeSelection= (ITreeSelection)fSelection; Map<IWorkingSet, List<Object>> workingSets= groupByWorkingSets(treeSelection.getPaths()); for (Iterator<IWorkingSet> iter= workingSets.keySet().iterator(); iter.hasNext();) { IWorkingSet ws= iter.next(); List<Object> toRemove= workingSets.get(ws); List<IAdaptable> currentElements= new ArrayList<IAdaptable>(Arrays.asList(ws.getElements())); currentElements.removeAll(toRemove); ws.setElements(currentElements.toArray(new IAdaptable[currentElements.size()])); } } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { // get Model Path ITreeSelection treeSelection = (ITreeSelection) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getSelectionService().getSelection(); File file = (File) treeSelection.getFirstElement(); modelPath = "platform:/resource" + file.getFullPath().toString(); // load Settings, if there are any loadSettings(); // open Wizard with ModelPath, Path and language as parameter SensidlWizard swizard = new SensidlWizard(modelPath, path, language, null); SensidlWizardDialog dialog = new SensidlWizardDialog(HandlerUtil.getActiveShell(event), swizard); dialog.open(); return null; }
public static IProject getProjectFromSelection(ISelection selection) { if (selection instanceof ITreeSelection) { Object firstElement = ((ITreeSelection) selection).getFirstElement(); if (firstElement != null) { IResource resource = (IResource) Platform.getAdapterManager().getAdapter( firstElement, IResource.class); if (resource != null) { return resource.getProject(); } } } return null; }
private void openSelectedVariable() { ISelection sel = view.getTreeArrayExpressions().getSelection(); if (sel != null) { ITreeSelection treeSel = (ITreeSelection)sel; if (treeSel.size() == 1) { Object element = treeSel.getFirstElement(); if (element instanceof ArrayExpression) { showViewFor((ArrayExpression)element, null); } else if (element instanceof FieldImpl){ ArrayExpression expr = (ArrayExpression)treeSel.getPaths()[0].getSegment(0); showViewFor(expr, (FieldImpl)element); } } } }
private void openSelectedVariable() { ISelection sel = view.getTreeWatchedVariables().getSelection(); if (sel != null) { ITreeSelection treeSel = (ITreeSelection) sel; if (treeSel.size() == 1) { Object element = treeSel.getFirstElement(); AbstractBreakpoint wp = (AbstractBreakpoint) treeSel .getPathsFor(element)[0].getFirstSegment(); ObjectReference obRef = null; if (element instanceof ObjectReference) { obRef = (ObjectReference) element; } showViewFor(getSelectedTarget(), wp, obRef); } } }
/** * Initializes the input filename. */ private void setInitialSelection() { if (selection == null) { return; } if (selection instanceof ITreeSelection) { ITreeSelection treeSelection = (ITreeSelection) selection; if (treeSelection.size() == 1 && treeSelection.getFirstElement() instanceof IFile) { IFile selFile = (IFile) treeSelection.getFirstElement(); if (inputFileExtension.equals(selFile.getFileExtension())) { inputFilePath.setText(selFile.getFullPath().toString()); } } } if (selection.getFirstElement() instanceof ShapeNodeEditPart) { inputFilePath.setText(inputModelFilePath); } }
private String getModelPath() { String path = ""; ITreeSelection selection = modelTreeViewer.getStructuredSelection(); if (selection != null && !selection.isEmpty()) { TVObject tvo = (TVObject)selection.getFirstElement(); path = tvo.getSourcePath(); } return path; }
private List<File> getSelectedJobFile() { List<File> selectedJobFiles = new ArrayList<>(); ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService(); ISelection selection = selectionService.getSelection(HYDROGRAPH_PROJECT_NAVIGATOR_ID); if (selection instanceof ITreeSelection) { List selectionFiles = ((ITreeSelection) selection).toList(); selectedJobFiles = getSelectedJobFile(selectionFiles); } return selectedJobFiles; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { // final MessageDialog dialog = new MessageDialog( // Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), // "Warning", // null, "Not implemented yet!", MessageDialog.WARNING, new String[] // {"OK"}, 0); // dialog.open(); this.delCandidates.clear(); this.switchCandidates.clear(); final IWorkbenchWindow window = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow(); final ISelection selection = window.getSelectionService().getSelection(); final String partId = window.getPartService().getActivePartReference().getId(); if (selection != null && selection instanceof ITreeSelection && partId.equals(this.MASTERVIEW_ID)) { @SuppressWarnings("rawtypes") final Iterator iterator = ((TreeSelection) selection).iterator(); while (iterator.hasNext()) { final Object element = iterator.next(); if (element instanceof IMarker) { this.determineCandidateMarkers((IMarker) element); } } this.determineCandidateToSwitch(); this.switchColors(); this.deleteSelections(); } return null; }
private void createMarker() { editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); file = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor().getEditorInput().getAdapter(IFile.class); selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); final IMarker beAdded = getMarker(); @SuppressWarnings("unused") String text = ""; if (selection instanceof ITextSelection) { if (beAdded != null && beAdded.exists()) { text = ((ITextSelection) selection).getText(); AnnotationFactory.addAnnotation(beAdded, AnnotationFactory.ANNOTATION_MARKING); } } else if (selection instanceof ITreeSelection) { if (editor instanceof EcoreEditor) { final ITreeSelection treeSelection = (ITreeSelection) selection; if (beAdded != null && beAdded.exists()) { if (treeSelection.getFirstElement() instanceof EModelElement) { text = ((ENamedElement) treeSelection.getFirstElement()).getName(); } else { text = MarkUtilities.getText(beAdded); } } } } addToAlloyXML(beAdded); // MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", // null, // "\"" + text + "\" has been selected to be marked", MessageDialog.INFORMATION, // new String[] {"OK"}, 0); // dialog.open(); }
private IMarker getMarker() { IMarker beAdded = null; if (selection instanceof ITextSelection) { beAdded = MarkerFactory.createMarker(file, (ITextSelection) selection); } else if (selection instanceof ITreeSelection) { final ITreeSelection treeSelection = (ITreeSelection) selection; beAdded = MarkerFactory.createMarker(file, treeSelection); } return beAdded; }
public static IMarker createMarker(IResource resource, ISelection selection, String type) { IMarker marker = null; if (selection instanceof ITextSelection) { marker = MarkerFactory.createMarker(resource, (ITextSelection) selection); } else if (selection instanceof ITreeSelection) { marker = MarkerFactory.createMarker(resource, (ITreeSelection) selection); } MarkUtilities.setType(marker, type); AlloyUtilities.addTypeToMarker(marker); AlloyUtilities.addMarkerToRepository(marker); return marker; }
/** * @param selections * @return */ public static String getQualifiedName(final ITreeSelection selections) { final TreePath[] paths = selections.getPaths(); // Consider only not empty and single selection if (selections.isEmpty() || selections.size() > 1) { return null; } final TreePath path = paths[0]; IElementComparer comparer = null; if (selections instanceof TreeSelection) { comparer = ((TreeSelection) selections).getElementComparer(); } System.out.println(path.hashCode(comparer)); for (int i = 1; i < path.getSegmentCount(); i++) { if (path.getSegment(i) instanceof ResourceFactoryImpl) { final EcoreResourceFactoryImpl eResourceFactory = (EcoreResourceFactoryImpl) path.getSegment(i); System.out .println(eResourceFactory.getClass().getName() + ": " + eResourceFactory.toString()); } else if (path.getSegment(i) instanceof ENamedElement) { final ENamedElement namedElement = (ENamedElement) path.getSegment(i); System.out.println(namedElement.getClass().getName() + ": " + namedElement.getName()); } else { System.out.println("?"); } } return null; }
public static IJavaProject[] getJavaProjects(final IWorkbenchPart part, final ISelection selection) { if (part instanceof IEditorPart) { return getJavaProjects((IEditorPart) part); } if (part instanceof IPackagesViewPart) { return getJavaProjects((ITreeSelection) selection); } return new IJavaProject[0]; }
@Override protected boolean computeEnablement(final IStructuredSelection selection) { if (selection.size() > 1) { setText(Messages.getString("HistoryEditor.RollbackMultipleName")); //$NON-NLS-1$ setToolTipText(Messages.getString("HistoryEditor.RollbackMultipleTooltip")); //$NON-NLS-1$ } else { setText(Messages.getString("HistoryEditor.RollbackSingleName")); //$NON-NLS-1$ setToolTipText(Messages.getString("HistoryEditor.RollbackSingleTooltip")); //$NON-NLS-1$ } if (selection instanceof ITreeSelection) { final ITreeSelection treeSelection = (ITreeSelection) selection; final TreePath[] treePaths = treeSelection.getPaths(); for (final TreePath path : treePaths) { if (path.getSegmentCount() > 1) { return false; } } } final TFSRepository repository = historyInput.getRepository(); if (repository == null) { return false; } if (repository.getVersionControlClient().getServiceLevel().getValue() < WebServiceLevel.TFS_2010.getValue()) { return false; } final String itemPath = historyInput.getHistoryItem(); if (itemPath == null) { return false; } if (ServerPath.isServerPath(itemPath)) { return repository.getWorkspace().isServerPathMapped(itemPath); } else { return repository.getWorkspace().isLocalPathMapped(itemPath); } }
private ImportEclipseProject[] getSelectedFolders() { final List<ImportEclipseProject> projects = new ArrayList<ImportEclipseProject>(); final ITreeSelection selectedElements = (ITreeSelection) treeViewer.getSelection(); for (final Iterator<?> i = selectedElements.iterator(); i.hasNext();) { final ImportEclipseProject folder = (ImportEclipseProject) i.next(); projects.add(folder); } return projects.toArray(new ImportEclipseProject[projects.size()]); }
/** * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent) */ public void doubleClick(final DoubleClickEvent dce) { if (dce.getSelection() instanceof ITreeSelection) { final ITreeSelection treeSelection = (ITreeSelection) dce.getSelection(); final AbstractTreeViewer treeViewer = (AbstractTreeViewer) dce.getSource(); boolean state = treeViewer.getExpandedState(treeSelection.getPaths()[0]); treeViewer.setExpandedState(treeSelection.getPaths()[0], !state); } if (UserPreferences.getInstance().getBoolean( JpwPreferenceConstants.DOUBLE_CLICK_COPIES_TO_CLIPBOARD)) { cpa.run(); } else { era.run(); } }
/** * Return the currently selected server (null if there is no selection or * if the selection is not a server) * * @return the currently selected server entry */ public HadoopServer getSelectedServer() { ITreeSelection selection = (ITreeSelection) viewer.getSelection(); Object first = selection.getFirstElement(); if (first instanceof HadoopServer) { return (HadoopServer) first; } return null; }
public IContainer getSelectedContainer() { ITreeSelection blix = containerViewer.getStructuredSelection(); Object item = blix.getFirstElement(); if (item instanceof IContainer) { return (IContainer) item; } return null; }
@SuppressWarnings("unchecked") public T getSelectedResource() { ITreeSelection blix = containerViewer.getStructuredSelection(); Object item = blix.getFirstElement(); if (item instanceof PropertyDocument<?>) { return (T) item; } return null; }
public IFile getSelectedDocument() { ITreeSelection blix = containerViewer.getStructuredSelection(); Object item = blix.getFirstElement(); if (item instanceof IFile) { return (IFile) item; } return null; }
public TreeNavigationView(Composite parent, int style) { super(parent, style); setLayout(new FillLayout(SWT.VERTICAL)); sashForm = new SashForm(this, SWT.HORIZONTAL); contentTypes = new TreeViewer(sashForm); contentTypes.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { fireSelectionChangedEvent(event); Object contentPanelSelection = null; ISelection selection = contentTypes.getSelection(); if (selection != null && !selection.isEmpty()) { contentPanelSelection = ((ITreeSelection) selection).getFirstElement(); } contentPanel.setSelection(contentPanelSelection); } }); contentPanel = new ContentPanel(sashForm, SWT.NONE); contentTypes.setComparator(new ModelNodeViewerComparator()); sashForm.setWeights(new int[] {20, 80}); contentTypes.setLabelProvider(new ModelLabelProvider()); contentTypes.setContentProvider(new TreeContentProvider()); contentTypes.getTree().addKeyListener( new EnterKeyTreeToggleKeyAdapter(contentTypes)); }
@Override /** * Called by a command from the plugin.xml extension points. */ public Object execute(ExecutionEvent event) { IDiffView diffView; IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); ISelection selection = page.getSelection(); if (selection != null && selection instanceof ITreeSelection) { diffView = getDiffView(window, page); if (diffView != null) { IStructuredSelection strucSelection = (ITreeSelection) selection; diffView.setSelectedFile((IFile) strucSelection.getFirstElement()); } } else { openErrorDialog("Diff View wasn't opened due to unexpected selection type.", window.getShell()); } return null; }
@Override public void run() { if (_tourViewer == null) { return; } final ColumnViewer viewer = _tourViewer.getViewer(); if (viewer instanceof TreeViewer) { final TreeViewer treeViewer = (TreeViewer) viewer; final ITreeSelection selection = (ITreeSelection) treeViewer.getSelection(); if (selection.size() == 0) { return; } final Tree tree = treeViewer.getTree(); tree.setRedraw(false); { for (final Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { treeViewer.expandToLevel(iterator.next(), _expandLevels); } } tree.setRedraw(true); } }
void handleDoubleClick(DoubleClickEvent event) { TreeViewer viewer= fPart.getTreeViewer(); IStructuredSelection selection= (IStructuredSelection)event.getSelection(); Object element= selection.getFirstElement(); if (viewer.isExpandable(element)) { if (doubleClickGoesInto()) { // don't zoom into compilation units and class files if (element instanceof ICompilationUnit || element instanceof IClassFile) return; if (element instanceof IOpenable || element instanceof IContainer || element instanceof IWorkingSet) { fZoomInAction.run(); } } else { IAction openAction= fNavigateActionGroup.getOpenAction(); if (openAction != null && openAction.isEnabled() && OpenStrategy.getOpenMethod() == OpenStrategy.DOUBLE_CLICK) return; if (selection instanceof ITreeSelection) { TreePath[] paths= ((ITreeSelection)selection).getPathsFor(element); for (int i= 0; i < paths.length; i++) { viewer.setExpandedState(paths[i], !viewer.getExpandedState(paths[i])); } } else { viewer.setExpandedState(element, !viewer.getExpandedState(element)); } } } else if (element instanceof IProject && !((IProject) element).isOpen()) { OpenProjectAction openProjectAction= fProjectActionGroup.getOpenProjectAction(); if (openProjectAction.isEnabled()) { openProjectAction.run(); } } }