Java Code Examples for org.eclipse.jdt.internal.ui.dialogs.StatusInfo#setWarning()

The following examples show how to use org.eclipse.jdt.internal.ui.dialogs.StatusInfo#setWarning() . 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 IStatus validatePath() {
	StatusInfo status= new StatusInfo();
	String val= fPathField.getText();
	if (val.length() == 0) {
		return status;
	}
	Path path= new Path(val);
	if (path.isAbsolute()) {
		if (!path.toFile().isDirectory()) {
			status.setWarning(NewWizardMessages.NativeLibrariesDialog_error_external_not_existing);
			return status;
		}
	} else {
		if (!(ResourcesPlugin.getWorkspace().getRoot().findMember(path) instanceof IContainer)) {
			status.setWarning(NewWizardMessages.NativeLibrariesDialog_error_internal_not_existing);
			return status;
		}
	}
	return status;
}
 
Example 2
Source File: JavadocStandardWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
final void doValidation(int VALIDATE) {
	switch (VALIDATE) {
		case STYLESHEETSTATUS :
			fStyleSheetStatus= new StatusInfo();
			if (fStyleSheetButton.getSelection()) {
				String filename= fStyleSheetText.getText();
				if (filename.length() == 0) {
					fStyleSheetStatus.setError(JavadocExportMessages.JavadocSpecificsWizardPage_overviewnotfound_error);
				} else {
					File file= new File(filename);
					String ext= filename.substring(filename.lastIndexOf('.') + 1);
					if (!file.isFile()) {
						fStyleSheetStatus.setError(JavadocExportMessages.JavadocStandardWizardPage_stylesheetnopath_error);
					} else if (!ext.equalsIgnoreCase("css")) { //$NON-NLS-1$
						fStyleSheetStatus.setError(JavadocExportMessages.JavadocStandardWizardPage_stylesheetnotcss_error);
					}
				}
			}
			break;
		case LINK_REFERENCES:
			fLinkRefStatus= new StatusInfo();
			List<JavadocLinkRef> list= fListDialogField.getCheckedElements();
			for (int i= 0; i < list.size(); i++) {
				JavadocLinkRef curr= list.get(i);
				URL url= curr.getURL();
				if (url == null) {
					fLinkRefStatus.setWarning(JavadocExportMessages.JavadocStandardWizardPage_nolinkref_error);
					break;
				} else if ("jar".equals(url.getProtocol())) { //$NON-NLS-1$
					fLinkRefStatus.setWarning(JavadocExportMessages.JavadocStandardWizardPage_nojarlinkref_error);
					break;
				}
			}
			break;
	}

	updateStatus(findMostSevereStatus());

}
 
Example 3
Source File: VariableCreationDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private StatusInfo pathUpdated() {
	StatusInfo status= new StatusInfo();

	String path= fPathField.getText();
	if (path.length() > 0) { // empty path is ok
		if (!Path.ROOT.isValidPath(path)) {
			status.setError(NewWizardMessages.VariableCreationDialog_error_invalidpath);
		} else if (!new File(path).exists()) {
			status.setWarning(NewWizardMessages.VariableCreationDialog_warning_pathnotexists);
		}
	}
	return status;
}
 
Example 4
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Validate the new entry in the context of the existing entries. Furthermore,
 * check if exclusion filters need to be applied and do so if necessary.
 *
 * If validation was successful, add the new entry to the list of existing entries.
 *
 * @param entry the entry to be validated and added to the list of existing entries.
 * @param existingEntries a list of existing entries representing the build path
 * @param project the Java project
 * @throws CoreException in case that validation fails
 */
private static void validateAndAddEntry(CPListElement entry, List<CPListElement> existingEntries, IJavaProject project) throws CoreException {
	IPath path= entry.getPath();
	IPath projPath= project.getProject().getFullPath();
	IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
	IStatus validate= workspaceRoot.getWorkspace().validatePath(path.toString(), IResource.FOLDER);
	StatusInfo rootStatus= new StatusInfo();
	rootStatus.setOK();
	boolean isExternal= isExternalArchiveOrLibrary(entry);
	if (!isExternal && validate.matches(IStatus.ERROR) && !project.getPath().equals(path)) {
		rootStatus.setError(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_error_InvalidRootName, validate.getMessage()));
		throw new CoreException(rootStatus);
	} else {
		if (!isExternal && !project.getPath().equals(path)) {
			IResource res= workspaceRoot.findMember(path);
			if (res != null) {
				if (res.getType() != IResource.FOLDER && res.getType() != IResource.FILE) {
					rootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_NotAFolder);
					throw new CoreException(rootStatus);
				}
			} else {
				URI projLocation= project.getProject().getLocationURI();
				if (projLocation != null) {
					IFileStore store= EFS.getStore(projLocation).getFileStore(path);
					if (store.fetchInfo().exists()) {
						rootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExistingDifferentCase);
						throw new CoreException(rootStatus);
					}
				}
			}
		}

		for (int i= 0; i < existingEntries.size(); i++) {
			CPListElement curr= existingEntries.get(i);
			if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
				if (path.equals(curr.getPath()) && !project.getPath().equals(path)) {
					rootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting);
					throw new CoreException(rootStatus);
				}
			}
		}

		if (!isExternal && !entry.getPath().equals(project.getPath()))
			exclude(entry.getPath(), existingEntries, new ArrayList<CPListElement>(), project, null);

		IPath outputLocation= project.getOutputLocation();
		insertAtEndOfCategory(entry, existingEntries);

		IClasspathEntry[] entries= convert(existingEntries);

		IJavaModelStatus status= JavaConventions.validateClasspath(project, entries, outputLocation);
		if (!status.isOK()) {
			if (outputLocation.equals(projPath)) {
				IStatus status2= JavaConventions.validateClasspath(project, entries, outputLocation);
				if (status2.isOK()) {
					if (project.isOnClasspath(project)) {
						rootStatus.setInfo(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSFandOL, BasicElementLabels.getPathLabel(outputLocation, false)));
					} else {
						rootStatus.setInfo(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceOL, BasicElementLabels.getPathLabel(outputLocation, false)));
					}
					return;
				}
			}
			rootStatus.setError(status.getMessage());
			throw new CoreException(rootStatus);
		}

		if (isSourceFolder(project) || project.getPath().equals(path)) {
			rootStatus.setWarning(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSF);
			return;
		}

		rootStatus.setOK();
		return;
	}
}
 
Example 5
Source File: NewPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Validates the package name and returns the status of the validation.
 * 
 * @param packName the package name
 * 
 * @return the status of the validation
 */
private IStatus getPackageStatus(String packName) {
	StatusInfo status= new StatusInfo();
	if (packName.length() > 0) {
		IStatus val= validatePackageName(packName);
		if (val.getSeverity() == IStatus.ERROR) {
			status.setError(Messages.format(NewWizardMessages.NewPackageWizardPage_error_InvalidPackageName, val.getMessage()));
			return status;
		} else if (val.getSeverity() == IStatus.WARNING) {
			status.setWarning(Messages.format(NewWizardMessages.NewPackageWizardPage_warning_DiscouragedPackageName, val.getMessage()));
		}
	} else {
		status.setError(NewWizardMessages.NewPackageWizardPage_error_EnterName);
		return status;
	}

	IPackageFragmentRoot root= getPackageFragmentRoot();
	if (root != null && root.getJavaProject().exists()) {
		IPackageFragment pack= root.getPackageFragment(packName);
		try {
			IPath rootPath= root.getPath();
			IPath outputPath= root.getJavaProject().getOutputLocation();
			if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
				// if the bin folder is inside of our root, don't allow to name a package
				// like the bin folder
				IPath packagePath= pack.getPath();
				if (outputPath.isPrefixOf(packagePath)) {
					status.setError(NewWizardMessages.NewPackageWizardPage_error_IsOutputFolder);
					return status;
				}
			}
			if (pack.exists()) {
				// it's ok for the package to exist as long we want to create package level documentation
				// and the package level documentation doesn't exist
				if (!isCreatePackageDocumentation() || packageDocumentationAlreadyExists(pack)) {
					if (pack.containsJavaResources() || !pack.hasSubpackages()) {
						status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageExists);
					} else {
						status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageNotShown);
					}
				}
			} else {
				IResource resource= pack.getResource();
				if (resource != null && !ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
					status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageNameFiltered);
					return status;
				}
				URI location= pack.getResource().getLocationURI();
				if (location != null) {
					IFileStore store= EFS.getStore(location);
					if (store.fetchInfo().exists()) {
						status.setError(NewWizardMessages.NewPackageWizardPage_error_PackageExistsDifferentCase);
					}
				}
			}
		} catch (CoreException e) {
			JavaPlugin.log(e);
		}
	}
	return status;
}
 
Example 6
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * A hook method that gets called when the package field has changed. The method
 * validates the package name and returns the status of the validation. The validation
 * also updates the package fragment model.
 * <p>
 * Subclasses may extend this method to perform their own validation.
 * </p>
 *
 * @return the status of the validation
 */
protected IStatus packageChanged() {
	StatusInfo status= new StatusInfo();
	IPackageFragmentRoot root= getPackageFragmentRoot();
	fPackageDialogField.enableButton(root != null);

	IJavaProject project= root != null ? root.getJavaProject() : null;

	String packName= getPackageText();
	if (packName.length() > 0) {
		IStatus val= validatePackageName(packName, project);
		if (val.getSeverity() == IStatus.ERROR) {
			status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage()));
			return status;
		} else if (val.getSeverity() == IStatus.WARNING) {
			status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
			// continue
		}
	} else {
		status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
	}

	if (project != null) {
		if (project.exists() && packName.length() > 0) {
			try {
				IPath rootPath= root.getPath();
				IPath outputPath= project.getOutputLocation();
				if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
					// if the bin folder is inside of our root, don't allow to name a package
					// like the bin folder
					IPath packagePath= rootPath.append(packName.replace('.', '/'));
					if (outputPath.isPrefixOf(packagePath)) {
						status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
						return status;
					}
				}
			} catch (JavaModelException e) {
				JavaPlugin.log(e);
				// let pass
			}
		}

		fCurrPackage= root.getPackageFragment(packName);
		IResource resource= fCurrPackage.getResource();
		if (resource != null){
			if (resource.isVirtual()){
				status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageIsVirtual);
				return status;
			}
			if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageNameFiltered);
				return status;
			}
		}
	} else {
		status.setError(""); //$NON-NLS-1$
	}
	return status;
}
 
Example 7
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Hook method that gets called when the enclosing type name has changed. The method
 * validates the enclosing type and returns the status of the validation. It also updates the
 * enclosing type model.
 * <p>
 * Subclasses may extend this method to perform their own validation.
 * </p>
 *
 * @return the status of the validation
 */
protected IStatus enclosingTypeChanged() {
	StatusInfo status= new StatusInfo();
	fCurrEnclosingType= null;

	IPackageFragmentRoot root= getPackageFragmentRoot();

	fEnclosingTypeDialogField.enableButton(root != null);
	if (root == null) {
		status.setError(""); //$NON-NLS-1$
		return status;
	}

	String enclName= getEnclosingTypeText();
	if (enclName.length() == 0) {
		status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeEnterName);
		return status;
	}
	try {
		IType type= findType(root.getJavaProject(), enclName);
		if (type == null) {
			status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists);
			return status;
		}

		if (type.getCompilationUnit() == null) {
			status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotInCU);
			return status;
		}
		if (!JavaModelUtil.isEditable(type.getCompilationUnit())) {
			status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotEditable);
			return status;
		}

		fCurrEnclosingType= type;
		IPackageFragmentRoot enclosingRoot= JavaModelUtil.getPackageFragmentRoot(type);
		if (!enclosingRoot.equals(root)) {
			status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_EnclosingNotInSourceFolder);
		}
		return status;
	} catch (JavaModelException e) {
		status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists);
		JavaPlugin.log(e);
		return status;
	}
}
 
Example 8
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Hook method that gets called when the type name has changed. The method validates the
 * type name and returns the status of the validation.
 * <p>
 * Subclasses may extend this method to perform their own validation.
 * </p>
 *
 * @return the status of the validation
 */
protected IStatus typeNameChanged() {
	StatusInfo status= new StatusInfo();
	fCurrType= null;
	String typeNameWithParameters= getTypeName();
	// must not be empty
	if (typeNameWithParameters.length() == 0) {
		status.setError(NewWizardMessages.NewTypeWizardPage_error_EnterTypeName);
		return status;
	}

	String typeName= getTypeNameWithoutParameters();
	if (typeName.indexOf('.') != -1) {
		status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName);
		return status;
	}

	IJavaProject project= getJavaProject();
	IStatus val= validateJavaTypeName(typeName, project);
	if (val.getSeverity() == IStatus.ERROR) {
		status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage()));
		return status;
	} else if (val.getSeverity() == IStatus.WARNING) {
		status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage()));
		// continue checking
	}

	// must not exist
	if (!isEnclosingTypeSelected()) {
		IPackageFragment pack= getPackageFragment();
		if (pack != null) {
			ICompilationUnit cu= pack.getCompilationUnit(getCompilationUnitName(typeName));
			fCurrType= cu.getType(typeName);
			IResource resource= cu.getResource();

			if (resource.exists()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
				return status;
			}
			if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameFiltered);
				return status;
			}
			URI location= resource.getLocationURI();
			if (location != null) {
				try {
					IFileStore store= EFS.getStore(location);
					if (store.fetchInfo().exists()) {
						status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExistsDifferentCase);
						return status;
					}
				} catch (CoreException e) {
					status.setError(Messages.format(
						NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown,
						BasicElementLabels.getURLPart(Resources.getLocationString(resource))));
				}
			}
		}
	} else {
		IType type= getEnclosingType();
		if (type != null) {
			fCurrType= type.getType(typeName);
			if (fCurrType.exists()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
				return status;
			}
		}
	}

	if (!typeNameWithParameters.equals(typeName) && project != null) {
		if (!JavaModelUtil.is50OrHigher(project)) {
			status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeParameters);
			return status;
		}
		String typeDeclaration= "class " + typeNameWithParameters + " {}"; //$NON-NLS-1$//$NON-NLS-2$
		ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
		parser.setSource(typeDeclaration.toCharArray());
		parser.setProject(project);
		CompilationUnit compilationUnit= (CompilationUnit) parser.createAST(null);
		IProblem[] problems= compilationUnit.getProblems();
		if (problems.length > 0) {
			status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage()));
			return status;
		}
	}
	return status;
}