Java Code Examples for org.eclipse.core.runtime.Path#lastSegment()

The following examples show how to use org.eclipse.core.runtime.Path#lastSegment() . 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: PullJob.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public PullJob(String userRunningTask, CredentialsProvider credentials, Path path, boolean force) {
	super(userRunningTask, true, (GitCredentialsProvider) credentials);
	// path: file/{...}
	this.path = path;
	this.projectName = path.lastSegment();
	// this.force = force; // TODO: enable when JGit starts to support this option
	setName(NLS.bind("Pulling {0}", projectName));
	setFinalMessage(NLS.bind("Pulling {0} done", projectName));
	setTaskExpirationTime(TimeUnit.DAYS.toMillis(7));
}
 
Example 2
Source File: DropAdapterAssistant.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Drop a trace by importing/linking a path in a trace folder
 *
 * @param path the source path
 * @param traceFolder the target trace folder
 * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK)
 * @return true if successful
 */
private static boolean drop(Path path,
        TmfTraceFolder traceFolder,
        int operation) {

    String targetName = path.lastSegment();
    for (ITmfProjectModelElement element : traceFolder.getChildren()) {
        if (element.getName().equals(targetName)) {
            targetName = promptRename(element);
            if (targetName == null) {
                return false;
            }
            break;
        }
    }
    if (operation == DND.DROP_COPY) {
        importTrace(traceFolder.getResource(), path, targetName);
    } else {
        createLink(traceFolder.getResource(), path, targetName);
    }
    IResource traceResource = traceFolder.getResource().findMember(targetName);
    if (traceResource != null && traceResource.exists()) {
        try {
            String sourceLocation = URIUtil.toUnencodedString(path.toFile().toURI());
            traceResource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
        } catch (CoreException e) {
            TraceUtils.displayErrorMsg(e);
        }
        setTraceType(traceResource);
    }
    return true;
}
 
Example 3
Source File: BuildPathsBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Validates output location & build path.
 */
private void updateOutputLocationStatus() {
	fOutputLocationPath= null;

	String text= fBuildPathDialogField.getText();
	if ("".equals(text)) { //$NON-NLS-1$
		fOutputFolderStatus.setError(NewWizardMessages.BuildPathsBlock_error_EnterBuildPath);
		return;
	}
	IPath path= getOutputLocation();
	fOutputLocationPath= path;

	IResource res= fWorkspaceRoot.findMember(path);
	if (res != null) {
		// if exists, must be a folder or project
		if (res.getType() == IResource.FILE) {
			fOutputFolderStatus.setError(NewWizardMessages.BuildPathsBlock_error_InvalidBuildPath);
			return;
		}
	}

	fOutputFolderStatus.setOK();

	String pathStr= fBuildPathDialogField.getText();
	Path outputPath= (new Path(pathStr));
	pathStr= outputPath.lastSegment();
	if (pathStr.equals(".settings") && outputPath.segmentCount() == 2) { //$NON-NLS-1$
		fOutputFolderStatus.setWarning(NewWizardMessages.OutputLocation_SettingsAsLocation);
	}

	if (pathStr.charAt(0) == '.' && pathStr.length() > 1) {
		fOutputFolderStatus.setWarning(Messages.format(NewWizardMessages.OutputLocation_DotAsLocation, BasicElementLabels.getResourceName(pathStr)));
	}

	updateBuildPathStatus();
}