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

The following examples show how to use org.eclipse.core.runtime.IPath#isEmpty() . 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: NativeLibrariesConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String chooseExternal() {
	IPath currPath= new Path(fPathField.getText());
	if (currPath.isEmpty()) {
		currPath= fEntry.getPath();
	} else {
		currPath= currPath.removeLastSegments(1);
	}

	DirectoryDialog dialog= new DirectoryDialog(fShell);
	dialog.setMessage(NewWizardMessages.NativeLibrariesDialog_external_message);
	dialog.setText(NewWizardMessages.NativeLibrariesDialog_extfiledialog_text);
	dialog.setFilterPath(currPath.toOSString());
	String res= dialog.open();
	if (res != null) {
		return res;
	}
	return null;
}
 
Example 2
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 3
Source File: ResourceForIEditorInputFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected ResourceSet getResourceSet(/* @Nullable */ IStorage storage) {
	if (storage instanceof IFile) {
		return resourceSetProvider.get(((IFile) storage).getProject());
	}
	if (workspace != null && storage != null) {
		IPath path = storage.getFullPath();
		if (path != null && !path.isEmpty()) {
			String firstSegment = path.segment(0);
			if (firstSegment != null) {
				IProject project = workspace.getRoot().getProject(firstSegment);
				if (project.isAccessible()) {
					return resourceSetProvider.get(project);
				}
			}
		}
	}
	return resourceSetProvider.get(null);
}
 
Example 4
Source File: NodeJSService.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public IStatus validateSourcePath(IPath path)
{
	if (path == null || path.isEmpty())
	{
		return new Status(Status.ERROR, JSCorePlugin.PLUGIN_ID, Messages.NodeJSService_EmptySourcePath);
	}

	if (!path.toFile().isDirectory())
	{
		return new Status(Status.ERROR, JSCorePlugin.PLUGIN_ID, INodeJS.ERR_DOES_NOT_EXIST, MessageFormat.format(
				Messages.NodeJSService_NoDirectory_0, path), null);
	}

	if (!path.append(LIB).toFile().isDirectory())
	{
		return new Status(Status.ERROR, JSCorePlugin.PLUGIN_ID, MessageFormat.format(
				Messages.NodeJSService_InvalidLocation_0, LIB));
	}
	// TODO Any other things we want to check for to "prove" it's a NodeJS source install?

	return Status.OK_STATUS;
}
 
Example 5
Source File: MavenUtils.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Given the path of an artifact in a local Maven repository and its group id, and the artifact id
 * of a peer artifact, return the path in the local Maven repository of the peer artifact.
 *
 * For example, with a base artifact path of
 * <code>/home/user/.m2/com/google/gwt/gwt-user/2.1/gwt-user-2.1.jar</code>, a group id of
 * <code>com.google.gwt</code>, and a peer artifact id of <code>gwt-dev.jar</code>, the returned
 * path would be <code>/home/user/.m2/com/google/gwt/gwt-dev/2.1/gwt-dev-2.1.jar</code>.
 */
public static IPath getArtifactPathForPeerMavenArtifact(IPath baseArtifactPath, String groupId,
    String peerArtifactId) {
  if (baseArtifactPath == null || baseArtifactPath.isEmpty()) {
    return null;
  }

  if (StringUtilities.isEmpty(groupId)) {
    return null;
  }

  if (StringUtilities.isEmpty(peerArtifactId)) {
    return null;
  }

  MavenInfo baseArtifactInfo = MavenInfo.create(baseArtifactPath, groupId);

  if (baseArtifactInfo == null) {
    return null;
  }

  return generateArtifactPath(baseArtifactInfo.getRepositoryPath(), groupId,
      baseArtifactInfo.getVersion(), peerArtifactId, baseArtifactInfo.computeArtifactNameSuffix());
}
 
Example 6
Source File: WorkspaceWizardPage.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This method should be invoked whenever source folder or project value change, to update the proposal contexts for
 * the field source folder and module specifier
 */
private void updateProposalContext() {
	IPath projectPath = model.getProject();
	IPath sourceFolderPath = model.getSourceFolder();

	// Early exit for empty project value
	if (projectPath.isEmpty()) {
		sourceFolderContentProposalAdapter.setContentProposalProvider(null);
		moduleSpecifierContentProposalAdapter.setContentProposalProvider(null);
		return;
	}

	IProject project = ResourcesPlugin.getWorkspace().getRoot()
			.getProject(projectPath.toString());

	if (null == project || !project.exists()) {
		// Disable source folder and module specifier proposals
		sourceFolderContentProposalAdapter.setContentProposalProvider(null);
		moduleSpecifierContentProposalAdapter.setContentProposalProvider(null);
	} else {
		// Try to retrieve the source folder and if not specified set it to null
		IContainer sourceFolder = sourceFolderPath.segmentCount() != 0 ? project.getFolder(sourceFolderPath) : null;

		// If the project exists, enable source folder proposals
		sourceFolderContentProposalAdapter
				.setContentProposalProvider(sourceFolderContentProviderFactory.createProviderForProject(project));

		if (null != sourceFolder && sourceFolder.exists()) {
			// If source folder exists as well enable module specifier proposal
			moduleSpecifierContentProposalAdapter.setContentProposalProvider(
					moduleSpecifierContentProviderFactory.createProviderForPath(sourceFolder.getFullPath()));
		} else {
			// Otherwise disable module specifier proposals
			moduleSpecifierContentProposalAdapter.setContentProposalProvider(null);
		}
	}
}
 
Example 7
Source File: BuildPathSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds a source attachment for a new archive in the existing classpaths.
 * @param elem The new classpath entry
 * @return A path to be taken for the source attachment or <code>null</code>
 */
public static IPath guessSourceAttachment(CPListElement elem) {
	if (elem.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
		return null;
	}
	IJavaProject currProject= elem.getJavaProject(); // can be null
	try {
		IJavaModel jmodel= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
		IJavaProject[] jprojects= jmodel.getJavaProjects();
		for (int i= 0; i < jprojects.length; i++) {
			IJavaProject curr= jprojects[i];
			if (!curr.equals(currProject)) {
				IClasspathEntry[] entries= curr.getRawClasspath();
				for (int k= 0; k < entries.length; k++) {
					IClasspathEntry entry= entries[k];
					if (entry.getEntryKind() == elem.getEntryKind()
						&& entry.getPath().equals(elem.getPath())) {
						IPath attachPath= entry.getSourceAttachmentPath();
						if (attachPath != null && !attachPath.isEmpty()) {
							return attachPath;
						}
					}
				}
			}
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e.getStatus());
	}
	return null;
}
 
Example 8
Source File: NewJavaProjectPreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static String encodePath(IPath path) {
	if (path == null) {
		return "#"; //$NON-NLS-1$
	} else if (path.isEmpty()) {
		return "&"; //$NON-NLS-1$
	} else {
		return encode(path.toPortableString());
	}
}
 
Example 9
Source File: JSIndexQueryHelper.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Determines the name of the type holding the object exported for the module defined in the given filepath.
 * 
 * @param absolutePath
 * @return
 */
public String getModuleType(IPath absolutePath)
{
	if (absolutePath == null || absolutePath.isEmpty())
	{
		return null;
	}

	// TODO Do smart lookup of the index that should contain the file?
	for (Index index : indices)
	{
		// Look up our mapping from generated type names to documents
		List<QueryResult> results = index.query(new String[] { IJSIndexConstants.MODULE_DEFINITION }, "*", //$NON-NLS-1$
				SearchPattern.PATTERN_MATCH);
		final String fileURI = absolutePath.toFile().toURI().toString();
		// Find the module declared in the file we resolved to...
		QueryResult match = CollectionsUtil.find(results, new IFilter<QueryResult>()
		{
			public boolean include(QueryResult item)
			{
				return item.getDocuments().contains(fileURI);
			}
		});
		if (match != null)
		{
			// Now use the stored generated type name...
			return match.getWord() + ".exports"; //$NON-NLS-1$
		}
	}
	return null;
}
 
Example 10
Source File: HostPagePathSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void setInitialPath(IPath initialPath) {
  if (!initialPath.isEmpty()) {
    for (HostPagePathTreeItem treeItem : rootTreeItems) {
      HostPagePathTreeItem initialSelection = treeItem.findPath(initialPath);
      if (initialSelection != null) {
        setInitialSelection(initialSelection);
        return;
      }
    }
  }
}
 
Example 11
Source File: VariablePathDialogField.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getVariable() {
	IPath path= getPath();
	if (!path.isEmpty()) {
		return path.segment(0);
	}
	return null;
}
 
Example 12
Source File: SdkManager.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public T findSdkForPath(IPath path) {
  if (path.isEmpty()) {
    return null;
  }

  SdkSet<T> sdks = getSdks();
  if (SdkClasspathContainer.isDefaultContainerPath(containerId, path)) {
    // If no specific SDK name was provided return the default
    return sdks.getDefault();
  }

  // Segment 0 is the container ID, segment 1 is the sdk name
  return sdks.findSdk(path.segment(1));
}
 
Example 13
Source File: TypeScriptBuildPath.java    From typescript.java with MIT License 5 votes vote down vote up
private static IPath toTsconfigFilePath(IPath path, IProject project) {
	if (path.isEmpty()) {
		return path.append(FileUtils.TSCONFIG_JSON);
	}
	if (project.exists(path)) {
		IResource resource = project.findMember(path);
		if (resource.getType() == IResource.FOLDER) {
			return path.append(FileUtils.TSCONFIG_JSON);
		}
	}
	return path;
}
 
Example 14
Source File: MavenBuildSupport.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void discoverSource(IClassFile classFile, IProgressMonitor monitor) throws CoreException {
	if (classFile == null) {
		return;
	}
	IJavaElement element = classFile;
	while (element.getParent() != null) {
		element = element.getParent();
		if (element instanceof IPackageFragmentRoot) {
			final IPackageFragmentRoot fragment = (IPackageFragmentRoot) element;
			IPath attachmentPath = fragment.getSourceAttachmentPath();
			if (attachmentPath != null && !attachmentPath.isEmpty() && attachmentPath.toFile().exists()) {
				break;
			}
			if (fragment.isArchive()) {
				IPath path = fragment.getPath();
				Boolean downloaded = downloadRequestsCache.getIfPresent(path.toString());
				if (downloaded == null) {
					downloadRequestsCache.put(path.toString(), true);
					IClasspathManager buildpathManager = MavenJdtPlugin.getDefault().getBuildpathManager();
					buildpathManager.scheduleDownload(fragment, true, true);
					JobHelpers.waitForDownloadSourcesJobs(MAX_TIME_MILLIS);
				}
				break;
			}
		}
	}
}
 
Example 15
Source File: JdtHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isFromOutputPath(IResource resource) {
	IProject project = resource.getProject();
	IJavaProject javaProject = JavaCore.create(project);
	if (javaProject != null && javaProject.exists()) {
		try {
			IPath defaultOutputLocation = javaProject.getOutputLocation();
			IPath resourcePath = resource.getFullPath();
			if (defaultOutputLocation != null && !defaultOutputLocation.isEmpty() && defaultOutputLocation.isPrefixOf(resourcePath)) {
				return true;
			}
			IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
			for(IClasspathEntry classpathEntry: classpathEntries) {
				if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
					IPath specializedOutputLocation = classpathEntry.getOutputLocation();
					if (specializedOutputLocation != null) {
						if (!specializedOutputLocation.equals(classpathEntry.getPath()) && 
								specializedOutputLocation.isPrefixOf(resourcePath)) {
							return true;
						}
					}
				}
			}
		} catch(CoreException e) {
			if (log.isDebugEnabled())
				log.debug("Error in isJavaTargetFolder():" + e.getMessage(), e);
		}
	}
	return false;
}
 
Example 16
Source File: CPVariableElementLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String getText(Object element) {
	if (element instanceof CPVariableElement) {
		CPVariableElement curr= (CPVariableElement)element;
		String name= curr.getName();
		IPath path= curr.getPath();

		String result= name;
		ArrayList<String> restrictions= new ArrayList<String>(2);

		if (curr.isReadOnly() && fHighlightReadOnly) {
			restrictions.add(NewWizardMessages.CPVariableElementLabelProvider_read_only);
		}
		if (curr.isDeprecated()) {
			restrictions.add(NewWizardMessages.CPVariableElementLabelProvider_deprecated);
		}
		if (restrictions.size() == 1) {
			result= Messages.format(NewWizardMessages.CPVariableElementLabelProvider_one_restriction, new Object[] {result, restrictions.get(0)});
		} else if (restrictions.size() == 2) {
			result= Messages.format(NewWizardMessages.CPVariableElementLabelProvider_two_restrictions, new Object[] {result, restrictions.get(0), restrictions.get(1)});
		}

		if (path != null) {
			String appendix;
			if (!path.isEmpty()) {
				appendix= BasicElementLabels.getPathLabel(path, true);
			} else {
				appendix= NewWizardMessages.CPVariableElementLabelProvider_empty;
			}
			result= Messages.format(NewWizardMessages.CPVariableElementLabelProvider_appendix, new Object[] {result, appendix});
		}

		return result;
	}


	return super.getText(element);
}
 
Example 17
Source File: CPListLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private ImageDescriptor getCPListElementBaseImage(CPListElement cpentry) {
	switch (cpentry.getEntryKind()) {
		case IClasspathEntry.CPE_SOURCE:
			if (cpentry.getPath().segmentCount() == 1) {
				return fProjectImage;
			} else {
				return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_PACKFRAG_ROOT);
			}
		case IClasspathEntry.CPE_LIBRARY:
			IResource res= cpentry.getResource();
			IPath path= (IPath) cpentry.getAttribute(CPListElement.SOURCEATTACHMENT);
			if (res == null) {
				if (ArchiveFileFilter.isArchivePath(cpentry.getPath(), true)) {
					if (path == null || path.isEmpty()) {
						return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE);
					} else {
						return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE_WITH_SOURCE);
					}
				} else {
					if (path == null || path.isEmpty()) {
						return JavaPluginImages.DESC_OBJS_CLASSFOLDER;
					} else {
						return JavaPluginImages.DESC_OBJS_CLASSFOLDER_WSRC;
					}
				}
			} else if (res instanceof IFile) {
				if (path == null || path.isEmpty()) {
					return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_JAR);
				} else {
					return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_JAR_WITH_SOURCE);
				}
			} else {
				return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_PACKFRAG_ROOT);
			}
		case IClasspathEntry.CPE_PROJECT:
			return fProjectImage;
		case IClasspathEntry.CPE_VARIABLE:
			ImageDescriptor variableImage= fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_CLASSPATH_VAR_ENTRY);
			if (cpentry.isDeprecated()) {
				return new JavaElementImageDescriptor(variableImage, JavaElementImageDescriptor.DEPRECATED, JavaElementImageProvider.SMALL_SIZE);
			}
			return variableImage;
		case IClasspathEntry.CPE_CONTAINER:
			return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_LIBRARY);
		default:
			return null;
	}
}
 
Example 18
Source File: BuildPathCommand.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static Result removeFromSourcePath(String sourceFolderUri) {
	IPath sourceFolderPath = ResourceUtils.filePathFromURI(sourceFolderUri);
	IProject targetProject = findBelongedProject(sourceFolderPath);
	if (targetProject != null && !ProjectUtils.isGeneralJavaProject(targetProject)) {
		String message = ProjectUtils.isGradleProject(targetProject) ? UNSUPPORTED_ON_GRADLE : UNSUPPORTED_ON_MAVEN;
		return new Result(false, message);
	}

	IPath projectLocation = null;
	IContainer projectRootResource = null;
	if (targetProject == null) {
		IPath workspaceRoot = ProjectUtils.findBelongedWorkspaceRoot(sourceFolderPath);
		if (workspaceRoot == null) {
			return new Result(false, Messages.format("The folder ''{0}'' doesn''t belong to any workspace.", getWorkspacePath(sourceFolderPath).toOSString()));
		}

		String invisibleProjectName = ProjectUtils.getWorkspaceInvisibleProjectName(workspaceRoot);
		targetProject = ResourcesPlugin.getWorkspace().getRoot().getProject(invisibleProjectName);
		if (!targetProject.exists()) {
			return new Result(true, Messages.format("No need to remove it from source path, because the folder ''{0}'' isn''t on any project''s source path.", getWorkspacePath(sourceFolderPath).toOSString()));
		}

		projectLocation = workspaceRoot;
		projectRootResource = targetProject.getFolder(ProjectUtils.WORKSPACE_LINK);
	} else {
		projectLocation = targetProject.getLocation();
		projectRootResource = targetProject;
	}

	IPath relativeSourcePath = sourceFolderPath.makeRelativeTo(projectLocation);
	IPath sourcePath = relativeSourcePath.isEmpty() ? projectRootResource.getFullPath() : projectRootResource.getFolder(relativeSourcePath).getFullPath();
	IJavaProject javaProject = JavaCore.create(targetProject);
	try {
		if (ProjectUtils.removeSourcePath(sourcePath, javaProject)) {
			return new Result(true, Messages.format("Successfully removed ''{0}'' from the project {1}''s source path.", new String[] { getWorkspacePath(sourceFolderPath).toOSString(), targetProject.getName() }));
		} else {
			return new Result(true, Messages.format("No need to remove it from source path, because the folder ''{0}'' isn''t on any project''s source path.", getWorkspacePath(sourceFolderPath).toOSString()));
		}
	} catch (CoreException e) {
		return new Result(false, e.getMessage());
	}
}
 
Example 19
Source File: ClassFileEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root) throws JavaModelException {
	IClasspathEntry entry;
	try {
		entry= JavaModelUtil.getClasspathEntry(root);
	} catch (JavaModelException ex) {
		if (ex.isDoesNotExist())
			entry= null;
		else
			throw ex;
	}
	IPath containerPath= null;

	if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) {
		createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSource, BasicElementLabels.getFileName( fFile)));
		return;
	}

	IJavaProject jproject= root.getJavaProject();
	boolean canEditEncoding= true;
	if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
		containerPath= entry.getPath();
		ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
		IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
		if (initializer == null || container == null) {
			createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_cannotconfigure, BasicElementLabels.getPathLabel(containerPath, false)));
			return;
		}
		String containerName= container.getDescription();
		IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject);
		if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
			createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_notsupported, containerName));
			return;
		}
		if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
			createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_readonly, containerName));
			return;
		}
		IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING);
		canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY);
		entry= JavaModelUtil.findEntryInContainer(container, root.getPath());
		Assert.isNotNull(entry);
	}


	Button button;

	IPath path= entry.getSourceAttachmentPath();
	if (path == null || path.isEmpty()) {
		String rootLabel= JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT);
		createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceAttachment, rootLabel));
		createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToAttach);
		createLabel(composite, null);

		button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_attachSource);

	} else {
		createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceInAttachment, BasicElementLabels.getFileName(fFile)));
		createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToChange);
		createLabel(composite, null);

		button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_changeAttachedSource);
	}

	button.addSelectionListener(getButtonListener(entry, containerPath, jproject, canEditEncoding));
}
 
Example 20
Source File: NewCodewindProjectPage.java    From codewind-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private boolean validate() {
	if (!validatePage()) {
		return false;
	}
	if (templateList == null || templateList.isEmpty()) {
		setErrorMessage(Messages.NewProjectPage_EmptyTemplateList);
		return false;
	}
	String projectName = getProjectName();
	if (projectName == null || projectName.isEmpty()) {
		setErrorMessage(Messages.NewProjectPage_EmptyProjectName);
		return false;
	}
	if (!projectNamePattern.matcher(projectName).matches()) {
		setErrorMessage(Messages.NewProjectPage_InvalidProjectName);
		return false;
	}
	if (connection.getAppByName(projectName) != null) {
		setErrorMessage(NLS.bind(Messages.NewProjectPage_ProjectExistsError, projectName));
		return false;
	}
	IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
	if (project != null && project.exists()) {
		setErrorMessage(NLS.bind(Messages.NewProjectPage_EclipseProjectExistsError, projectName));
		return false;
	}
	IPath location = getLocationPath();
	if (location == null || location.isEmpty()) {
		setErrorMessage(Messages.NewProjectPage_NoLocationError);
		return false;
	}

	// It is an error if the project is located in the codewind-data folder
	IPath dataPath = CoreUtil.getCodewindDataPath();
	if (dataPath != null && dataPath.isPrefixOf(location)) {
		setErrorMessage(NLS.bind(Messages.ProjectLocationInCodewindDataDirError, dataPath.toOSString()));
		return false;
	}
	
	if (selectionTable.getSelectionCount() != 1) {
		setErrorMessage(Messages.NewProjectPage_NoTemplateSelected);
		return false;
	}
	setErrorMessage(null);
	return true;
}