private IPathVariableManager getPathVariableManager() { if (currentResource != null) return currentResource.getPathVariableManager(); return ResourcesPlugin.getWorkspace().getPathVariableManager(); }
static public String getUniqueVariableName(String variable, IResource resource) { int index = 1; variable = getValidVariableName(variable); StringBuilder destVariable = new StringBuilder(variable); IPathVariableManager pathVariableManager = resource.getPathVariableManager(); if (variable.startsWith(ParentVariableResolver.NAME) || variable.startsWith(ProjectLocationVariableResolver.NAME)) destVariable.insert(0, "copy_"); //$NON-NLS-1$ while (pathVariableManager.isDefined(destVariable.toString())) { destVariable.append(index); index++; } return destVariable.toString(); }
static public String getUniqueVariableName(String variable, IResource resource) { int index = 1; variable = getValidVariableName(variable); String destVariable = variable; IPathVariableManager pathVariableManager = resource.getPathVariableManager(); if (destVariable.startsWith(ParentVariableResolver.NAME) || destVariable.startsWith(ProjectLocationVariableResolver.NAME)) destVariable = "copy_" + destVariable; //$NON-NLS-1$ while (pathVariableManager.isDefined(destVariable)) { destVariable = destVariable + index; index++; } return destVariable; }
/** * @param resource */ public void setResource(IResource resource) { currentResource = resource; if (resource != null) pathVariableManager = resource.getPathVariableManager(); else pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); removedVariableNames = new HashSet(); tempPathVariables = new TreeMap(); // initialize internal model initTemporaryState(); }
static public String getUniqueVariableName(String variable, IResource resource) { int index = 1; variable = getValidVariableName(variable); String destVariable = variable; IPathVariableManager pathVariableManager = resource.getPathVariableManager(); if (destVariable.startsWith(ParentVariableResolver.NAME) || destVariable.startsWith(ProjectLocationVariableResolver.NAME)) destVariable = "copy_" + destVariable; //$NON-NLS-1$ while (pathVariableManager.isDefined(destVariable)) { destVariable = destVariable + index; index++; } return destVariable; }
private IPathVariableManager getManager(IPath workspacePath) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = workspaceRoot.findMember(workspacePath); if (resource != null) return resource.getPathVariableManager(); return workspaceRoot.getFile(workspacePath).getPathVariableManager(); }
private IPathVariableManager getManager(IPath workspacePath) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = workspaceRoot.findMember(workspacePath); if (resource != null) return resource.getPathVariableManager(); return workspaceRoot.getFile(workspacePath).getPathVariableManager(); }
private IPathVariableManager getManager(IPath workspacePath) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = workspaceRoot.findMember(workspacePath); if (resource != null) return resource.getPathVariableManager(); return workspaceRoot.getFile(workspacePath).getPathVariableManager(); }
/** * @return the current IPathVariableManager */ private IPathVariableManager getPathVariableManager() { if (updatableResourceName != null && updatableResourceName.getResource() != null) return updatableResourceName.getResource().getPathVariableManager(); return ResourcesPlugin.getWorkspace().getPathVariableManager(); }
/** * Transform an absolute path URI to a relative path one (i.e. from "C:\foo\bar\file.txt" to * "VAR\file.txt" granted that the relativeVariable is "VAR" and points to "C:\foo\bar\"). * * @param location * @param resource * @return an URI that was made relative to a variable */ private IPath createRelativePath(IPath location, IResource resource) { if (relativeVariable == null) return location; if (relativeVariable.equals(ABSOLUTE_PATH)) return location; IPathVariableManager pathVariableManager = resource.getPathVariableManager(); try { return URIUtil.toPath( pathVariableManager.convertToRelative(URIUtil.toURI(location), true, relativeVariable)); } catch (CoreException e) { return location; } }
public IStatus validateLinkLocation(IResource resource, IPath unresolvedLocation) { IPath location = resource.getPathVariableManager().resolvePath(unresolvedLocation); if (location.isEmpty()) return new ResourceStatus(IResourceStatus.INVALID_VALUE, resource.getFullPath(), Messages.links_noPath); //check that the location is absolute if (!location.isAbsolute()) { //we know there is at least one segment, because of previous isEmpty check String message = NLS.bind(Messages.pathvar_undefined, location.toOSString(), location.segment(0)); return new ResourceStatus(IResourceStatus.VARIABLE_NOT_DEFINED_WARNING, resource.getFullPath(), message); } //if the location doesn't have a device, see if the OS will assign one if (location.getDevice() == null) location = new Path(location.toFile().getAbsolutePath()); return validateLinkLocationURI(resource, URIUtil.toURI(location)); }
public IStatus validateLinkLocation(IResource resource, IPath unresolvedLocation) { IPath location = resource.getPathVariableManager().resolvePath(unresolvedLocation); if (location.isEmpty()) return new ResourceStatus(IResourceStatus.INVALID_VALUE, resource.getFullPath(), Messages.links_noPath); //check that the location is absolute if (!location.isAbsolute()) { //we know there is at least one segment, because of previous isEmpty check String message = NLS.bind(Messages.pathvar_undefined, location.toOSString(), location.segment(0)); return new ResourceStatus(IResourceStatus.VARIABLE_NOT_DEFINED_WARNING, resource.getFullPath(), message); } //if the location doesn't have a device, see if the OS will assign one if (location.getDevice() == null) location = new Path(location.toFile().getAbsolutePath()); return validateLinkLocationURI(resource, URIUtil.toURI(location)); }
public IStatus validateLinkLocation(IResource resource, IPath unresolvedLocation) { IPath location = resource.getPathVariableManager().resolvePath(unresolvedLocation); if (location.isEmpty()) return new ResourceStatus(IResourceStatus.INVALID_VALUE, resource.getFullPath(), Messages.links_noPath); //check that the location is absolute if (!location.isAbsolute()) { //we know there is at least one segment, because of previous isEmpty check String message = NLS.bind(Messages.pathvar_undefined, location.toOSString(), location.segment(0)); return new ResourceStatus(IResourceStatus.VARIABLE_NOT_DEFINED_WARNING, resource.getFullPath(), message); } //if the location doesn't have a device, see if the OS will assign one if (location.getDevice() == null) location = new Path(location.toFile().getAbsolutePath()); return validateLinkLocationURI(resource, URIUtil.toURI(location)); }
/** * Transform an absolute path URI to a relative path one (i.e. from * "C:\foo\bar\file.txt" to "VAR\file.txt" granted that the relativeVariable * is "VAR" and points to "C:\foo\bar\"). * * @param locationURI * @return an URI that was made relative to a variable */ private URI createRelativePath(URI locationURI, IResource resource) { if (relativeVariable == null) return locationURI; IPath location = URIUtil.toPath(locationURI); IPath result; try { result = URIUtil.toPath(resource.getPathVariableManager().convertToRelative(URIUtil.toURI(location), true, relativeVariable)); } catch (CoreException e) { return locationURI; } return URIUtil.toURI(result); }
/** * Sets the dialog result to the concatenated variable name and extension. * * @param variable variable selected in the variables list and extended * by <code>extensionFile</code> * @param extensionFile file selected to extend the variable. */ private void setExtensionResult( PathVariablesGroup.PathVariableElement variable, IFileStore extensionFile) { IPath extensionPath = new Path(extensionFile.toString()); IPath selectionPath = variable.path; if (currentResource != null) selectionPath = URIUtil.toPath(currentResource.getPathVariableManager().resolveURI(URIUtil.toURI(selectionPath))); int matchCount = extensionPath.matchingFirstSegments(selectionPath); IPath resultPath = new Path(variable.name); extensionPath = extensionPath.removeFirstSegments(matchCount); resultPath = resultPath.append(extensionPath); setSelectionResult(new String[] { resultPath.toPortableString() }); }
protected void editLinkLocation() { IResource resource = Adapters.adapt(getElement(), IResource.class); String locationFormat = resource.getPathVariableManager().convertFromUserEditableFormat(locationValue.getText(), true); IPath location = Path.fromOSString(locationFormat); PathVariableDialog dialog = new PathVariableDialog(getShell(), PathVariableDialog.EDIT_LINK_LOCATION, resource.getType(), resource.getPathVariableManager(), null); dialog.setLinkLocation(location); dialog.setResource(resource); // opens the dialog - just returns if the user cancels it if (dialog.open() == Window.CANCEL) { return; } location = Path.fromOSString(dialog.getVariableValue()); newResourceLocation = location; refreshLinkLocation(); }
/** * Creates an IFileStore for a given workspace path. The prefix of the path of * the returned IFileStore corresponding to this root is canonicalized. * @exception CoreException If the file system for that resource is undefined */ IFileStore createStore(IPath workspacePath, IResource resource) throws CoreException { IPath childPath = workspacePath.removeFirstSegments(chop); IFileStore rootStore; final URI uri = resource.getPathVariableManager().resolveURI(getCanonicalRoot()); if (!uri.isAbsolute()) { //handles case where resource location cannot be resolved //such as unresolved path variable or invalid file system scheme return EFS.getNullFileSystem().getStore(workspacePath); } rootStore = EFS.getStore(uri); if (childPath.segmentCount() == 0) return rootStore; return rootStore.getFileStore(childPath); }
/** * Creates an IFileStore for a given workspace path. The prefix of the path of * the returned IFileStore corresponding to this root is canonicalized. * @exception CoreException If the file system for that resource is undefined */ IFileStore createStore(IPath workspacePath, IResource resource) throws CoreException { IPath childPath = workspacePath.removeFirstSegments(chop); IFileStore rootStore; final URI uri = resource.getPathVariableManager().resolveURI(getCanonicalRoot()); if (!uri.isAbsolute()) { //handles case where resource location cannot be resolved //such as unresolved path variable or invalid file system scheme return EFS.getNullFileSystem().getStore(workspacePath); } rootStore = EFS.getStore(uri); if (childPath.segmentCount() == 0) return rootStore; return rootStore.getFileStore(childPath); }
@Override public String getColumnText(Object obj, int index) { if (obj instanceof IResource) { IResource resource = (IResource) obj; if (index == NAME_COLUMN) return resource.getName(); else if (index == PATH_COLUMN) return resource.getParent() .getProjectRelativePath().toPortableString(); else { IPath rawLocation = resource.getRawLocation(); if (rawLocation != null) return resource.getPathVariableManager().convertToUserEditableFormat(rawLocation.toOSString(), true); } } else if ((obj instanceof String) && index == 0) return (String) obj; return null; }
void editLocation() { IResource resource = getSelectedResource()[0]; IPath location = resource.getRawLocation(); PathVariableDialog dialog = new PathVariableDialog( fConvertAbsoluteButton.getShell(), PathVariableDialog.EDIT_LINK_LOCATION, resource.getType(), resource.getPathVariableManager(), null); if (location != null) dialog.setLinkLocation(location); dialog.setResource(resource); if (dialog.open() == Window.CANCEL) { return; } location = Path.fromOSString(dialog.getVariableValue()); try { setLinkLocation(resource, location); } catch (Exception e) { e.printStackTrace(); } reparent(new IResource[] { resource }); }