Java Code Examples for org.eclipse.jface.viewers.IStructuredSelection#toList()
The following examples show how to use
org.eclipse.jface.viewers.IStructuredSelection#toList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReorgCopyAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public void run(IStructuredSelection selection) { if (ReorgUtils.containsOnlyProjects(selection.toList())){ createWorkbenchAction(selection).run(); return; } try { List<?> elements= selection.toList(); IResource[] resources= ReorgUtils.getResources(elements); IJavaElement[] javaElements= ReorgUtils.getJavaElements(elements); if (RefactoringAvailabilityTester.isCopyAvailable(resources, javaElements)) RefactoringExecutionStarter.startCopyRefactoring(resources, javaElements, getShell()); } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); } }
Example 2
Source File: ReorgCopyAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public void selectionChanged(IStructuredSelection selection) { if (!selection.isEmpty()) { if (ReorgUtils.containsOnlyProjects(selection.toList())) { setEnabled(createWorkbenchAction(selection).isEnabled()); return; } try { List<?> elements= selection.toList(); IResource[] resources= ReorgUtils.getResources(elements); IJavaElement[] javaElements= ReorgUtils.getJavaElements(elements); if (elements.size() != resources.length + javaElements.length) setEnabled(false); else setEnabled(RefactoringAvailabilityTester.isCopyAvailable(resources, javaElements)); } catch (JavaModelException e) { // no ui here - this happens on selection changes // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.isExceptionToBeLogged(e)) JavaPlugin.log(e); setEnabled(false); } } else setEnabled(false); }
Example 3
Source File: AvailableCordovaEnginesSection.java From thym with Eclipse Public License 1.0 | 6 votes |
@Override public void setSelection(ISelection selection) { if (selection instanceof IStructuredSelection) { if (!selection.equals(prevSelection)) { prevSelection = selection; if (selection.isEmpty()) { engineList.setCheckedElements(new Object[0]); } else { IStructuredSelection structuredSelection = (IStructuredSelection) selection; List<HybridMobileEngine> checkedEngines = structuredSelection.toList(); for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) { HybridMobileEngine engine = (HybridMobileEngine) iterator.next(); engineList.reveal(engine); } engineList.setCheckedElements(checkedEngines.toArray()); } engineList.refresh(true); fireSelectionChanged(); } } }
Example 4
Source File: RevealInWorkspace.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event); if (sel.isEmpty()) { return null; } final IWorkbenchPart part = HandlerUtil.getActivePart(event); if (!(part instanceof GamaNavigator)) { return null; } final GamaNavigator nav = (GamaNavigator) part; final List<Object> selection = sel.toList(); final List<WrappedFile> newSelection = new ArrayList<>(); for (final Object o : selection) { if (o instanceof LinkedFile) { newSelection.add(((LinkedFile) o).getTarget()); } } if (newSelection.isEmpty()) { return null; } nav.selectReveal(new StructuredSelection(newSelection)); return this; }
Example 5
Source File: WizardTemplateChoicePage.java From birt with Eclipse Public License 1.0 | 6 votes |
private ReportDesignHandle getSelectionHandle( ) { IStructuredSelection selection = (IStructuredSelection) templateList.getSelection( ); List<?> list = selection.toList( ); if ( list.size( ) != 1 ) { return null; } Object data = list.get( 0 ); if ( data instanceof ReportDesignHandle ) { return (ReportDesignHandle) data; } ReportDesignHandle handle = provider.getReportDesignHandle( data ); return handle; }
Example 6
Source File: FileStagingModeUtil.java From ADT_Frontend with MIT License | 6 votes |
public static void stageObjects(TreeViewer unstagedTreeViewer, IStructuredSelection selection, IAbapGitStaging model, List<Object> expandedNodes) { IAbapGitObject abapObject; IAbapGitFile file; movedObjects.clear(); for (Object object : selection.toList()) { abapObject = null; file = null; if (object instanceof IAbapGitObject) { abapObject = (IAbapGitObject) object; if (unstagedTreeViewer.getExpandedState(abapObject)) { expandedNodes.add(abapObject); } stageObject(model, abapObject); } else if (object instanceof IAbapGitFile) { abapObject = (IAbapGitObject) ((IAbapGitFile) object).eContainer(); file = (IAbapGitFile) object; if (movedObjects.contains(abapObject)) { continue; } expandedNodes.add(abapObject); stageFile(model, abapObject, file); } } }
Example 7
Source File: FileStagingModeUtil.java From ADT_Frontend with MIT License | 6 votes |
public static void unstageObjects(TreeViewer stagedTreeViewer, IStructuredSelection selection, IAbapGitStaging model, List<Object> expandedNodes) { IAbapGitObject abapObject; IAbapGitFile file; movedObjects.clear(); for (Object object : selection.toList()) { abapObject = null; file = null; if (object instanceof IAbapGitObject) { abapObject = (IAbapGitObject) object; if (stagedTreeViewer.getExpandedState(abapObject)) { expandedNodes.add(abapObject); } unstageObject(model, abapObject); } else if (object instanceof IAbapGitFile) { abapObject = (IAbapGitObject) ((IAbapGitFile) object).eContainer(); file = (IAbapGitFile) object; if (movedObjects.contains(abapObject)) { continue; } expandedNodes.add(abapObject); unstageFile(model, abapObject, file); } } }
Example 8
Source File: ReorgMoveAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public void run(IStructuredSelection selection) { if (ReorgUtils.containsOnlyProjects(selection.toList())) { createWorkbenchAction(selection).run(); return; } try { List<?> elements= selection.toList(); IResource[] resources= ReorgUtils.getResources(elements); IJavaElement[] javaElements= ReorgUtils.getJavaElements(elements); if (RefactoringAvailabilityTester.isMoveAvailable(resources, javaElements)) RefactoringExecutionStarter.startMoveRefactoring(resources, javaElements, getShell()); } catch (JavaModelException e) { ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); } }
Example 9
Source File: SelectionFilesCollector.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** Collects files from provided selection. */ public List<IFile> collectFiles(IStructuredSelection structuredSelection) { Set<IFile> collected = new HashSet<>(); for (Object object : structuredSelection.toList()) { collectRelevantFiles(object, collected); } return Lists.newArrayList(collected); }
Example 10
Source File: ConfigureWorkingSetAssignementAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IAdaptable[] getSelectedElements(IStructuredSelection selection) { ArrayList<Object> result= new ArrayList<Object>(); List<?> list= selection.toList(); for (Iterator<?> iterator= list.iterator(); iterator.hasNext();) { Object object= iterator.next(); if (object instanceof IResource || object instanceof IJavaElement) { result.add(object); } } return result.toArray(new IAdaptable[result.size()]); }
Example 11
Source File: OpenCallHierarchyAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void run(IStructuredSelection selection) { List<?> elements= selection.toList(); if (!CallHierarchy.arePossibleInputElements(elements)) { elements= Collections.EMPTY_LIST; } IMember[] members= elements.toArray(new IMember[elements.size()]); if (!ActionUtil.areProcessable(getShell(), members)) return; CallHierarchyUI.openView(members, getSite().getWorkbenchWindow()); }
Example 12
Source File: N4JSNewWizardsActionGroup.java From n4js with Eclipse Public License 1.0 | 5 votes |
private boolean canEnable(final IStructuredSelection sel) { if (sel.size() == 0) { return true; } final List<?> list = sel.toList(); for (final Iterator<?> iterator = list.iterator(); iterator.hasNext(); /**/) { if (!isNewTarget(iterator.next())) { return false; } } return true; }
Example 13
Source File: DFSActionImpl.java From RDFS with Apache License 2.0 | 5 votes |
/** * Extract the list of <T> from the structured selection * * @param clazz the class T * @param selection the structured selection * @return the list of <T> it contains */ private static <T> List<T> filterSelection(Class<T> clazz, IStructuredSelection selection) { List<T> list = new ArrayList<T>(); for (Object obj : selection.toList()) { if (clazz.isAssignableFrom(obj.getClass())) { list.add((T) obj); } } return list; }
Example 14
Source File: GenerateNewConstructorUsingFieldsAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IField[] getSelectedFields(IStructuredSelection selection) { List<?> elements= selection.toList(); if (elements.size() > 0) { IField[] fields= new IField[elements.size()]; ICompilationUnit unit= null; for (int index= 0; index < elements.size(); index++) { if (elements.get(index) instanceof IField) { IField field= (IField) elements.get(index); if (index == 0) { // remember the CU of the first element unit= field.getCompilationUnit(); if (unit == null) { return null; } } else if (!unit.equals(field.getCompilationUnit())) { // all fields must be in the same CU return null; } try { final IType declaringType= field.getDeclaringType(); if (declaringType.isInterface() || declaringType.isAnnotation() || declaringType.isAnonymous()) return null; } catch (JavaModelException exception) { JavaPlugin.log(exception); return null; } fields[index]= field; } else { return null; } } return fields; } return null; }
Example 15
Source File: GroupStatesIntoCompositeHandler.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void setContext(AbstractRefactoring<GraphicalEditPart> refactoring, ISelection selection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; List<GraphicalEditPart> editParts = structuredSelection.toList(); refactoring.setContextObjects(editParts); }
Example 16
Source File: ExternalizeStringsAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * returns <code>List</code> of <code>IPackageFragments</code>, <code>IPackageFragmentRoots</code> or * <code>IJavaProjects</code> (all entries are of the same kind) * @param selection the selection * @return the selected elements */ private static List<?> getSelectedElementList(IStructuredSelection selection) { if (selection == null) return null; return selection.toList(); }
Example 17
Source File: GenerateConstructorUsingFieldsSelectionDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
List<?> getElementList() { IStructuredSelection selection= (IStructuredSelection) getTreeViewer().getSelection(); List<?> elements= selection.toList(); ArrayList<Object> elementList= new ArrayList<Object>(); for (int i= 0; i < elements.size(); i++) { elementList.add(elements.get(i)); } return elementList; }
Example 18
Source File: PullUpMemberPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private MemberActionInfo[] getSelectedMembers() { Assert.isTrue(fTableViewer.getSelection() instanceof IStructuredSelection); final IStructuredSelection structured= (IStructuredSelection) fTableViewer.getSelection(); final List<?> result= structured.toList(); return result.toArray(new MemberActionInfo[result.size()]); }
Example 19
Source File: DeleteModelHandler.java From tlaplus with MIT License | 4 votes |
private String getLabel(final IStructuredSelection iss) { if (iss.size() > 1) { // The selected models. @SuppressWarnings("unchecked") final List<Model> list = (List<Model>) iss.toList(); final Predicate<Model> p = Model::isSnapshot; final Set<Model> models = list.stream().filter(p.negate()).collect(Collectors.toSet()); if (models.isEmpty()) { // Only Snapshots are selected. return String.format("Are you sure you want to delete the %s selected snapshots?", iss.size()); } else { // The set of snapshots (either explicitly selected or implicit via parent // model) to be deleted. final Set<Model> allSnapshots = list.stream().map(Model::getSnapshots).flatMap(c -> c.stream()) .collect(Collectors.toSet()); if (models.size() > 1 && allSnapshots.isEmpty()) { return String.format("Are you sure you want to delete the %s selected models?", iss.size()); } else { // The set of selected snapshots to be deleted. final Set<Model> selectedSnapshots = list.stream().filter(Model::isSnapshot) .collect(Collectors.toSet()); if (models.size() == 1) { // 1 Model with its snapshots and selected snapshots. allSnapshots.addAll(selectedSnapshots); return String.format("Are you sure you want to delete the select model '%s' and %s snapshot%s?", models.iterator().next().getName(), allSnapshots.size(), isPlural(allSnapshots)); } else { // N models with M snapshots allSnapshots.addAll(selectedSnapshots); return String.format("Are you sure you want to delete %s models and %s snapshot%s?", models.size(), allSnapshots.size(), isPlural(allSnapshots)); } } } } return getLabel((Model) iss.getFirstElement()); }
Example 20
Source File: RemoteProfilesPreferencePage.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
private void fillContextMenu(IMenuManager manager) { final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); final List<Object> items = selection.toList(); if (items.size() == 1) { Object item = items.get(0); if (item instanceof RemoteImportProfileElement) { final RemoteImportProfileElement profile = (RemoteImportProfileElement) item; manager.add(new Action(RemoteMessages.RemoteProfilesPreferencePage_NewConnectionNode) { @Override public void run() { newConnectionNode(profile, null); } }); } else if (item instanceof RemoteImportConnectionNodeElement) { final RemoteImportConnectionNodeElement node = (RemoteImportConnectionNodeElement) item; manager.add(new Action(RemoteMessages.RemoteProfilesPreferencePage_NewTraceGroupAction) { @Override public void run() { newTraceGroup(node, null); } }); } else if (item instanceof RemoteImportTraceGroupElement) { final RemoteImportTraceGroupElement traceGroup = (RemoteImportTraceGroupElement) item; manager.add(new Action(RemoteMessages.RemoteProfilesPreferencePage_NewTraceAction) { @Override public void run() { newTrace(traceGroup, null); } }); } } manager.add(new Separator()); manager.add(fDeleteAction); fDeleteAction.setEnabled(!items.isEmpty()); manager.add(new Separator()); manager.add(fCutAction); fCutAction.setEnabled(items.size() == 1); manager.add(fCopyAction); fCopyAction.setEnabled(items.size() == 1); manager.add(fPasteAction); fPasteAction.setEnabled(items.size() <= 1 && validatePaste(selection.getFirstElement())); }