/** * Returns the selected resources. * * @return the selected resources */ protected IResource[] getSelectedResources() { ArrayList resourceArray = new ArrayList(); IResource[] resources = (IResource[])getSelectedResources(IResource.class); for (int i = 0; i < resources.length; i++) resourceArray.add(resources[i]); ResourceMapping[] resourceMappings = (ResourceMapping[])getSelectedAdaptables(selection, ResourceMapping.class); for (int i = 0; i < resourceMappings.length; i++) { ResourceMapping resourceMapping = (ResourceMapping)resourceMappings[i]; try { ResourceTraversal[] traversals = resourceMapping.getTraversals(null, null); for (int j = 0; j < traversals.length; j++) { IResource[] traversalResources = traversals[j].getResources(); for (int k = 0; k < traversalResources.length; k++) { if (!resourceArray.contains(traversalResources[k])) resourceArray.add(traversalResources[k]); } } } catch (CoreException e) { SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e); } } IResource[] selectedResources = new IResource[resourceArray.size()]; resourceArray.toArray(selectedResources); return selectedResources; }
public static ResourceMapping create(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.TYPE: return create((IType) element); case IJavaElement.COMPILATION_UNIT: return create((ICompilationUnit) element); case IJavaElement.CLASS_FILE: return create((IClassFile) element); case IJavaElement.PACKAGE_FRAGMENT: return create((IPackageFragment) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return create((IPackageFragmentRoot) element); case IJavaElement.JAVA_PROJECT: return create((IJavaProject) element); case IJavaElement.JAVA_MODEL: return create((IJavaModel) element); default: return null; } }
public void copy( IPackageFragmentRoot sourceFolder, CopyArguments javaArgs, CopyArguments resourceArgs) { add(sourceFolder, javaArgs, null); ResourceMapping mapping = JavaElementResourceMapping.create(sourceFolder); if (mapping != null) { add(mapping, resourceArgs, null); } IResource sourceResource = sourceFolder.getResource(); if (sourceResource != null) { getResourceModifications().addCopyDelta(sourceResource, resourceArgs); IFile classpath = getClasspathFile((IResource) resourceArgs.getDestination()); if (classpath != null) { getResourceModifications().addChanged(classpath); } } }
@Override public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException { pm.beginTask(getName(), 2); try { String newName = getNewResourceName(); IPackageFragmentRoot root = getRoot(); ResourceMapping mapping = JavaElementResourceMapping.create(root); final Change result = doPerformReorg( getDestinationProjectPath().append(newName), new SubProgressMonitor(pm, 1)); markAsExecuted(root, mapping); return result; } finally { pm.done(); } }
private static <RES> List<RES> readFiles(ResourceMapping resourceMapping, final FileFilter<RES> fileFilter) { final List<RES> fileList = new ArrayList<RES>(1); IResourceVisitor visitor = new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (resource instanceof IFile == false) { return true; } else { IFile file = (IFile) resource; RES res = fileFilter.accept(file); if (res != null) { fileList.add(res); } return false; } } }; try { resourceMapping.accept(null, visitor, null); } catch (CoreException e) { throw new RuntimeException(e); } return fileList; }
public static ResourceMapping create(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.TYPE: return create((IType)element); case IJavaElement.COMPILATION_UNIT: return create((ICompilationUnit)element); case IJavaElement.CLASS_FILE: return create((IClassFile)element); case IJavaElement.PACKAGE_FRAGMENT: return create((IPackageFragment)element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return create((IPackageFragmentRoot)element); case IJavaElement.JAVA_PROJECT: return create((IJavaProject)element); case IJavaElement.JAVA_MODEL: return create((IJavaModel)element); default: return null; } }
/** * {@inheritDoc} */ public Object getAdapter(final Object adaptable, final Class adapter) { if (adaptable instanceof JavaModelProvider) { if (adapter == IResourceMappingMerger.class) return new JavaModelMerger((ModelProvider) adaptable); else if (adapter == ISynchronizationCompareAdapter.class) return new JavaSynchronizationCompareAdapter(); } else if (adaptable instanceof RefactoringHistory) { if (adapter == ResourceMapping.class) return new JavaRefactoringHistoryResourceMapping((RefactoringHistory) adaptable); else if (adapter == IResource.class) return new JavaRefactoringHistoryResourceMapping((RefactoringHistory) adaptable).getResource(); } else if (adaptable instanceof RefactoringDescriptorProxy) { if (adapter == ResourceMapping.class) return new JavaRefactoringDescriptorResourceMapping((RefactoringDescriptorProxy) adaptable); } return null; }
@SuppressWarnings("unchecked") @Override default <T> T getAdapter(final Class<T> adapter) { if (IWorkingSet.class == adapter || ResourceMapping.class == adapter) { return (T) new WorkingSetAdapter(this); } return Platform.getAdapterManager().getAdapter(this, adapter); }
/** * Returns the resource for the given input object, or * null if there is no resource associated with it. * * @param object the object to find the resource for * @return the resource for the given object, or null */ private IResource getResource(Object object) { if (object instanceof ResourceMapping) { object = ((ResourceMapping) object).getModelObject(); return getModelObjectResource(object); } if (object instanceof IResource) { return (IResource) object; } if (object instanceof IAdaptable) { return (IResource) ((IAdaptable) object).getAdapter( IResource.class); } return null; }
@Override public boolean contains(ResourceMapping mapping) { if (mapping instanceof JavaElementResourceMapping) { JavaElementResourceMapping javaMapping = (JavaElementResourceMapping) mapping; IJavaElement element = getJavaElement(); IJavaElement other = javaMapping.getJavaElement(); if (other != null && element != null) return element.getPath().isPrefixOf(other.getPath()); } return false; }
public static ResourceMapping create(final IPackageFragment pack) { // test if in an archive IPackageFragmentRoot root = (IPackageFragmentRoot) pack.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (!root.isArchive() && !root.isExternal()) { return new PackageFragmentResourceMapping(pack); } return null; }
public static ResourceMapping create(IClassFile classFile) { // test if in a archive IPackageFragmentRoot root = (IPackageFragmentRoot) classFile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (!root.isArchive() && !root.isExternal()) { return new ClassFileResourceMapping(classFile); } return null; }
public static ResourceMapping create(IType type) { // top level types behave like the CU IJavaElement parent = type.getParent(); if (parent instanceof ICompilationUnit) { return create((ICompilationUnit) parent); } return null; }
private void markAsExecuted(ICompilationUnit unit, ResourceMapping mapping) { ReorgExecutionLog log = (ReorgExecutionLog) getAdapter(ReorgExecutionLog.class); if (log != null) { log.markAsProcessed(unit); log.markAsProcessed(mapping); } }
@Override public Change perform(IProgressMonitor monitor) throws CoreException { ResourceMapping mapping = JavaElementResourceMapping.create(fOldCu); final Change result = super.perform(monitor); markAsExecuted(fOldCu, mapping); return result; }
public void copy(ICompilationUnit unit, CopyArguments javaArgs, CopyArguments resourceArgs) { add(unit, javaArgs, null); ResourceMapping mapping = JavaElementResourceMapping.create(unit); if (mapping != null) { add(mapping, resourceArgs, null); } if (unit.getResource() != null) { getResourceModifications().addCopyDelta(unit.getResource(), resourceArgs); } }
private void markAsExecuted(IPackageFragmentRoot root, ResourceMapping mapping) { // ReorgExecutionLog log= (ReorgExecutionLog)getAdapter(ReorgExecutionLog.class); // if (log != null) { // log.markAsProcessed(root); // log.markAsProcessed(mapping); // } }
@Override public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException { pm.beginTask(getName(), 1); try { ICompilationUnit unit = getCu(); ResourceMapping mapping = JavaElementResourceMapping.create(unit); Change result = doPerformReorg(new SubProgressMonitor(pm, 1)); markAsExecuted(unit, mapping); return result; } finally { pm.done(); } }
private void markAsExecuted(ICompilationUnit unit, ResourceMapping mapping) { // ReorgExecutionLog log= (ReorgExecutionLog)getAdapter(ReorgExecutionLog.class); // if (log != null) { // log.markAsProcessed(unit); // log.markAsProcessed(mapping); // } }
@Override public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException { pm.beginTask(getName(), 1); try { IPackageFragment pack = getPackage(); ResourceMapping mapping = JavaElementResourceMapping.create(pack); final Change result = doPerformReorg(pm); // markAsExecuted(pack, mapping); return result; } finally { pm.done(); } }
private void markAsExecuted(IPackageFragment pack, ResourceMapping mapping) { ReorgExecutionLog log = (ReorgExecutionLog) getAdapter(ReorgExecutionLog.class); if (log != null) { log.markAsProcessed(pack); log.markAsProcessed(mapping); } }
@Override public ResourceMapping getAdaptedResourceMapping(IAdaptable adaptable) { if (adaptable instanceof TreeElement<?, ?>) { TreeElement<?, ?> elt = (TreeElement<?, ?>) adaptable; return super.getAdaptedResourceMapping(elt.getJavaElement()); } return super.getAdaptedResourceMapping(adaptable); }
private void addOpenWithMenu(final IMenuManager aMenu) { final IStructuredSelection ss = (IStructuredSelection) getContext().getSelection(); if (ss == null || ss.size() != 1) { return; } final Object o = ss.getFirstElement(); // first try IResource IAdaptable openable = (IAdaptable) AdaptabilityUtility.getAdapter(o, IResource.class); // otherwise try ResourceMapping if (openable == null) { openable = (IAdaptable) AdaptabilityUtility.getAdapter(o, ResourceMapping.class); } else if (((IResource) openable).getType() != IResource.FILE) { openable = null; } if (openable != null) { // Create a menu flyout. final IMenuManager submenu = new MenuManager(WorkbenchNavigatorMessages.OpenActionProvider_OpenWithMenu_label, ICommonMenuConstants.GROUP_OPEN_WITH); submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP)); submenu.add(new OpenWithMenu(viewSite.getPage(), openable)); submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS)); // Add the submenu. if (submenu.getItems().length > 2 && submenu.isEnabled()) { aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu); } } }
private static <RES> List<RES> readFilesFromSelectionObject(Object element, FileFilter<RES> fileFilter) { if (element instanceof ResourceMapping == false) { return null; } ResourceMapping resourceMapping = (ResourceMapping) element; return readFiles(resourceMapping, fileFilter); }
private void markAsExecuted(ICompilationUnit unit, ResourceMapping mapping) { ReorgExecutionLog log= (ReorgExecutionLog) getAdapter(ReorgExecutionLog.class); if (log != null) { log.markAsProcessed(unit); log.markAsProcessed(mapping); } }
@Override public Change perform(IProgressMonitor monitor) throws CoreException { ResourceMapping mapping= JavaElementResourceMapping.create(fOldCu); final Change result= super.perform(monitor); markAsExecuted(fOldCu, mapping); return result; }
public void copy(IPackageFragmentRoot sourceFolder, CopyArguments javaArgs, CopyArguments resourceArgs) { add(sourceFolder, javaArgs, null); ResourceMapping mapping= JavaElementResourceMapping.create(sourceFolder); if (mapping != null) { add(mapping, resourceArgs, null); } IResource sourceResource= sourceFolder.getResource(); if (sourceResource != null) { getResourceModifications().addCopyDelta(sourceResource, resourceArgs); IFile classpath= getClasspathFile((IResource) resourceArgs.getDestination()); if (classpath != null) { getResourceModifications().addChanged(classpath); } } }
public void copy(ICompilationUnit unit, CopyArguments javaArgs, CopyArguments resourceArgs) { add(unit, javaArgs, null); ResourceMapping mapping= JavaElementResourceMapping.create(unit); if (mapping != null) { add(mapping, resourceArgs, null); } if (unit.getResource() != null) { getResourceModifications().addCopyDelta(unit.getResource(), resourceArgs); } }
public INewNameQuery createNewCompilationUnitNameQuery(final ICompilationUnit cu, final String initialSuggestedName) { return new INewNameQuery() { public String getNewName() throws OperationCanceledException { String result= fDelegate.createNewCompilationUnitNameQuery(cu, initialSuggestedName).getNewName(); String newName= JavaModelUtil.getRenamedCUName(cu, result); fExecutionLog.setNewName(cu, newName); ResourceMapping mapping= JavaElementResourceMapping.create(cu); if (mapping != null) { fExecutionLog.setNewName(mapping, newName); } return result; } }; }
public INewNameQuery createNewPackageFragmentRootNameQuery(final IPackageFragmentRoot root, final String initialSuggestedName) { return new INewNameQuery() { public String getNewName() throws OperationCanceledException { String result= fDelegate.createNewPackageFragmentRootNameQuery(root, initialSuggestedName).getNewName(); fExecutionLog.setNewName(root, result); ResourceMapping mapping= JavaElementResourceMapping.create(root); if (mapping != null) { fExecutionLog.setNewName(mapping, result); } return result; } }; }
public INewNameQuery createNewPackageNameQuery(final IPackageFragment pack, final String initialSuggestedName) { return new INewNameQuery() { public String getNewName() throws OperationCanceledException { String result= fDelegate.createNewPackageNameQuery(pack, initialSuggestedName).getNewName(); fExecutionLog.setNewName(pack, result); ResourceMapping mapping= JavaElementResourceMapping.create(pack); if (mapping != null) { int index= result.lastIndexOf('.'); String newFolderName= index == -1 ? result : result.substring(index + 1); fExecutionLog.setNewName(mapping, newFolderName); } return result; } }; }
@Override public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException { pm.beginTask(getName(), 2); try { String newName= getNewResourceName(); IPackageFragmentRoot root= getRoot(); ResourceMapping mapping= JavaElementResourceMapping.create(root); final Change result= doPerformReorg(getDestinationProjectPath().append(newName), new SubProgressMonitor(pm, 1)); markAsExecuted(root, mapping); return result; } finally { pm.done(); } }
private void markAsExecuted(IPackageFragmentRoot root, ResourceMapping mapping) { ReorgExecutionLog log= (ReorgExecutionLog)getAdapter(ReorgExecutionLog.class); if (log != null) { log.markAsProcessed(root); log.markAsProcessed(mapping); } }
@Override public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException { pm.beginTask(getName(), 1); try { ICompilationUnit unit= getCu(); ResourceMapping mapping= JavaElementResourceMapping.create(unit); Change result= doPerformReorg(new SubProgressMonitor(pm, 1)); markAsExecuted(unit, mapping); return result; } finally { pm.done(); } }
private void markAsExecuted(ICompilationUnit unit, ResourceMapping mapping) { ReorgExecutionLog log= (ReorgExecutionLog)getAdapter(ReorgExecutionLog.class); if (log != null) { log.markAsProcessed(unit); log.markAsProcessed(mapping); } }
@Override public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException { pm.beginTask(getName(), 1); try { IPackageFragment pack= getPackage(); ResourceMapping mapping= JavaElementResourceMapping.create(pack); final Change result= doPerformReorg(pm); markAsExecuted(pack, mapping); return result; } finally { pm.done(); } }