Java Code Examples for org.eclipse.core.resources.IWorkspace#validatePath()

The following examples show how to use org.eclipse.core.resources.IWorkspace#validatePath() . 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: NewContainerDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void checkIfPathValid() {
	fFolder= null;

	String pathStr= fContainerDialogField.getText();
	if (pathStr.length() == 0) {
		fContainerFieldStatus.setError(NewWizardMessages.NewContainerDialog_error_enterpath);
		return;
	}
	IPath path= fCurrProject.getFullPath().append(pathStr);
	IWorkspace workspace= fCurrProject.getWorkspace();

	IStatus pathValidation= workspace.validatePath(path.toString(), IResource.FOLDER);
	if (!pathValidation.isOK()) {
		fContainerFieldStatus.setError(Messages.format(NewWizardMessages.NewContainerDialog_error_invalidpath, pathValidation.getMessage()));
		return;
	}
	IFolder folder= fCurrProject.getFolder(pathStr);
	if (isFolderExisting(folder)) {
		fContainerFieldStatus.setError(NewWizardMessages.NewContainerDialog_error_pathexists);
		return;
	}
	fContainerFieldStatus.setOK();
	fFolder= folder;
}
 
Example 2
Source File: H5ResourcePage.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
/**
   * Returns the path of the container resource specified in the container
   * name entry field, or <code>null</code> if no name has been typed in.
   * <p>
   * The container specified by the full path might not exist and would need to
   * be created.
   * </p>
   *
   * @return the full path of the container resource specified in
   *   the container name entry field, or <code>null</code>
   */
  protected IPath getContainerFullPath() {
      IWorkspace workspace = ResourcesPlugin.getWorkspace();

      //make the path absolute to allow for optional leading slash
      IPath testPath = getResourcePath();

      if (testPath.equals(workspace.getRoot().getFullPath())) {
	return testPath;
}

      IStatus result = workspace.validatePath(testPath.toString(),
              IResource.PROJECT | IResource.FOLDER | IResource.ROOT);
      if (result.isOK()) {
          return testPath;
      }

      return null;
  }
 
Example 3
Source File: WizardNewReportCreationPage.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isInValidFilePath() {
	String fn = getFileName();

	IPath resourcePath;
	if (!fn.endsWith("." + fileExtension)) //$NON-NLS-1$
	{
		resourcePath = getContainerFullPath().append(
				getFileName() + "." + fileExtension); //$NON-NLS-1$
	} else
		resourcePath = getContainerFullPath().append(getFileName());

	IWorkspace workspace = ResourcesPlugin.getWorkspace();

	IStatus result = workspace.validatePath(resourcePath
			.removeFileExtension().toString(), IResource.FOLDER);

	if (!result.isOK()) {
		setErrorMessage(result.getMessage());
		return true;
	}

	return false;
}
 
Example 4
Source File: WizardSaveAsPage.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a <code>boolean</code> indicating whether the specified resource
 * path represents a valid new resource in the workbench. An error message
 * is stored for future reference if the path does not represent a valid new
 * resource path.
 * 
 * @param resourcePath
 *            the path to validate
 * @return <code>boolean</code> indicating validity of the resource path
 */
protected boolean validateFullResourcePath( IPath resourcePath )
{
	IWorkspace workspace = ResourcesPlugin.getWorkspace( );

	IStatus result = workspace.validatePath( resourcePath.toString( ),
			IResource.FOLDER );
	if ( !result.isOK( ) )
	{
		problemType = PROBLEM_PATH_INVALID;
		problemMessage = result.getMessage( );
		return false;
	}

	if ( !allowExistingResources
			&& ( workspace.getRoot( ).getFolder( resourcePath ).exists( ) || workspace.getRoot( )
					.getFile( resourcePath )
					.exists( ) ) )
	{
		problemType = PROBLEM_RESOURCE_EXIST;
		problemMessage = Messages.getString( "WizardSaveAsPage.NameExists" ); //$NON-NLS-1$
		return false;
	}
	return true;
}
 
Example 5
Source File: JarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the resource for the specified path.
 *
 * @param path	the path for which the resource should be returned
 * @return the resource specified by the path or <code>null</code>
 */
protected IResource findResource(IPath path) {
	IWorkspace workspace= ResourcesPlugin.getWorkspace();
	IStatus result= workspace.validatePath(
						path.toString(),
						IResource.ROOT | IResource.PROJECT | IResource.FOLDER | IResource.FILE);
	if (result.isOK() && workspace.getRoot().exists(path))
		return workspace.getRoot().findMember(path);
	return null;
}
 
Example 6
Source File: JarOptionsPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the resource for the specified path.
 *
 * @param path	the path for which the resource should be returned
 * @return the resource specified by the path or <code>null</code>
 */
protected IResource findResource(IPath path) {
	IWorkspace workspace= JavaPlugin.getWorkspace();
	IStatus result= workspace.validatePath(
						path.toString(),
						IResource.ROOT | IResource.PROJECT | IResource.FOLDER | IResource.FILE);
	if (result.isOK() && workspace.getRoot().exists(path))
		return workspace.getRoot().findMember(path);
	return null;
}
 
Example 7
Source File: JarManifestWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the resource for the specified path.
 *
 * @param path	the path for which the resource should be returned
 * @return the resource specified by the path or <code>null</code>
 */
protected IResource findResource(IPath path) {
	IWorkspace workspace= JavaPlugin.getWorkspace();
	IStatus result= workspace.validatePath(
						path.toString(),
						IResource.ROOT | IResource.PROJECT | IResource.FOLDER | IResource.FILE);
	if (result.isOK() && workspace.getRoot().exists(path))
		return workspace.getRoot().findMember(path);
	return null;
}