Java Code Examples for org.eclipse.core.runtime.IPath#isRoot()

The following examples show how to use org.eclipse.core.runtime.IPath#isRoot() . 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: FileFieldSetter.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent event) {
  IPath inputPath = new Path(fileField.getText().trim());

  IPath filterPath = preProcessInputPath(inputPath);
  while (!filterPath.isEmpty() && !filterPath.isRoot() && !filterPath.toFile().isDirectory()) {
    filterPath = filterPath.removeLastSegments(1);
  }
  dialog.setFilterPath(filterPath.toString());
  dialog.setFilterExtensions(Arrays.copyOf(filterExtensions, filterExtensions.length));

  String result = dialog.open();
  if (result != null) {
    IPath pathToSet = postProcessResultPath(new Path(result));
    fileField.setText(pathToSet.toString());
  }
}
 
Example 2
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the tool tip text for the given element.
 * @param element the element
 * @return the tooltip for the element
 */
String getToolTipText(Object element) {
	String result;
	if (!(element instanceof IResource)) {
		result= JavaElementLabels.getTextLabel(element, AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS);
	} else {
		IPath path= ((IResource) element).getFullPath();
		if (path.isRoot()) {
			result= getConfigurationElement().getAttribute("name"); //$NON-NLS-1$
		} else {
			result= path.makeRelative().toString();
		}
	}

	if (fWorkingSetFilterActionGroup == null || fWorkingSetFilterActionGroup.getWorkingSet() == null)
		return result;

	IWorkingSet ws= fWorkingSetFilterActionGroup.getWorkingSet();
	String wsstr= Messages.format(JavaBrowsingMessages.JavaBrowsingPart_toolTip, new String[] { BasicElementLabels.getWorkingSetLabel(ws) });
	if (result.length() == 0)
		return wsstr;
	return Messages.format(JavaBrowsingMessages.JavaBrowsingPart_toolTip2, new String[] { result, BasicElementLabels.getWorkingSetLabel(ws) });
}
 
Example 3
Source File: ZipFileSystemObject.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getSourceLocation() {
    File file = new File(fArchivePath);
    try {
        file = file.getCanonicalFile();
    } catch (IOException e) {
        // Will still work but might have extra ../ in the path
    }
    URI uri = file.toURI();
    IPath entryPath = new Path(fFileSystemObject.getName());

    URI jarURI = entryPath.isRoot() ? URIUtil.toJarURI(uri, Path.EMPTY) : URIUtil.toJarURI(uri, entryPath);
    return URIUtil.toUnencodedString(jarURI);
}
 
Example 4
Source File: TarFileSystemObject.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getSourceLocation() {
    File file = new File(fArchivePath);
    try {
        file = file.getCanonicalFile();
    } catch (IOException e) {
        // Will still work but might have extra ../ in the path
    }
    URI uri = file.toURI();
    IPath entryPath = new Path(fFileSystemObject.getName());

    URI jarURI = entryPath.isRoot() ? URIUtil.toJarURI(uri, Path.EMPTY) : URIUtil.toJarURI(uri, entryPath);
    return URIUtil.toUnencodedString(jarURI);
}
 
Example 5
Source File: GzipFileSystemObject.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getSourceLocation() {
    File file = new File(fArchivePath);
    try {
        file = file.getCanonicalFile();
    } catch (IOException e) {
        // Will still work but might have extra ../ in the path
    }
    URI uri = file.toURI();
    IPath entryPath = new Path(fFileSystemObject.getName());

    URI jarURI = entryPath.isRoot() ? URIUtil.toJarURI(uri, Path.EMPTY) : URIUtil.toJarURI(uri, entryPath);
    return URIUtil.toUnencodedString(jarURI);
}
 
Example 6
Source File: SVNWorkspaceRoot.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
* Returns workspace resource for the given local file system <code>location</code>
* and which is a child of the given <code>parent</code> resource. Returns
* <code>parent</code> if parent's file system location equals to the given
* <code>location</code>. Returns <code>null</code> if <code>parent</code> is the
* workspace root.
*
* Resource does not have to exist in the workspace in which case resource
* type will be determined by the type of the local filesystem object.
*/
  public static IResource getResourceFor(IResource parent, IPath location) {
  	if (parent == null || location == null) {
  		return null;
  	}

  	if (parent instanceof IWorkspaceRoot) {
  		return null;
  	}

  	if (!isManagedBySubclipse(parent.getProject())) {
  		return null;
  	}

  	if (!parent.getLocation().isPrefixOf(location)) {
  		return null;
  	}

int segmentsToRemove = parent.getLocation().segmentCount();
  	IPath fullPath = parent.getFullPath().append(location.removeFirstSegments(segmentsToRemove));

  	IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

  	IResource resource = root.findMember(fullPath,true);

  	if (resource != null) {
  		return resource;
  	}

  	if (parent instanceof IFile) {
  		return null;
  	}

if (fullPath.isRoot()) {
	return root;
} else if (fullPath.segmentCount() == 1) {
	return root.getProject(fullPath.segment(0));
}

if (!location.toFile().exists()) {
	if (location.toFile().getName().indexOf(".") == -1) {
		return root.getFolder(fullPath);
	}
}

if (location.toFile().isDirectory()) {
	return root.getFolder(fullPath);
}

return root.getFile(fullPath);
  }
 
Example 7
Source File: Repository.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public IRepositoryFileStore asRepositoryFileStore(final Path path, boolean force)
        throws IOException, CoreException {
    if (!project.isAccessible() || project.getLocation() == null) {
        return null;
    }
    final IPath resourcePath = fromOSString(path.toString()).makeRelativeTo(project.getLocation());
    if (resourcePath.isRoot() || resourcePath.isEmpty()
            || Objects.equals(org.eclipse.core.runtime.Path.fromOSString(".."), resourcePath)) {
        return null;
    }
    IResource iResource = null;
    try {
        iResource = isFile(resourcePath) ? project.getFile(resourcePath) : project.getFolder(resourcePath);
    } catch (IllegalArgumentException e) {
        return null;
    }
    if (!iResource.exists()) {
        if (force) {
            iResource.getParent().refreshLocal(IResource.DEPTH_ONE, NULL_PROGRESS_MONITOR);
            if (!iResource.exists()) {
                throw new FileNotFoundException(path.toFile().getAbsolutePath());
            }
        } else {
            return null;
        }
    }

    final IPath projectRelativePath = iResource.getProjectRelativePath();
    if (projectRelativePath.segmentCount() > 0) {
        final IPath iPath = projectRelativePath.removeFirstSegments(0);
        if (iPath.segmentCount() > 1) {
            final String storeName = iPath.segments()[0];
            final IFile file = getProject().getFile(iPath);
            return getRepositoryStoreByName(storeName)
                    .filter(repositoryStore -> belongToRepositoryStore(repositoryStore, file))
                    .map(repositoryStore -> repositoryStore
                            .createRepositoryFileStore(file.getName()))
                    .orElse(null);
        }
    }
    return null;
}