*/
public void run(IAction action)
{
IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
Cursor waitCursor = new Cursor(window.getShell().getDisplay(),
SWT.CURSOR_WAIT);
try
{
window.getShell().setCursor(waitCursor);
((ApplicationWindow) window).setStatus(Messages.ADDING_NATURE);
//new way
if (currentJavaProject == null)
{
// if the java nature is not present
// it must be added, along with the Derby nature
IProjectDescription description = currentProject
.getDescription();
String[] natureIds = description.getNatureIds();
String[] newNatures = new String[natureIds.length + 2];
System.arraycopy(natureIds, 0, newNatures, 0, natureIds.length);
newNatures[newNatures.length - 2] = JavaCore.NATURE_ID;
newNatures[newNatures.length - 1] = CommonNames.DERBY_NATURE;
description.setNatureIds(newNatures);
currentProject.setDescription(description, null);
currentJavaProject = (IJavaProject) JavaCore
.create((IProject) currentProject);
}
else
{
//add the derby nature, the java nature is already present
IProjectDescription description = currentJavaProject
.getProject().getDescription();
String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
// must prefix with plugin id
newNatures[natures.length] = CommonNames.DERBY_NATURE;
description.setNatureIds(newNatures);
currentJavaProject.getProject().setDescription(description,
null);
}
IClasspathEntry[] rawClasspath = currentJavaProject
.getRawClasspath();
currentJavaProject.setRawClasspath(DerbyUtils
.addDerbyJars(rawClasspath), null);
// refresh project so user sees new files, libraries, etc
currentJavaProject.getProject().refreshLocal(
IResource.DEPTH_INFINITE, null);
((ApplicationWindow) window).setStatus(Messages.DERBY_NATURE_ADDED);
} catch ( Exception e)
{
Logger.log(Messages.ERROR_ADDING_NATURE + " '"
+ currentJavaProject.getProject().getName() + "' : " + e,
IStatus.ERROR);
Shell shell = new Shell();
MessageDialog.openInformation(shell, CommonNames.PLUGIN_NAME,
Messages.ERROR_ADDING_NATURE + ":\n"
+ SelectionUtil.getStatusMessages(e));
} finally
{
window.getShell().setCursor(null);
waitCursor.dispose();
}
}