IViewPart [] parts = MyPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getViews(); IProject activeProject = null; for(int i=0;i<parts.length;i++) { if(parts[i] instanceof ResourceNavigator) { ResourceNavigator navigator = (ResourceNavigator)parts[i]; StructuredSelection sel = (StructuredSelection)navigator.getTreeViewer().getSelection(); IResource resource = (IResource)sel.getFirstElement(); activeProject = resource.getProject(); break; } } String activeProjectName = activeProject .getName();
private IResource createSourceResource(IResourceDelta delta) { IPath sourcePath = delta.getMovedFromPath(); IResource resource = delta.getResource(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); switch (resource.getType()) { case IResource.PROJECT : return wsRoot.getProject(sourcePath.segment(0)); case IResource.FOLDER : return wsRoot.getFolder(sourcePath); case IResource.FILE : return wsRoot.getFile(sourcePath); } return null; }
public static IPath makeAbsolute(IPath p) { IPath absolutePath = p; if (p.toFile().exists()) { return p; } IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(p); if (resource != null && resource.exists()) { absolutePath = resource.getLocation(); } return absolutePath; }
@Override public void buildDelta(IResourceChangeDescriptionFactory builder) { IResource existing= ResourcesPlugin.getWorkspace().getRoot().findMember(fDestination); if (existing != null && !existing.equals(fResource)) { builder.delete(existing); } builder.copy(fResource, fDestination); } @Override
@Override public final Object convertToObject(final String parameterValue) throws ParameterValueConversionException { final Path path = new Path(parameterValue); final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace() .getRoot(); final IResource resource = workspaceRoot.findMember(path); if ((resource == null) || (!resource.exists())) { throw new ParameterValueConversionException( "parameterValue must be the path of an existing resource"); //$NON-NLS-1$ } return resource; }
private String getExpandedPath(String path) { if (path == null || path.length() == 0) return null; IResource resource = PDECore.getWorkspace().getRoot().findMember(new Path(path)); if (resource != null) { IPath fullPath = resource.getLocation(); return fullPath == null ? null : fullPath.toOSString(); } return null; }
public static class ClasspathResolutionBreakpointListener { public void breakpoint(int bp) { // override in listener implementation } }
public IProject[] getProjects(IJavaSearchScope scope) { IPath[] paths= scope.enclosingProjectsAndJars(); HashSet<IResource> temp= new HashSet<>(); for (int i= 0; i < paths.length; i++) { IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(paths[i]); if (resource != null && resource.getType() == IResource.PROJECT) temp.add(resource); } return temp.toArray(new IProject[temp.size()]); }
private String makeAbsolute(String input, ILaunchConfiguration configuration) throws CoreException { IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(input); if (member != null) { return member.getLocation().toPortableString(); } return input; }
@Override public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { IResource resource = getResource(); if (resource == null || !resource.exists()) return RefactoringStatus.createFatalErrorStatus(MessageFormat.format(PDEUIMessages.RenameProjectChange_projectDoesNotExist, fResourcePath.toString())); if (ResourcesPlugin.getWorkspace().getRoot().getProject(fNewName).exists()) return RefactoringStatus.createFatalErrorStatus(MessageFormat.format(PDEUIMessages.RenameProjectChange_destinationExists, fNewName)); return new RefactoringStatus(); }
/** * Returns the local file system location in which the meta data for the * given resource is stored. */ public IPath locationFor(IResource resource) { if (resource.getType() == IResource.ROOT) return metaAreaLocation.append(F_ROOT); return projectMetaLocation.append(resource.getProject().getName()); }
private String getPath(IResource resource) { final StringBuffer buffer= new StringBuffer(resource.getProject().getName()); final String path= resource.getParent().getProjectRelativePath().toString(); if (path.length() > 0) { buffer.append('/'); buffer.append(path); } return buffer.toString(); } }
static IPath getResourcePath(IResource resource){ return resource.getFullPath().removeFirstSegments(ResourcesPlugin.getWorkspace().getRoot().getFullPath().segmentCount()); }
private String formatResourceMessage(IResource element) { IContainer parent = element.getParent(); if (parent != null && parent.getType() != IResource.ROOT) return element.getName() + JavaElementLabels.CONCAT_STRING + parent.getFullPath().makeRelative().toString(); else return element.getName(); }
/** * Returns true if this resource represents the project description file, and * false otherwise. */ protected boolean isProjectDescriptionFile(IResource resource) { return resource.getType() == IResource.FILE && resource.getFullPath().segmentCount() == 2 && resource.getName().equals(IProjectDescription.DESCRIPTION_FILE_NAME); }
@Override public String selectArgument(IStringVariable variable, Shell shell) { ResourceListSelectionDialog dialog = new ResourceListSelectionDialog(shell, ResourcesPlugin.getWorkspace().getRoot(), IResource.FILE | IResource.FOLDER | IResource.PROJECT); dialog.setTitle(StringSubstitutionMessages.ResourceSelector_0); if (dialog.open() == Window.OK) { Object[] objects = dialog.getResult(); if (objects.length == 1) { return ((IResource)objects[0]).getFullPath().toString(); } } return null; }
@Override protected URI resolvePath(URI path) { IResource member = getWorkspace().getRoot().findMember(zipFilePath); if (member != null) return URI.createURI("archive:platform:/resource" + member.getFullPath().toString() + "!/" + path); return URI.createURI("archive:file:" + zipFilePath.toString() + "!/" + path); }
private boolean contains(IResource resource, IResource child) { if (resource.equals(child)) return true; if (depth == IResource.DEPTH_ZERO) return false; if (child.getParent().equals(resource)) return true; if (depth == IResource.DEPTH_INFINITE) return resource.getFullPath().isPrefixOf(child.getFullPath()); return false; }
public String getContainerPath() { if (resource != null) { if (resource.getType() == IResource.FILE) { return resource.getParent().getFullPath().toString(); } else { return resource.getFullPath().toString(); } } return ""; }
@Override public void copyValuesFromGUI() { if (resourcesUI.getSelectionCount() > 0) { pickedResource = (IResource)resourcesUI.getSelection()[0].getData(); IPath ipath = (null == pickedResource) ? null : pickedResource.getFullPath(); result = (null == ipath || (2 > ipath.segmentCount())) // project name alone cant be given to getFile ? null : new IFile[] {TAEConfiguratorPlugin.getWorkspace().getRoot().getFile(ipath)}; } }