* Update modification of package input field.
*
* @return Package validation status
*/
protected IStatus updatePackage() {
StatusInfo status = new StatusInfo();
fPackageDialogField.setStatus(getPackage().length() == 0 ? "(default)" : "");
fPackageDialogField.enableButton(getPackageFragmentRoot() != null);
String packName = getPackage();
if (packName.length() > 0) {
IStatus val = JavaConventions.validatePackageName(packName);
if (val.getSeverity() == IStatus.ERROR) {
status.setError("Package name is not valid." + val.getMessage());
return status;
} else if (val.getSeverity() == IStatus.WARNING) {
status.setWarning("This package name is discouraged. " + val.getMessage());
// continue
}
} else {
status.setWarning("The use of the default package is discouraged.");
}
IPackageFragmentRoot root = getPackageFragmentRoot();
if (root != null) {
if (root.getJavaProject().exists() && packName.length() > 0) {
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 = rootPath.append(packName.replace('.', '/'));
if (outputPath.isPrefixOf(packagePath)) {
status.setError("Package clashes with project output folder.");
return status;
}
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
// let pass
}
}
fPackageFragment = root.getPackageFragment(packName);
} else {
status.setError(""); //$NON-NLS-1$
}
return status;
}