Java Code Examples for org.eclipse.ui.IWorkingSet#getElements()
The following examples show how to use
org.eclipse.ui.IWorkingSet#getElements() .
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: PythonBaseModelProvider.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * @param newWorkingSet */ private IWorkspace[] getWorkspaces(IWorkingSet newWorkingSet) { IAdaptable[] elements = newWorkingSet.getElements(); HashSet<IWorkspace> set = new HashSet<IWorkspace>(); for (IAdaptable adaptable : elements) { IResource adapter = adaptable.getAdapter(IResource.class); if (adapter != null) { IWorkspace workspace = adapter.getWorkspace(); set.add(workspace); } else { Log.log("Was not expecting that IWorkingSet adaptable didn't return anything..."); } } return set.toArray(new IWorkspace[0]); }
Example 2
Source File: WorkingSetModel.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Tells whether the given working set is supported as top-level element * * @param workingSet the working set to test * @return <code>true</code> if the given working set is supported as top-level element * @since 3.6 */ public static boolean isSupportedAsTopLevelElement(IWorkingSet workingSet) { Object id= workingSet.getId(); if (IWorkingSetIDs.OTHERS.equals(id) || IWorkingSetIDs.JAVA.equals(id) || IWorkingSetIDs.RESOURCE.equals(id)) return true; if (!workingSet.isSelfUpdating() || workingSet.isAggregateWorkingSet()) return false; IAdaptable[] elements= workingSet.getElements(); for (int i= 0; i < elements.length; i++) { IAdaptable element= elements[i]; IProject p= (IProject)element.getAdapter(IProject.class); if (p != null && p.exists()) return true; } return false; }
Example 3
Source File: BugContentProvider.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
private Set<IResource> getResources(Object parent) { Set<IResource> resources = new HashSet<>(); if (parent instanceof IWorkingSet) { IWorkingSet workingSet = (IWorkingSet) parent; IAdaptable[] elements = workingSet.getElements(); // elements may contain NON-resource elements, which we have to // convert to // resources for (IAdaptable adaptable : elements) { IResource resource = (IResource) adaptable.getAdapter(IResource.class); // TODO get only java projects or children of them if (resource != null) { resources.add(resource); } } } else if (parent instanceof IWorkspaceRoot) { IWorkspaceRoot workspaceRoot = (IWorkspaceRoot) parent; // TODO get only java projects IProject[] projects = workspaceRoot.getProjects(); for (IProject project : projects) { resources.add(project); } } return resources; }
Example 4
Source File: WorkingSetModel.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public IAdaptable[] refresh(IWorkingSet ws) { IAdaptable[] oldElements= fWorkingSetToElement.get(ws); if (oldElements == null) return null; IAdaptable[] newElements= ws.getElements(); List<IAdaptable> toRemove= new ArrayList<IAdaptable>(Arrays.asList(oldElements)); List<IAdaptable> toAdd= new ArrayList<IAdaptable>(Arrays.asList(newElements)); computeDelta(toRemove, toAdd, oldElements, newElements); for (Iterator<IAdaptable> iter= toAdd.iterator(); iter.hasNext();) { addElement(iter.next(), ws); } for (Iterator<IAdaptable> iter= toRemove.iterator(); iter.hasNext();) { removeElement(iter.next(), ws); } if (toRemove.size() > 0 || toAdd.size() > 0) fWorkingSetToElement.put(ws, newElements); return oldElements; }
Example 5
Source File: TagsSetHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Get the correct working set, if working sets are present in environment * The Eclipse UI's default 'Other Projects' entry is not represented in the manager * so, if a file from there is selected a Workspace search will result. * * @param editor * @return current IWorkingSet or null */ private IWorkingSet getWorkingSet(ITextEditor editor) { IWorkingSet result = null; IWorkbenchPage page = getWorkbenchPage(); if (page != null) { IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); IWorkingSet[] workingSets = manager.getRecentWorkingSets(); if (workingSets != null && workingSets.length > 0) { // return most recent working set result = workingSets[0]; } else { // For some lame reason, recent working sets is often not set in the manager // so paw through them manually workingSets = manager.getAllWorkingSets(); if (workingSets != null && workingSets.length > 0) { IProject proj = this.getCurrentProject(editor); for(IWorkingSet set : workingSets) { for (IAdaptable ele : set.getElements()) { Object adapt = ele.getAdapter(IProject.class); if (adapt != null && adapt.equals(proj)){ return set; } } } } } } return result; }
Example 6
Source File: WorkingSetsContentProvider.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private IAdaptable[] getWorkingSetElements(IWorkingSet workingSet) { IAdaptable[] children = workingSet.getElements(); for (int i = 0; i < children.length; i++) { Object resource = children[i].getAdapter(IResource.class); if (resource instanceof IProject) children[i] = (IProject) resource; } return children; }
Example 7
Source File: WorkingSetsContentProvider.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
private IAdaptable[] getWorkingSetElements(IWorkingSet workingSet) { IAdaptable[] children = workingSet.getElements(); for (int i = 0; i < children.length; i++) { Object resource = children[i].getAdapter(IResource.class); if (resource instanceof IProject) children[i] = (IProject) resource; } return children; }
Example 8
Source File: WorkingSetModel.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void put(IWorkingSet ws) { if (fWorkingSetToElement.containsKey(ws)) return; IAdaptable[] elements= ws.getElements(); fWorkingSetToElement.put(ws, elements); for (int i= 0; i < elements.length; i++) { IAdaptable element= elements[i]; addElement(element, ws); if (!(element instanceof IProject) && !(element instanceof IJavaProject)) { fNonProjectTopLevelElements.add(element); } } }
Example 9
Source File: ConfigureWorkingSetAssignementAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static void add(IWorkingSet workingSet, IAdaptable adaptedElement) { IAdaptable[] elements= workingSet.getElements(); IAdaptable[] newElements= new IAdaptable[elements.length + 1]; System.arraycopy(elements, 0, newElements, 0, elements.length); newElements[elements.length]= adaptedElement; workingSet.setElements(newElements); }
Example 10
Source File: ConfigureWorkingSetAssignementAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean contains(IWorkingSet set, IAdaptable adaptedElement) { IAdaptable[] elements= set.getElements(); for (int i= 0; i < elements.length; i++) { if (elements[i].equals(adaptedElement)) return true; } return false; }
Example 11
Source File: JavaSearchScopeFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void addJavaElements(Set<IJavaElement> javaElements, IWorkingSet workingSet) { if (workingSet == null) return; if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) { try { IJavaProject[] projects= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects(); javaElements.addAll(Arrays.asList(projects)); } catch (JavaModelException e) { JavaPlugin.log(e); } return; } IAdaptable[] elements= workingSet.getElements(); for (int i= 0; i < elements.length; i++) { IJavaElement javaElement=(IJavaElement) elements[i].getAdapter(IJavaElement.class); if (javaElement != null) { addJavaElements(javaElements, javaElement); continue; } IResource resource= (IResource)elements[i].getAdapter(IResource.class); if (resource != null) { addJavaElements(javaElements, resource); } // else we don't know what to do with it, ignore. } }
Example 12
Source File: TopLevelProjectsOrWorkingSetChoice.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * @param object the object whose parent we want * @param getWorkingSetsCallback a callback that'll return the available working sets. * @return null if the parent is not a working set element or the working set that's a parent * @note if we're not currently showing working sets as top-level elements, it'll return null. */ public Object getWorkingSetParentIfAvailable(Object object, ICallback<List<IWorkingSet>, IWorkspaceRoot> getWorkingSetsCallback) { if (rootMode != WORKING_SETS || object == null) { return null; } //TODO: This could be optimized by creating an auxiliary structure where child->parent working set //so that we could get it directly without the need to traverse all the elements. //this can be interesting because whenever we try to get a parent this method will be called //for all the elements. //showing as working sets List<IWorkingSet> workingSets = getWorkingSetsCallback.call(null); for (IWorkingSet w : workingSets) { IAdaptable[] elements = w.getElements(); if (elements != null) { for (IAdaptable a : elements) { if (a == null) { continue; } if (object.equals(a)) { return w; } if (object instanceof IWrappedResource) { IWrappedResource wrappedResource = (IWrappedResource) object; if (wrappedResource.getActualObject().equals(a)) { return w; } } } } } return null; }
Example 13
Source File: NewCargoProjectWizard.java From corrosion with Eclipse Public License 2.0 | 5 votes |
private static Set<IWorkingSet> getWorkingSets(IResource resource) { IWorkingSet[] allWorkingSets = PlatformUI.getWorkbench().getWorkingSetManager().getAllWorkingSets(); Set<IWorkingSet> fileWorkingSets = new HashSet<>(); for (IWorkingSet iWorkingSet : allWorkingSets) { IAdaptable[] elements = iWorkingSet.getElements(); if (Arrays.asList(elements).contains(resource.getProject())) { fileWorkingSets.add(iWorkingSet); } } return fileWorkingSets; }
Example 14
Source File: DotnetNewWizard.java From aCute with Eclipse Public License 2.0 | 5 votes |
private Set<IWorkingSet> getWorkingSets(IResource resource) { IWorkingSet[] allWorkingSets = PlatformUI.getWorkbench().getWorkingSetManager().getAllWorkingSets(); Set<IWorkingSet> fileWorkingSets = new HashSet<>(); for (IWorkingSet iWorkingSet : allWorkingSets) { IAdaptable[] elements = iWorkingSet.getElements(); if (Arrays.asList(elements).contains(resource.getProject())) { fileWorkingSets.add(iWorkingSet); } } return fileWorkingSets; }
Example 15
Source File: AbstractStatsView.java From eclipse-cs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Invoked on selection changes within the workspace. * * @param part * the workbench part the selection occurred * @param selection * the selection */ private void focusSelectionChanged(IWorkbenchPart part, ISelection selection) { List<IResource> resources = new ArrayList<>(); if (part instanceof IEditorPart) { IEditorPart editor = (IEditorPart) part; IFile file = getFile(editor.getEditorInput()); if (file != null) { resources.add(file); } } else { if (selection instanceof IStructuredSelection) { for (Iterator<?> iterator = ((IStructuredSelection) selection).iterator(); iterator .hasNext();) { Object object = iterator.next(); if (object instanceof IWorkingSet) { IWorkingSet workingSet = (IWorkingSet) object; IAdaptable[] elements = workingSet.getElements(); for (int i = 0; i < elements.length; i++) { considerAdaptable(elements[i], resources); } } else if (object instanceof IAdaptable) { considerAdaptable((IAdaptable) object, resources); } } } } IResource[] focusedResources = new IResource[resources.size()]; resources.toArray(focusedResources); // check if update necessary -> if so then update boolean updateNeeded = updateNeeded(mFocusedResources, focusedResources); if (updateNeeded) { mFocusedResources = focusedResources; getFilter().setFocusResource(focusedResources); refresh(); } }
Example 16
Source File: CleanUpAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void collectCompilationUnits(Object element, Collection<IJavaElement> result) { try { if (element instanceof IJavaElement) { IJavaElement elem= (IJavaElement)element; if (elem.exists()) { switch (elem.getElementType()) { case IJavaElement.TYPE: if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) { result.add(elem.getParent()); } break; case IJavaElement.COMPILATION_UNIT: result.add(elem); break; case IJavaElement.IMPORT_CONTAINER: result.add(elem.getParent()); break; case IJavaElement.PACKAGE_FRAGMENT: collectCompilationUnits((IPackageFragment)elem, result); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: collectCompilationUnits((IPackageFragmentRoot)elem, result); break; case IJavaElement.JAVA_PROJECT: IPackageFragmentRoot[] roots= ((IJavaProject)elem).getPackageFragmentRoots(); for (int k= 0; k < roots.length; k++) { collectCompilationUnits(roots[k], result); } break; } } } else if (element instanceof LogicalPackage) { IPackageFragment[] packageFragments= ((LogicalPackage)element).getFragments(); for (int k= 0; k < packageFragments.length; k++) { IPackageFragment pack= packageFragments[k]; if (pack.exists()) { collectCompilationUnits(pack, result); } } } else if (element instanceof IWorkingSet) { IWorkingSet workingSet= (IWorkingSet) element; IAdaptable[] elements= workingSet.getElements(); for (int j= 0; j < elements.length; j++) { collectCompilationUnits(elements[j], result); } } } catch (JavaModelException e) { if (JavaModelUtil.isExceptionToBeLogged(e)) JavaPlugin.log(e); } }
Example 17
Source File: PythonBaseModelProvider.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * The inputs for this method are: * * IWorkingSet (in which case it will return the projects -- IResource -- that are a part of the working set) * IResource (in which case it will return IWrappedResource or IResources) * IWrappedResource (in which case it will return IWrappedResources) * * @return the children for some element (IWrappedResource or IResource) */ @Override public Object[] getChildren(Object parentElement) { if (DEBUG) { System.out.println("getChildren for: " + parentElement); } Object[] childrenToReturn = null; if (parentElement instanceof IWrappedResource) { // we're below some python model childrenToReturn = getChildrenForIWrappedResource((IWrappedResource) parentElement); } else if (parentElement instanceof IResource) { // now, this happens if we're not below a python model(so, we may only find a source folder here) childrenToReturn = getChildrenForIResourceOrWorkingSet(parentElement); } else if (parentElement instanceof IWorkspaceRoot) { switch (topLevelChoice.getRootMode()) { case TopLevelProjectsOrWorkingSetChoice.WORKING_SETS: IWorkingSet[] workingSets = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets(); if (workingSets == null || workingSets.length == 0) { TreeNode noWorkingSets = createErrorNoWorkingSetsDefined(parentElement); return new Object[] { noWorkingSets }; } return workingSets; case TopLevelProjectsOrWorkingSetChoice.PROJECTS: //Just go on... } } else if (parentElement instanceof IWorkingSet) { if (parentElement instanceof IWorkingSet) { IWorkingSet workingSet = (IWorkingSet) parentElement; childrenToReturn = workingSet.getElements(); if (childrenToReturn == null || childrenToReturn.length == 0) { childrenToReturn = new Object[] { createErrorWorkingSetWithoutChildren(workingSet) }; } } } else if (parentElement instanceof TreeNode<?>) { TreeNode<?> treeNode = (TreeNode<?>) parentElement; return treeNode.getChildren().toArray(); } if (childrenToReturn == null) { childrenToReturn = EMPTY; } if (DEBUG) { System.out.println("getChildren RETURN: " + childrenToReturn); } return childrenToReturn; }
Example 18
Source File: JavaWorkingSetPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * {@inheritDoc} */ @Override protected Object[] getInitialWorkingSetElements(IWorkingSet workingSet) { Object[] elements; if (workingSet == null) { if (fInitialSelection == null) return new IAdaptable[0]; elements= fInitialSelection.toArray(); } else { elements= workingSet.getElements(); } // Use closed project for elements in closed project and remove PackageFragmentRootContainer elements int deletedElements= 0; for (int i= 0; i < elements.length; i++) { Object element= elements[i]; if (element instanceof IResource) { IProject project= ((IResource)element).getProject(); if (!project.isAccessible()) elements[i]= project; } else if (element instanceof PackageFragmentRootContainer) { for (int j= i; j < elements.length - 1; j++) elements[j]= elements[j + 1]; deletedElements++; } else if (element instanceof IJavaElement) { IJavaProject jProject= ((IJavaElement)element).getJavaProject(); if (jProject != null && !jProject.getProject().isAccessible()) elements[i]= jProject.getProject(); } else if (!(element instanceof IAdaptable) || ((IAdaptable)element).getAdapter(IProject.class) == null) { for (int j= i; j < elements.length - 1; j++) elements[j]= elements[j + 1]; deletedElements++; } } if (deletedElements == 0) return elements; IAdaptable[] result= new IAdaptable[elements.length - deletedElements]; System.arraycopy(elements, 0, result, 0, result.length); return result; }
Example 19
Source File: MultiOrganizeImportsHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
private void collectRelevantFiles(Object element, Multimap<IProject, IFile> result) { try { if (element instanceof IJavaElement) { IJavaElement elem = (IJavaElement) element; if (elem.exists()) { switch (elem.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT: collectRelevantFiles((IPackageFragment) elem, result); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: collectRelevantFiles((IPackageFragmentRoot) elem, result); break; case IJavaElement.JAVA_PROJECT: IPackageFragmentRoot[] roots; roots = ((IJavaProject) elem).getPackageFragmentRoots(); for (int k = 0; k < roots.length; k++) { collectRelevantFiles(roots[k], result); } break; } } } else if (element instanceof LogicalPackage) { IPackageFragment[] packageFragments = ((LogicalPackage) element).getFragments(); for (int k = 0; k < packageFragments.length; k++) { IPackageFragment pack = packageFragments[k]; if (pack.exists()) { collectRelevantFiles(pack, result); } } } else if (element instanceof IWorkingSet) { IWorkingSet workingSet = (IWorkingSet) element; IAdaptable[] elements = workingSet.getElements(); for (int j = 0; j < elements.length; j++) { collectRelevantFiles(elements[j], result); } } else if (element instanceof IFile) { collectIFiles(result, new Object[] { element }); } } catch (JavaModelException e) { e.printStackTrace(); } }
Example 20
Source File: WorkingSetModel.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public IAdaptable[] getChildren(IWorkingSet workingSet) { return workingSet.getElements(); }