summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2012-11-14 13:46:45 (EST)
committerKaren Butzke2012-11-14 13:46:45 (EST)
commit45afe1e41eb5f882c40138aba89bad5a79c859f3 (patch)
tree1aa36d031c324634b50b2dc2aa32872b0abe54ec
parent6f867b86662761700efdd121b7783eb2cc0eed9d (diff)
downloadwebtools.dali-45afe1e41eb5f882c40138aba89bad5a79c859f3.zip
webtools.dali-45afe1e41eb5f882c40138aba89bad5a79c859f3.tar.gz
webtools.dali-45afe1e41eb5f882c40138aba89bad5a79c859f3.tar.bz2
Bug 239011 - Fixed Convert to JPA project so that it does not remove the facted proejct nature if it already existed before runnin the commandv201211150033
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties1
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java1
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java65
3 files changed, 41 insertions, 26 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
index b368548..00f8ef9 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
@@ -34,6 +34,7 @@ AddPersistentClassDialog_noMappingKeyError=You must specify a mapping type
convertToJpa_convertingProject="Converting project to faceted form..."
convertToJpa_detectingTechnologies="Detecting existing technologies..."
+convertToJpa_installingJpaFacet="Installing JPA facet..."
DatabaseSchemaWizardPage_title=Database Schema
DatabaseSchemaWizardPage_desc=Select a database schema
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java
index 9d8d669..347dd87 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java
@@ -46,6 +46,7 @@ public class JptUiMessages {
public static String AddPersistentClassDialog_title;
public static String convertToJpa_convertingProject;
public static String convertToJpa_detectingTechnologies;
+ public static String convertToJpa_installingJpaFacet;
public static String DatabaseSchemaWizardPage_title;
public static String DatabaseSchemaWizardPage_desc;
public static String DatabaseSchemaWizardPage_schemaSettings;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java
index eb90d04..b7322c5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java
@@ -9,8 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.commands;
-import static org.eclipse.wst.common.project.facet.core.util.internal.FileUtil.FILE_DOT_PROJECT;
-import static org.eclipse.wst.common.project.facet.core.util.internal.FileUtil.validateEdit;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@@ -79,42 +77,60 @@ public class ConvertJavaProjectToJpaCommandHandler
private final IProject project;
private IFacetedProjectWorkingCopy fprojwc;
-
+
public static void runInProgressDialog(Shell shell, IProject project) {
+ final boolean startedWithFacetNature = hasFacetNature(project);
final ConvertJavaProjectToJpaRunnable runnable
= new ConvertJavaProjectToJpaRunnable(project);
-
+
try {
- new ProgressMonitorDialog(shell).run(true, true, runnable);
+ try {
+ new ProgressMonitorDialog(shell).run(true, true, runnable);
+ }
+ catch (InvocationTargetException ex) {
+ JptJpaUiPlugin.instance().logError(ex);
+ return;
+ }
ModifyFacetedProjectWizard wizard
= new ModifyFacetedProjectWizard(runnable.getFacetedProjectWorkingCopy());
WizardDialog dialog = new WizardDialog(shell, wizard);
if (dialog.open() == Window.CANCEL) {
+ //throw an InterruptedException since this is also what the above
+ //ProgressMonitorDialog will do if the user cancels that.
throw new InterruptedException();
}
}
- catch (InvocationTargetException ex) {
- JptJpaUiPlugin.instance().logError(ex);
- }
catch(InterruptedException ex) {
+ //No need to log since InterruptedException is thrown when the user cancels:
+ //1. the ProgressMonitorDialog for converting to a faceted project
+ //2. the ModifyFacetedProjectWizard
+ if (!startedWithFacetNature && hasFacetNature(project)) {
+ //only remove the facet nature if the project did not have it to begin with
+ //and it has already been added before cancellation
+ removeFacetNature(project);
+ }
Thread.currentThread().interrupt();
- JptJpaUiPlugin.instance().logError(ex);
- removeFacetNature(project);
}
}
-
-
- public static void removeFacetNature(IProject project) {
+
+ protected static boolean hasFacetNature(IProject project) {
+ try {
+ return project.getDescription().hasNature(FacetedProjectNature.NATURE_ID);
+ }
+ catch (CoreException ce) {
+ JptJpaUiPlugin.instance().logError(ce);
+ }
+ return false;
+ }
+
+ protected static void removeFacetNature(IProject project) {
try {
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = ArrayTools.remove(prevNatures, FacetedProjectNature.NATURE_ID);
- description.setNatureIds( newNatures );
-
- validateEdit( project.getFile( FILE_DOT_PROJECT ) );
-
+ description.setNatureIds(newNatures);
project.setDescription(description, null);
}
catch (CoreException ce) {
@@ -131,7 +147,6 @@ public class ConvertJavaProjectToJpaCommandHandler
throws InvocationTargetException, InterruptedException {
monitor.beginTask(JptUiMessages.convertToJpa_convertingProject, 1000);
-
try {
IProgressMonitor createProgressMonitor = new SubProgressMonitor(monitor, 100);
IFacetedProject fproj = ProjectFacetsManager.create(this.project, true, createProgressMonitor);
@@ -140,17 +155,15 @@ public class ConvertJavaProjectToJpaCommandHandler
throw new InterruptedException();
}
- monitor.setTaskName(JptUiMessages.convertToJpa_detectingTechnologies);
-
- IProgressMonitor detectProgressMonitor = new SubProgressMonitor(monitor, 800);
+ monitor.setTaskName(JptUiMessages.convertToJpa_detectingTechnologies);
+ IProgressMonitor detectProgressMonitor = new SubProgressMonitor(monitor, 400);
this.fprojwc = fproj.createWorkingCopy();
this.fprojwc.detect(detectProgressMonitor);
-
- if (! this.fprojwc.hasProjectFacet(JpaProject.FACET)) {
- this.fprojwc.addProjectFacet(JpaProject.FACET.getDefaultVersion());
- }
+
+ monitor.setTaskName(JptUiMessages.convertToJpa_installingJpaFacet);
+ this.fprojwc.addProjectFacet(JpaProject.FACET.getDefaultVersion());
}
- catch(CoreException e) {
+ catch (CoreException e) {
throw new InvocationTargetException(e);
}
finally {