399104 : optional JavaEE configurators preferences

Signed-off-by: Fred Bricon <fbricon@gmail.com>
diff --git a/org.eclipse.m2e.wtp.jpa/plugin.properties b/org.eclipse.m2e.wtp.jpa/plugin.properties
index 6822a8c..402d40c 100644
--- a/org.eclipse.m2e.wtp.jpa/plugin.properties
+++ b/org.eclipse.m2e.wtp.jpa/plugin.properties
@@ -2,3 +2,5 @@
 Bundle-Name = Maven JPA Configurator
 jpa_project_configurator = JPA configurator for JDT projects
 jpa_project_configurator_wtp = JPA configurator for WTP projects
+jpa_enabler_label=JPA Configurator
+jpa_enabler_description=The JPA Configurator adds the JPA Facet if a persistence.xml is found.
diff --git a/org.eclipse.m2e.wtp.jpa/plugin.xml b/org.eclipse.m2e.wtp.jpa/plugin.xml
index 8c5469f..9ae0bdd 100644
--- a/org.eclipse.m2e.wtp.jpa/plugin.xml
+++ b/org.eclipse.m2e.wtp.jpa/plugin.xml
@@ -18,5 +18,14 @@
           name="%jpa_project_configurator_wtp" 
           secondaryTo="org.maven.ide.eclipse.configuration.wtp.configurator"/>
     </extension>   
+    <extension
+         point="org.eclipse.m2e.wtp.javaeeConfiguratorEnabler">
+         <javaeeConfiguratorEnabler
+           id="org.eclipse.m2e.wtp.jpa.enabler"
+           label="%jpa_enabler_label"
+           description="%jpa_enabler_description"
+           configuratorIds="org.eclipse.m2e.wtp.jpa.configurator.wtp,org.eclipse.m2e.wtp.jpa.configurator.jdt"
+         />
+    </extension>
 
 </plugin>
diff --git a/org.eclipse.m2e.wtp.jpa/src/org/eclipse/m2e/wtp/jpa/internal/configurators/JpaProjectConfigurator.java b/org.eclipse.m2e.wtp.jpa/src/org/eclipse/m2e/wtp/jpa/internal/configurators/JpaProjectConfigurator.java
index a2feb46..667ca3c 100644
--- a/org.eclipse.m2e.wtp.jpa/src/org/eclipse/m2e/wtp/jpa/internal/configurators/JpaProjectConfigurator.java
+++ b/org.eclipse.m2e.wtp.jpa/src/org/eclipse/m2e/wtp/jpa/internal/configurators/JpaProjectConfigurator.java
@@ -45,6 +45,7 @@
 import org.eclipse.m2e.core.project.configurator.ILifecycleMappingConfiguration;
 import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
 import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
+import org.eclipse.m2e.wtp.MavenWtpPlugin;
 import org.eclipse.m2e.wtp.ProjectUtils;
 import org.eclipse.m2e.wtp.jpa.PlatformIdentifierManager;
 import org.eclipse.m2e.wtp.jpa.internal.MavenJpaActivator;
@@ -165,7 +166,6 @@
 		dm.setProperty(JpaFacetDataModelProperties.PLATFORM, platformConfig); 
 		dm.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, false);
 		dm.setProperty(JpaFacetInstallDataModelProperties.DISCOVER_ANNOTATED_CLASSES, true);
-		
 		LibraryInstallDelegate libraryInstallDelegate = getNoOpLibraryProvider(facetedProject, version);
 		dm.setProperty(JpaFacetInstallDataModelProperties.LIBRARY_PROVIDER_DELEGATE, libraryInstallDelegate);
 		
@@ -173,14 +173,12 @@
 	}
 
 	private boolean canConfigure(IProject project) throws CoreException {
-		/* FIX_POST_MIGRATION (dis/en)able configurators in prefs
-		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
-		boolean configureJpa = store.getBoolean(Activator.CONFIGURE_JPA);
-		*/
+		boolean enabled = MavenWtpPlugin.getDefault().getMavenWtpPreferencesManager().isEnabled(getId());
+		if (!enabled || !project.hasNature(JavaCore.NATURE_ID)) {
+			return false;
+		}
 		IFacetedProject fProj = ProjectFacetsManager.create(project);
-		
-		return fProj != null && !fProj.hasProjectFacet(JpaProject.FACET) 
-				&& project.hasNature(JavaCore.NATURE_ID);
+		return  fProj == null || !fProj.hasProjectFacet(JpaProject.FACET);
 	}
 
 	private LibraryInstallDelegate getNoOpLibraryProvider(IFacetedProject facetedProject, IProjectFacetVersion facetVersion) {