Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortle2012-02-20 19:30:23 +0000
committertle2012-02-20 19:30:23 +0000
commit17f02c829619fcf7e95e96d9c51aac6936f2c423 (patch)
tree9ef10076e2d2ecac2d1b8fdacbe4d57ef7374dc7
parent3c6ec5a8fb6843b0620c946dfa22f569f027afa9 (diff)
downloadwebtools.dali-17f02c829619fcf7e95e96d9c51aac6936f2c423.tar.gz
webtools.dali-17f02c829619fcf7e95e96d9c51aac6936f2c423.tar.xz
webtools.dali-17f02c829619fcf7e95e96d9c51aac6936f2c423.zip
Refactored preferences support with JpaPreferencesManager
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JptJpaCorePlugin.java279
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetUninstallDelegate.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaPreferenceInitializer.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaPreferencesManager.java360
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaValidationPreferencesManager.java127
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/DefaultJpaValidationMessages.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationPreferences.java138
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java3
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpql/JpaJpqlQueryHelper.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/builder/StaticWeavingBuilderConfigurator.java97
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/weave/EclipselinkPreferencePage.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java102
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java2
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java3
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/ContextModelTestCase.java5
16 files changed, 615 insertions, 527 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JptJpaCorePlugin.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JptJpaCorePlugin.java
index 2c784e51c7..2d0c954774 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JptJpaCorePlugin.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JptJpaCorePlugin.java
@@ -10,13 +10,13 @@
package org.eclipse.jpt.jpa.core;
import java.util.Hashtable;
+
import javax.xml.parsers.SAXParserFactory;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
@@ -24,30 +24,22 @@ import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.preferences.DefaultScope;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.IScopeContext;
-import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
import org.eclipse.jpt.jpa.core.internal.InternalJpaProjectManager;
-import org.eclipse.jpt.jpa.core.internal.JptCoreMessages;
import org.eclipse.jpt.jpa.core.internal.platform.JpaPlatformManagerImpl;
-import org.eclipse.jpt.jpa.core.internal.prefs.JpaPreferenceInitializer;
+import org.eclipse.jpt.jpa.core.internal.prefs.JpaPreferencesManager;
import org.eclipse.jpt.jpa.core.platform.GenericPlatform;
import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
import org.eclipse.jpt.jpa.core.platform.JpaPlatformManager;
import org.eclipse.jst.j2ee.internal.J2EEConstants;
-import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.osgi.framework.BundleContext;
-import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
import org.osgi.util.tracker.ServiceTracker;
@@ -74,8 +66,6 @@ public class JptJpaCorePlugin
private volatile boolean active = false;
private final Hashtable<IWorkspace, InternalJpaProjectManager> jpaProjectManagers = new Hashtable<IWorkspace, InternalJpaProjectManager>();
private volatile ServiceTracker<?, SAXParserFactory> parserTracker;
- private static volatile boolean flushPreferences = true;
-
// ********** public constants **********
@@ -94,50 +84,6 @@ public class JptJpaCorePlugin
public static final String LEGACY_PLUGIN_ID_ = LEGACY_PLUGIN_ID + '.';
/**
- * The key for storing a JPA project's platform ID in the Eclipse
- * project's preferences.
- */
- private static final String JPA_PLATFORM_PREF_KEY = LEGACY_PLUGIN_ID_ + "platform"; //$NON-NLS-1$
-
- /**
- * The old key for storing the default JPA platform ID in the workspace preferences.
- * @deprecated As of version 2.3. Instead use {@link #DEFAULT_JPA_PLATFORM_1_0_PREF_KEY} or
- * {@link #DEFAULT_JPA_PLATFORM_2_0_PREF_KEY}
- */
- @Deprecated
- public static final String DEFAULT_JPA_PLATFORM_PREF_KEY = "defaultJpaPlatform"; //$NON-NLS-1$
-
- /**
- * The key for storing the default JPA platform ID for JPA 1.0 in the workspace preferences.
- */
- public static final String DEFAULT_JPA_PLATFORM_1_0_PREF_KEY =
- DEFAULT_JPA_PLATFORM_PREF_KEY + "_" + JpaFacet.VERSION_1_0.getVersionString(); //$NON-NLS-1$
-
- /**
- * The key for storing the default JPA platform ID for JPA 2.0 in the workspace preferences.
- */
- public static final String DEFAULT_JPA_PLATFORM_2_0_PREF_KEY =
- DEFAULT_JPA_PLATFORM_PREF_KEY + "_" + JpaFacet.VERSION_2_0.getVersionString(); //$NON-NLS-1$
-
- /**
- * The key for storing a JPA project's "discover" flag in the Eclipse
- * project's preferences.
- */
- public static final String DISCOVER_ANNOTATED_CLASSES = PLUGIN_ID_ + "discoverAnnotatedClasses"; //$NON-NLS-1$
-
- //bug 354780 - made the mistake of changing the project metadata in the 3.0 release
- private static final String LEGACY_DISCOVER_ANNOTATED_CLASSES = LEGACY_PLUGIN_ID_ + "discoverAnnotatedClasses"; //$NON-NLS-1$
-
- /**
- * The key for storing the name of a JPA project's metamodel source folder
- * in the Eclipse project's preferences.
- */
- public static final String METAMODEL_SOURCE_FOLDER_NAME = PLUGIN_ID_ + "metamodelSourceFolderName"; //$NON-NLS-1$
-
- //bug 354780 - made the mistake of changing the project metadata in the 3.0 release
- private static final String LEGACY_METAMODEL_SOURCE_FOLDER_NAME = LEGACY_PLUGIN_ID_ + "metamodelSourceFolderName"; //$NON-NLS-1$
-
- /**
* The key for storing a JPA project's data source connection profile name
* in the Eclipse project's persistent properties.
*/
@@ -232,12 +178,10 @@ public class JptJpaCorePlugin
return Platform.getContentTypeManager().getContentType(contentType);
}
-
// ********** singleton **********
static JptJpaCorePlugin INSTANCE;
-
// ********** public static methods **********
/**
@@ -289,138 +233,41 @@ public class JptJpaCorePlugin
: new Path("/"); //$NON-NLS-1$
}
- public static void initializeDefaultPreferences() {
- IEclipsePreferences node = getDefaultPreferences();
-
- // default JPA platforms
- JpaPlatformDescription defaultPlatform_1_0 =
- JpaPlatformManagerImpl.instance().getDefaultJpaPlatform(JpaFacet.VERSION_1_0);
- if (defaultPlatform_1_0 == null) {
- defaultPlatform_1_0 = GenericPlatform.VERSION_1_0;
- }
- node.put(DEFAULT_JPA_PLATFORM_1_0_PREF_KEY, defaultPlatform_1_0.getId());
-
- JpaPlatformDescription defaultPlatform_2_0 =
- JpaPlatformManagerImpl.instance().getDefaultJpaPlatform(JpaFacet.VERSION_2_0);
- if (defaultPlatform_2_0 == null) {
- defaultPlatform_2_0 = GenericPlatform.VERSION_2_0;
- }
- node.put(DEFAULT_JPA_PLATFORM_2_0_PREF_KEY, defaultPlatform_2_0.getId());
- }
-
- /**
- * Return the default Dali preferences
- * @see JpaPreferenceInitializer
- */
- public static IEclipsePreferences getDefaultPreferences() {
- return getPreferences(DefaultScope.INSTANCE);
- }
-
- /**
- * Return the Dali preferences for the current workspace instance.
- */
- public static IEclipsePreferences getWorkspacePreferences() {
- return getPreferences(InstanceScope.INSTANCE);
- }
-
- /**
- * Set the workspace preference.
- */
- public static void setWorkspacePreference(String preferenceKey, String preferenceValue) {
- IEclipsePreferences prefs = getWorkspacePreferences();
- prefs.put(preferenceKey, preferenceValue);
- flush(prefs);
- }
-
- /**
- * Return the Dali preferences for the specified Eclipse project.
- */
- public static IEclipsePreferences getProjectPreferences(IProject project) {
- return getPreferences(new ProjectScope(project));
- }
-
- /**
- * Set the project preference
- */
- public static void setProjectPreference(IProject project, String preferenceKey, String preferenceValue) {
- IEclipsePreferences prefs = getProjectPreferences(project);
- if (preferenceValue == null) {
- prefs.remove(preferenceKey);
- }
- else {
- prefs.put(preferenceKey, preferenceValue);
- }
- flush(prefs);
- }
-
- /**
- * Set the project preference
- */
- public static void setProjectPreference(IProject project, String preferenceKey, boolean preferenceValue) {
- IEclipsePreferences prefs = getProjectPreferences(project);
- prefs.putBoolean(preferenceKey, preferenceValue);
- flush(prefs);
- }
-
- /**
- * Clears the project of JPA-specific preferences
- */
- public static void clearProjectPreferences(IProject project) {
- clearProjectPreferences(
- project,
- JPA_PLATFORM_PREF_KEY,
- DISCOVER_ANNOTATED_CLASSES,
- METAMODEL_SOURCE_FOLDER_NAME,
- LEGACY_DISCOVER_ANNOTATED_CLASSES,
- LEGACY_METAMODEL_SOURCE_FOLDER_NAME);
- }
-
- /**
- * Clears the specified preferences
- */
- public static void clearProjectPreferences(IProject project, String ... preferenceKeys) {
- IEclipsePreferences prefs = getProjectPreferences(project);
- for (String preferenceKey : preferenceKeys) {
- prefs.remove(preferenceKey);
- }
- flush(prefs);
- }
-
- /**
- * Return the Dali preferences for the specified context.
- */
- private static IEclipsePreferences getPreferences(IScopeContext context) {
- return context.getNode(LEGACY_PLUGIN_ID);
- }
-
/**
* Return the default {@link JpaPlatformDescription} for new JPA projects with the given JPA facet version.
*/
public static JpaPlatformDescription getDefaultJpaPlatform(IProjectFacetVersion jpaFacetVersion) {
- JpaPlatformDescription defaultPlatform =
- getDefaultJpaPlatform(jpaFacetVersion, getWorkspacePreferences(), getDefaultPreferences());
+ JpaPlatformDescription defaultPlatform = getDefaultJpaPlatform(
+ jpaFacetVersion,
+ JpaPreferencesManager.getWorkspacePreferences(),
+ JpaPreferencesManager.getDefaultPreferences());
if (defaultPlatform == null) {
// if the platform ID stored in the workspace prefs is invalid (i.e. null), look in the default prefs
- defaultPlatform = getDefaultJpaPlatform(jpaFacetVersion, getDefaultPreferences());
+ defaultPlatform = getDefaultJpaPlatform(
+ jpaFacetVersion,
+ JpaPreferencesManager.getDefaultPreferences());
}
return defaultPlatform;
}
private static JpaPlatformDescription getDefaultJpaPlatform(IProjectFacetVersion jpaFacetVersion, Preferences ... nodes) {
- JpaPlatformDescription defaultDefaultPlatform =
- getDefaultJpaPlatform(jpaFacetVersion, DEFAULT_JPA_PLATFORM_PREF_KEY, null, nodes);
+ JpaPlatformDescription defaultDefaultPlatform = getDefaultJpaPlatform(
+ jpaFacetVersion,
+ JpaPreferencesManager.DEFAULT_JPA_PLATFORM_PREF_KEY,
+ null,
+ nodes);
String preferenceKey = null;
if (jpaFacetVersion.equals(JpaFacet.VERSION_1_0)) {
if (defaultDefaultPlatform == null) {
defaultDefaultPlatform = GenericPlatform.VERSION_1_0;
}
- preferenceKey = DEFAULT_JPA_PLATFORM_1_0_PREF_KEY;
+ preferenceKey = JpaPreferencesManager.DEFAULT_JPA_PLATFORM_1_0_PREF_KEY;
}
else if (jpaFacetVersion.equals(JpaFacet.VERSION_2_0)) {
if (defaultDefaultPlatform == null) {
defaultDefaultPlatform = GenericPlatform.VERSION_2_0;
}
- preferenceKey = DEFAULT_JPA_PLATFORM_2_0_PREF_KEY;
+ preferenceKey = JpaPreferencesManager.DEFAULT_JPA_PLATFORM_2_0_PREF_KEY;
}
else {
throw new IllegalArgumentException("Illegal JPA facet version: " + jpaFacetVersion); //$NON-NLS-1$
@@ -453,22 +300,22 @@ public class JptJpaCorePlugin
public static void setDefaultJpaPlatformId(String jpaFacetVersion, String platformId) {
String preferenceKey = null;
if (JpaFacet.VERSION_1_0.getVersionString().equals(jpaFacetVersion)) {
- preferenceKey = DEFAULT_JPA_PLATFORM_1_0_PREF_KEY;
+ preferenceKey = JpaPreferencesManager.DEFAULT_JPA_PLATFORM_1_0_PREF_KEY;
}
else if (JpaFacet.VERSION_2_0.getVersionString().equals(jpaFacetVersion)) {
- preferenceKey = DEFAULT_JPA_PLATFORM_2_0_PREF_KEY;
+ preferenceKey = JpaPreferencesManager.DEFAULT_JPA_PLATFORM_2_0_PREF_KEY;
}
else {
throw new IllegalArgumentException("Illegal JPA facet version: " + jpaFacetVersion); //$NON-NLS-1$
}
- setWorkspacePreference(preferenceKey, platformId);
+ JpaPreferencesManager.setWorkspacePreference(preferenceKey, platformId);
}
/**
* Return the JPA platform ID associated with the specified Eclipse project.
*/
public static String getJpaPlatformId(IProject project) {
- return getProjectPreferences(project).get(JPA_PLATFORM_PREF_KEY, GenericPlatform.VERSION_1_0.getId());
+ return (new JpaPreferencesManager(project)).getJpaPlatformId();
}
/**
@@ -483,27 +330,15 @@ public class JptJpaCorePlugin
* Set the JPA platform ID associated with the specified Eclipse project.
*/
public static void setJpaPlatformId(IProject project, String jpaPlatformId) {
- setProjectPreference(project, JPA_PLATFORM_PREF_KEY, jpaPlatformId);
- }
-
- /**
- * Return the preferences key used to look up an Eclipse project's
- * JPA platform ID.
- */
- public static String getJpaPlatformIdPrefKey() {
- return JPA_PLATFORM_PREF_KEY;
+ (new JpaPreferencesManager(project)).setJpaPlatformId(jpaPlatformId);
}
/**
* Return the JPA "discover" flag associated with the specified
* Eclipse project.
*/
- public static boolean discoverAnnotatedClasses(IProject project) {
- if (getProjectPreferences(project).get(DISCOVER_ANNOTATED_CLASSES, null) != null) {
- return getProjectPreferences(project).getBoolean(DISCOVER_ANNOTATED_CLASSES, false);
- }
- //bug 354780 - made the mistake of changing the project metadata in the 3.0 release
- return getProjectPreferences(project).getBoolean(LEGACY_DISCOVER_ANNOTATED_CLASSES, false);
+ public static boolean getDiscoverAnnotatedClasses(IProject project) {
+ return (new JpaPreferencesManager(project)).getDiscoverAnnotatedClasses();
}
/**
@@ -511,7 +346,7 @@ public class JptJpaCorePlugin
* Eclipse project.
*/
public static void setDiscoverAnnotatedClasses(IProject project, boolean discoverAnnotatedClasses) {
- setProjectPreference(project, DISCOVER_ANNOTATED_CLASSES, discoverAnnotatedClasses);
+ (new JpaPreferencesManager(project)).setDiscoverAnnotatedClasses(discoverAnnotatedClasses);
}
/**
@@ -519,12 +354,7 @@ public class JptJpaCorePlugin
* specified Eclipse project.
*/
public static String getMetamodelSourceFolderName(IProject project) {
- String metamodelSourceFolderName = getProjectPreferences(project).get(METAMODEL_SOURCE_FOLDER_NAME, null);
- if (metamodelSourceFolderName != null) {
- return metamodelSourceFolderName;
- }
- //bug 354780 - made the mistake of changing the project metadata in the 3.0 release
- return getProjectPreferences(project).get(LEGACY_METAMODEL_SOURCE_FOLDER_NAME, null);
+ return (new JpaPreferencesManager(project)).getMetamodelSourceFolderName();
}
/**
@@ -532,59 +362,9 @@ public class JptJpaCorePlugin
* specified Eclipse project.
*/
public static void setMetamodelSourceFolderName(IProject project, String metamodelSourceFolderName) {
- setProjectPreference(project, METAMODEL_SOURCE_FOLDER_NAME, metamodelSourceFolderName);
- //bug 354780 - made the mistake of changing the project metadata in the 3.0 release.
- //make sure legacy setting is removed when turning off metamodel gen, if we don't then
- //there will be no way to turn off meatamodel gen without sacrificing backwards compatibility
- if(metamodelSourceFolderName == null) {
- setProjectPreference(project, LEGACY_METAMODEL_SOURCE_FOLDER_NAME, null);
- }
-
- }
-
- /**
- * This method is called (via reflection) when the test plug-in is loaded.
- * The preferences end up getting flushed after the test case has deleted
- * its project, resulting in resource exceptions in the log, e.g.
- * <pre>
- * Resource '/JpaProjectManagerTests' is not open.
- * </pre>
- * See <code>JptJpaCoreTestsPlugin.start(BundleContext)</code>
- */
- @SuppressWarnings("unused")
- private static void doNotFlushPreferences() {
- flushPreferences = false;
- }
-
- /**
- * Flush preferences in an asynchronous Job because the flush request will
- * trigger a lock on the project, which can cause us some deadlocks (e.g.
- * when deleting the metamodel source folder).
- * Note: the flush will also remove the prefs node if it is empty
- */
- private static void flush(IEclipsePreferences prefs) {
- if (flushPreferences) {
- new PreferencesFlushJob(prefs).schedule();
- }
- }
-
- private static class PreferencesFlushJob extends Job {
- private final IEclipsePreferences prefs;
- PreferencesFlushJob(IEclipsePreferences prefs) {
- super(NLS.bind(JptCoreMessages.PREFERENCES_FLUSH_JOB_NAME, prefs.absolutePath()));
- this.prefs = prefs;
- }
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- this.prefs.flush();
- } catch(BackingStoreException ex) {
- log(ex);
- }
- return Status.OK_STATUS;
- }
+ (new JpaPreferencesManager(project)).setMetamodelSourceFolderName(metamodelSourceFolderName);
}
-
+
/**
* Return the name of the connection profile associated with the specified
* Eclipse project.
@@ -717,8 +497,7 @@ public class JptJpaCorePlugin
INSTANCE.getLog().log(status);
}
-
- // ********** plug-in implementation **********
+ // ********** plug-in implementation **************************************************
public JptJpaCorePlugin() {
super();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java
index 9369ca97a9..5d4ab4175f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java
@@ -630,7 +630,7 @@ public class InternalJpaProjectManager
config.setConnectionProfileName(JptJpaCorePlugin.getConnectionProfileName(project));
config.setUserOverrideDefaultCatalog(JptJpaCorePlugin.getUserOverrideDefaultCatalog(project));
config.setUserOverrideDefaultSchema(JptJpaCorePlugin.getUserOverrideDefaultSchema(project));
- config.setDiscoverAnnotatedClasses(JptJpaCorePlugin.discoverAnnotatedClasses(project));
+ config.setDiscoverAnnotatedClasses(JptJpaCorePlugin.getDiscoverAnnotatedClasses(project));
config.setMetamodelSourceFolderName(JptJpaCorePlugin.getMetamodelSourceFolderName(project));
return config;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetUninstallDelegate.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetUninstallDelegate.java
index b71b2ce923..1559337946 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetUninstallDelegate.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetUninstallDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.internal.prefs.JpaValidationPreferencesManager;
import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
@@ -22,7 +23,7 @@ public class JpaFacetUninstallDelegate
public void execute(IProject project, IProjectFacetVersion fv,
Object config, IProgressMonitor monitor) throws CoreException {
- JptJpaCorePlugin.clearProjectPreferences(project);
+ (new JpaValidationPreferencesManager(project)).clearProjectPreferences();
JptJpaCorePlugin.clearProjectPersistentProperties(project);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaPreferenceInitializer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaPreferenceInitializer.java
index d6fd0418ca..c8136cf4b4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaPreferenceInitializer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaPreferenceInitializer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,6 @@
package org.eclipse.jpt.jpa.core.internal.prefs;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
/**
* Class used to initialize default preference values.
@@ -21,6 +20,6 @@ public class JpaPreferenceInitializer
{
@Override
public void initializeDefaultPreferences() {
- JptJpaCorePlugin.initializeDefaultPreferences();
+ JpaPreferencesManager.initializeDefaultPreferences();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaPreferencesManager.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaPreferencesManager.java
new file mode 100644
index 0000000000..ad2e9e34ce
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaPreferencesManager.java
@@ -0,0 +1,360 @@
+/*******************************************************************************
+* Copyright (c) 2012 Oracle. All rights reserved.
+* This program and the accompanying materials are made available under the
+* terms of the Eclipse Public License v1.0, which accompanies this distribution
+* and is available at http://www.eclipse.org/legal/epl-v10.html.
+*
+* Contributors:
+* Oracle - initial API and implementation
+*******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal.prefs;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jpt.jpa.core.JpaFacet;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.internal.JptCoreMessages;
+import org.eclipse.jpt.jpa.core.internal.platform.JpaPlatformManagerImpl;
+import org.eclipse.jpt.jpa.core.platform.GenericPlatform;
+import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
+import org.eclipse.osgi.util.NLS;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * JptPreferencesManager
+ */
+public class JpaPreferencesManager
+{
+ private final IProject project;
+
+ private static volatile boolean flushPreferences = true;
+
+ // ********** public constants **********
+
+ /**
+ * The key for storing a JPA project's platform ID in the Eclipse
+ * project's preferences.
+ */
+ protected static final String JPA_PLATFORM_PREF_KEY = JptJpaCorePlugin.LEGACY_PLUGIN_ID_ + "platform"; //$NON-NLS-1$
+
+ /**
+ * The old key for storing the default JPA platform ID in the workspace preferences.
+ * @deprecated As of version 2.3. Instead use {@link #DEFAULT_JPA_PLATFORM_1_0_PREF_KEY} or
+ * {@link #DEFAULT_JPA_PLATFORM_2_0_PREF_KEY}
+ */
+ @Deprecated
+ public static final String DEFAULT_JPA_PLATFORM_PREF_KEY = "defaultJpaPlatform"; //$NON-NLS-1$
+
+ /**
+ * The key for storing the default JPA platform ID for JPA 1.0 in the workspace preferences.
+ */
+ public static final String DEFAULT_JPA_PLATFORM_1_0_PREF_KEY =
+ DEFAULT_JPA_PLATFORM_PREF_KEY + "_" + JpaFacet.VERSION_1_0.getVersionString(); //$NON-NLS-1$
+
+ /**
+ * The key for storing the default JPA platform ID for JPA 2.0 in the workspace preferences.
+ */
+ public static final String DEFAULT_JPA_PLATFORM_2_0_PREF_KEY =
+ DEFAULT_JPA_PLATFORM_PREF_KEY + "_" + JpaFacet.VERSION_2_0.getVersionString(); //$NON-NLS-1$
+
+ /**
+ * The key for storing a JPA project's "discover" flag in the Eclipse
+ * project's preferences.
+ */
+ public static final String DISCOVER_ANNOTATED_CLASSES = JptJpaCorePlugin.PLUGIN_ID_ + "discoverAnnotatedClasses"; //$NON-NLS-1$
+
+ //bug 354780 - made the mistake of changing the project metadata in the 3.0 release
+ protected static final String LEGACY_DISCOVER_ANNOTATED_CLASSES = JptJpaCorePlugin.LEGACY_PLUGIN_ID_ + "discoverAnnotatedClasses"; //$NON-NLS-1$
+
+ /**
+ * The key for storing the name of a JPA project's metamodel source folder
+ * in the Eclipse project's preferences.
+ */
+ public static final String METAMODEL_SOURCE_FOLDER_NAME = JptJpaCorePlugin.PLUGIN_ID_ + "metamodelSourceFolderName"; //$NON-NLS-1$
+
+ //bug 354780 - made the mistake of changing the project metadata in the 3.0 release
+ protected static final String LEGACY_METAMODEL_SOURCE_FOLDER_NAME = JptJpaCorePlugin.LEGACY_PLUGIN_ID_ + "metamodelSourceFolderName"; //$NON-NLS-1$
+
+
+ // ********** static methods **************************************************
+
+ public static void clearWorkspacePreferences() throws BackingStoreException {
+ getWorkspacePreferences().clear();
+ }
+
+ // ********** preferences **********
+
+ /**
+ * Return the Dali preferences for the specified context.
+ */
+ private static IEclipsePreferences getPreferences(IScopeContext context) {
+ return context.getNode(JptJpaCorePlugin.LEGACY_PLUGIN_ID);
+ }
+
+ /**
+ * Return the Dali preferences for the current workspace instance.
+ */
+ public static IEclipsePreferences getWorkspacePreferences() {
+ return getPreferences(InstanceScope.INSTANCE);
+ }
+
+ /**
+ * Return the default Dali preferences
+ * @see JpaPreferenceInitializer
+ */
+ public static IEclipsePreferences getDefaultPreferences() {
+ return getPreferences(DefaultScope.INSTANCE);
+ }
+
+ public static void initializeDefaultPreferences() {
+ IEclipsePreferences node = getDefaultPreferences();
+
+ // default JPA platforms
+ JpaPlatformDescription defaultPlatform_1_0 =
+ JpaPlatformManagerImpl.instance().getDefaultJpaPlatform(JpaFacet.VERSION_1_0);
+ if (defaultPlatform_1_0 == null) {
+ defaultPlatform_1_0 = GenericPlatform.VERSION_1_0;
+ }
+ node.put(DEFAULT_JPA_PLATFORM_1_0_PREF_KEY, defaultPlatform_1_0.getId());
+
+ JpaPlatformDescription defaultPlatform_2_0 =
+ JpaPlatformManagerImpl.instance().getDefaultJpaPlatform(JpaFacet.VERSION_2_0);
+ if (defaultPlatform_2_0 == null) {
+ defaultPlatform_2_0 = GenericPlatform.VERSION_2_0;
+ }
+ node.put(DEFAULT_JPA_PLATFORM_2_0_PREF_KEY, defaultPlatform_2_0.getId());
+ }
+
+ // ********** workspace preference **********
+
+ public static String getWorkspacePreference(String key, String defaultValue) {
+ return getWorkspacePreferences().get(key, defaultValue);
+ }
+
+ public static String getWorkspacePreference(String key) {
+ return getWorkspacePreferences().get(key, null);
+ }
+
+ public static void setWorkspacePreference(String key, String value) {
+ IEclipsePreferences wkspPrefs = getWorkspacePreferences();
+ if(value == null) {
+ wkspPrefs.remove(key);
+ }
+ else {
+ wkspPrefs.put(key, value);
+ }
+ flush(wkspPrefs);
+ }
+
+ // ********** private static methods **********
+
+ /**
+ * This method is called (via reflection) when the test plug-in is loaded.
+ * The preferences end up getting flushed after the test case has deleted
+ * its project, resulting in resource exceptions in the log, e.g.
+ * <pre>
+ * Resource '/JpaProjectManagerTests' is not open.
+ * </pre>
+ * See <code>JptJpaCoreTestsPlugin.start(BundleContext)</code>
+ */
+ @SuppressWarnings("unused")
+ private static void doNotFlushPreferences() {
+ flushPreferences = false;
+ }
+
+ /**
+ * Flush preferences in an asynchronous Job because the flush request will
+ * trigger a lock on the project, which can cause us some deadlocks (e.g.
+ * when deleting the metamodel source folder).
+ * Note: the flush will also remove the prefs node if it is empty
+ */
+ private static void flush(IEclipsePreferences prefs) {
+ if (flushPreferences) {
+ new PreferencesFlushJob(prefs).schedule();
+ }
+ }
+
+ private static class PreferencesFlushJob extends Job {
+ private final IEclipsePreferences prefs;
+ PreferencesFlushJob(IEclipsePreferences prefs) {
+ super(NLS.bind(JptCoreMessages.PREFERENCES_FLUSH_JOB_NAME, prefs.absolutePath()));
+ this.prefs = prefs;
+ }
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ this.prefs.flush();
+ }
+ catch(BackingStoreException ex) {
+ JptJpaCorePlugin.log(ex);
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ // ********** implementation **************************************************
+
+ public JpaPreferencesManager(IProject project) {
+ if(project == null) {
+ throw new RuntimeException("Project is null"); //$NON-NLS-1$
+ }
+ this.project = project;
+ }
+
+ // ********** query **********
+
+ public String getPreference(String key) {
+ String preference = this.getProjectPreference(key);
+
+ // check workspace preferences if not a project preference
+ if(preference == null) {
+ preference = getWorkspacePreference(key);
+ }
+ return preference;
+ }
+
+ // ********** preferences **********
+
+ /**
+ * Return the Dali preferences for the specified Eclipse project.
+ */
+ protected IEclipsePreferences getProjectPreferences() {
+ return getPreferences(new ProjectScope(this.project));
+ }
+
+ /**
+ * Clears the project of JPA-specific preferences
+ */
+ public void clearProjectPreferences() {
+ this.clearProjectPreferences(
+ JPA_PLATFORM_PREF_KEY,
+ DISCOVER_ANNOTATED_CLASSES,
+ METAMODEL_SOURCE_FOLDER_NAME,
+ LEGACY_DISCOVER_ANNOTATED_CLASSES,
+ LEGACY_METAMODEL_SOURCE_FOLDER_NAME);
+ }
+
+ /**
+ * Clears the specified preferences
+ */
+ public void clearProjectPreferences(String ... preferenceKeys) {
+ IEclipsePreferences projectPrefs = this.getProjectPreferences();
+ for(String preferenceKey : preferenceKeys) {
+ projectPrefs.remove(preferenceKey);
+ }
+ flush(projectPrefs);
+ }
+
+ // ********** project preference **********
+
+ public String getProjectPreference(String key, String defaultValue) {
+ return this.getProjectPreferences().get(key, defaultValue);
+ }
+
+ public String getProjectPreference(String key) {
+ return this.getProjectPreferences().get(key, null);
+ }
+
+ public void setProjectPreference(String key, String value) {
+ IEclipsePreferences projectPrefs = this.getProjectPreferences();
+ if(value == null) {
+ projectPrefs.remove(key);
+ }
+ else {
+ projectPrefs.put(key, value);
+ }
+ flush(projectPrefs);
+ }
+
+ public boolean getProjectPreference(String key, boolean defaultBooleanValue) {
+ return this.getProjectPreferences().getBoolean(key, defaultBooleanValue);
+ }
+
+ public void setProjectPreference(String key, boolean booleanValue) {
+ IEclipsePreferences projectPrefs = this.getProjectPreferences();
+ if( ! booleanValue) {
+ projectPrefs.remove(key);
+ }
+ else {
+ projectPrefs.putBoolean(key, booleanValue);
+ }
+ flush(projectPrefs);
+ }
+
+ // ********** getters/setters *********
+
+ /**
+ * Return the JPA platform ID associated with the specified Eclipse project.
+ */
+ public String getJpaPlatformId() {
+ return this.getProjectPreference(JPA_PLATFORM_PREF_KEY, GenericPlatform.VERSION_1_0.getId());
+ }
+
+ /**
+ * Set the JPA platform ID associated with the specified Eclipse project.
+ */
+ public void setJpaPlatformId(String jpaPlatformId) {
+ this.setProjectPreference(JPA_PLATFORM_PREF_KEY, jpaPlatformId);
+ }
+
+ /**
+ * Return the JPA "discover" flag associated with the specified
+ * Eclipse project.
+ */
+ public boolean getDiscoverAnnotatedClasses() {
+ if (this.getProjectPreference(DISCOVER_ANNOTATED_CLASSES, null) != null) {
+ return this.getProjectPreference(DISCOVER_ANNOTATED_CLASSES, false);
+ }
+ //bug 354780 - made the mistake of changing the project metadata in the 3.0 release
+ return this.getProjectPreference(LEGACY_DISCOVER_ANNOTATED_CLASSES, false);
+ }
+
+ /**
+ * Set the JPA "discover" flag associated with the specified
+ * Eclipse project.
+ */
+ public void setDiscoverAnnotatedClasses(boolean discoverAnnotatedClasses) {
+ this.setProjectPreference(DISCOVER_ANNOTATED_CLASSES, discoverAnnotatedClasses);
+ }
+
+ /**
+ * Return the name of the metamodel source folder associated with the
+ * specified Eclipse project.
+ */
+ public String getMetamodelSourceFolderName() {
+ String metamodelSourceFolderName = this.getProjectPreference(METAMODEL_SOURCE_FOLDER_NAME, null);
+ if (metamodelSourceFolderName != null) {
+ return metamodelSourceFolderName;
+ }
+ //bug 354780 - made the mistake of changing the project metadata in the 3.0 release
+ return this.getProjectPreference(LEGACY_METAMODEL_SOURCE_FOLDER_NAME, null);
+ }
+
+ /**
+ * Set the name of the metamodel source folder associated with the
+ * specified Eclipse project.
+ */
+ public void setMetamodelSourceFolderName(String metamodelSourceFolderName) {
+ this.setProjectPreference(METAMODEL_SOURCE_FOLDER_NAME, metamodelSourceFolderName);
+ //bug 354780 - made the mistake of changing the project metadata in the 3.0 release.
+ //make sure legacy setting is removed when turning off metamodel gen, if we don't then
+ //there will be no way to turn off meatamodel gen without sacrificing backwards compatibility
+ if(metamodelSourceFolderName == null) {
+ this.setProjectPreference(LEGACY_METAMODEL_SOURCE_FOLDER_NAME, null);
+ }
+ }
+
+ // ********** protected methods **********
+
+ protected IProject getProject() {
+ return this.project;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaValidationPreferencesManager.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaValidationPreferencesManager.java
new file mode 100644
index 0000000000..a721373cb5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/prefs/JpaValidationPreferencesManager.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+* Copyright (c) 2012 Oracle. All rights reserved.
+* This program and the accompanying materials are made available under the
+* terms of the Eclipse Public License v1.0, which accompanies this distribution
+* and is available at http://www.eclipse.org/legal/epl-v10.html.
+*
+* Contributors:
+* Oracle - initial API and implementation
+*******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal.prefs;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jpt.common.utility.internal.Tools;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+
+/**
+ * JpaValidationPreferencesManager
+ */
+public class JpaValidationPreferencesManager extends JpaPreferencesManager
+{
+ /*
+ * prefix for all preference strings. This is only used internally.
+ * Clients of get*LevelProblemPrefernce() and set*LevelProblemPreference
+ * should not include the prefix.
+ */
+ private static final String PROBLEM_PREFIX = "problem."; //$NON-NLS-1$
+
+ public static final String ERROR = "error"; //$NON-NLS-1$
+ public static final String WARNING = "warning"; //$NON-NLS-1$
+ public static final String INFO = "info"; //$NON-NLS-1$
+ public static final String IGNORE = "ignore"; //$NON-NLS-1$
+
+ public static final int NO_SEVERITY_PREFERENCE = -1;
+
+ public static final String WORKSPACE_PREFERENCES_OVERRIDEN = "workspace_preferences_overriden"; //$NON-NLS-1$
+
+ // ********** public static methods **********
+
+ /**
+ * Returns only the severity level of a given problem preference. This does not
+ * include information on whether the problem is ignored. See isProblemIgnored.
+ * @return an IMessage severity level
+ */
+ public static int getProblemSeverityPreference(IResource targetObject, String messageId) {
+ String problemPreference = (new JpaValidationPreferencesManager(targetObject.getProject())).
+ getPreference(appendProblemPrefix(messageId));
+
+ if(problemPreference == null) {
+ return NO_SEVERITY_PREFERENCE;
+ }
+ else if (problemPreference.equals(ERROR)) {
+ return IMessage.HIGH_SEVERITY;
+ }
+ else if (problemPreference.equals(WARNING)) {
+ return IMessage.NORMAL_SEVERITY;
+ }
+ else if (problemPreference.equals(INFO)) {
+ return IMessage.LOW_SEVERITY;
+ }
+ return NO_SEVERITY_PREFERENCE;
+ }
+
+ // ********** workspace preference **********
+
+ /**
+ * Returns the String value of the problem preference from the workspace preferences
+ */
+ public static String getWorkspaceLevelProblemPreference(String messageId) {
+ return getWorkspacePreference(appendProblemPrefix(messageId));
+ }
+
+ public static void setWorkspaceLevelProblemPreference(String messageId, String problemPreference) {
+ setWorkspacePreference(appendProblemPrefix(messageId), problemPreference);
+ }
+
+ protected static String appendProblemPrefix(String messageId) {
+ return PROBLEM_PREFIX + messageId;
+ }
+
+ // ********** implementation **************************************************
+
+ public JpaValidationPreferencesManager(IProject project) {
+
+ super(project);
+ }
+
+ // ********** behavior **********
+
+ /**
+ * Return whether the specified problem should <em>not</em> be ignored based
+ * on project or workspace preferences.
+ */
+ public boolean problemIsNotIgnored(String messageId) {
+ return ! problemIsIgnored(messageId);
+ }
+
+ /**
+ * Return whether the specified problem should be ignored based on project or
+ * workspace preferences.
+ */
+ public boolean problemIsIgnored(String messageId) {
+ return Tools.valuesAreEqual(this.getPreference(appendProblemPrefix(messageId)), IGNORE);
+ }
+
+ public boolean projectHasSpecificOptions() {
+ return this.getProjectPreference(WORKSPACE_PREFERENCES_OVERRIDEN, false);
+ }
+
+ public void setProjectHasSpecificOptions(boolean booleanValue) {
+ this.setProjectPreference(WORKSPACE_PREFERENCES_OVERRIDEN, booleanValue);
+ }
+
+ // ********** project preference **********
+
+ /**
+ * Returns the String value of the problem preference from the project preferences
+ */
+ public String getProjectLevelProblemPreference(String messageId) {
+ return this.getProjectPreference(appendProblemPrefix(messageId));
+ }
+
+ public void setProjectLevelProblemPreference(String messageId, String problemPreference) {
+ this.setProjectPreference(appendProblemPrefix(messageId), problemPreference);
+ }
+
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/DefaultJpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/DefaultJpaValidationMessages.java
index 366250c267..7a0dd08990 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/DefaultJpaValidationMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/DefaultJpaValidationMessages.java
@@ -15,6 +15,7 @@ import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.JpaNode;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.internal.prefs.JpaValidationPreferencesManager;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -96,8 +97,8 @@ public class DefaultJpaValidationMessages {
{
public IMessage buildMessage(int severity, String messageId, String[] parms, IResource targetObject) {
// check for preference override
- int prefSeverity = JpaValidationPreferences.getProblemSeverityPreference(targetObject, messageId);
- if (prefSeverity != JpaValidationPreferences.NO_SEVERITY_PREFERENCE){
+ int prefSeverity = JpaValidationPreferencesManager.getProblemSeverityPreference(targetObject, messageId);
+ if (prefSeverity != JpaValidationPreferencesManager.NO_SEVERITY_PREFERENCE){
severity = prefSeverity;
}
IMessage message = new Message(JpaValidationMessages.BUNDLE_NAME, severity, messageId, parms, targetObject);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationPreferences.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationPreferences.java
deleted file mode 100644
index da9b129a1b..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationPreferences.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2012 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.core.internal.validation;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.jpt.common.utility.internal.Tools;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
-import org.osgi.service.prefs.BackingStoreException;
-
-//TODO: Probably want to merge the behavior in this class into JptJpaCorePlugin
-public class JpaValidationPreferences {
-
- /*
- * prefix for all preference strings. This is only used internally.
- * Clients of get*LevelProblemPrefernce() and set*LevelProblemPreference
- * should not include the prefix.
- */
- private static final String PROBLEM_PREFIX = "problem."; //$NON-NLS-1$
-
- public static final String ERROR = "error"; //$NON-NLS-1$
- public static final String WARNING = "warning"; //$NON-NLS-1$
- public static final String INFO = "info"; //$NON-NLS-1$
- public static final String IGNORE = "ignore"; //$NON-NLS-1$
-
- static final int NO_SEVERITY_PREFERENCE = -1;
-
- public static final String WORKSPACE_PREFERENCES_OVERRIDEN = "workspace_preferences_overriden"; //$NON-NLS-1$
-
- /**
- * Returns only the severity level of a given problem preference. This does not
- * include information on whether the problem is ignored. See isProblemIgnored.
- * @return an IMessage severity level
- */
- public static int getProblemSeverityPreference(IResource targetObject, String messageId) {
- String problemPreference = getPreference(targetObject.getProject(), messageId);
-
- if (problemPreference == null){
- return NO_SEVERITY_PREFERENCE;
- }
- if (problemPreference.equals(ERROR)){
- return IMessage.HIGH_SEVERITY;
- }
- if (problemPreference.equals(WARNING)){
- return IMessage.NORMAL_SEVERITY;
- }
- if (problemPreference.equals(INFO)){
- return IMessage.LOW_SEVERITY;
- }
- return NO_SEVERITY_PREFERENCE;
- }
-
- /**
- * Return whether the specified problem should <em>not</em> be ignored based
- * on project or workspace preferences.
- */
- public static boolean problemIsNotIgnored(IProject project, String messageId) {
- return ! problemIsIgnored(project, messageId);
- }
-
- /**
- * Return whether the specified problem should be ignored based on project or
- * workspace preferences.
- */
- public static boolean problemIsIgnored(IProject project, String messageId) {
- return Tools.valuesAreEqual(getPreference(project, messageId), IGNORE);
- }
-
- private static String getPreference(IProject project, String messageId) {
- String problemPreference = null;
- problemPreference = getProjectLevelProblemPreference(project, messageId);
- //if severity is still null, check the workspace preferences
- if (problemPreference == null) {
- problemPreference = getWorkspaceLevelProblemPreference(messageId);
- }
- return problemPreference;
- }
-
- /**
- * Returns the String value of the problem preference from the project preferences
- */
- public static String getProjectLevelProblemPreference(IProject project, String messageId){
- return getPreference(JptJpaCorePlugin.getProjectPreferences(project), messageId);
- }
-
- public static void setProjectLevelProblemPreference(IProject project, String messageId, String problemPreference) {
- IEclipsePreferences projectPreferences = JptJpaCorePlugin.getProjectPreferences(project);
- setPreference(projectPreferences, messageId, problemPreference);
- flush(projectPreferences);
- }
-
- /**
- * Returns the String value of the problem preference from the workspace preferences
- */
- public static String getWorkspaceLevelProblemPreference(String messageId){
- return getPreference(JptJpaCorePlugin.getWorkspacePreferences(), messageId);
- }
-
- public static void setWorkspaceLevelProblemPreference(String messageId, String problemPreference) {
- IEclipsePreferences workspacePreferences = JptJpaCorePlugin.getWorkspacePreferences();
- setPreference(workspacePreferences, messageId, problemPreference);
- flush(workspacePreferences);
- }
-
- private static String getPreference(IEclipsePreferences preferences, String messageId) {
- return preferences.get(appendProblemPrefix(messageId), null);
- }
-
- private static void setPreference(IEclipsePreferences preferences, String messageId, String problemPreference) {
- if (problemPreference == null){
- preferences.remove(appendProblemPrefix(messageId));
- }
- else {
- preferences.put(appendProblemPrefix(messageId), problemPreference);
- }
- }
-
- private static String appendProblemPrefix(String messageId) {
- return PROBLEM_PREFIX + messageId;
- }
-
- public static void flush(IEclipsePreferences prefs) {
- try {
- prefs.flush();
- } catch(BackingStoreException ex) {
- JptJpaCorePlugin.log(ex);
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java
index 05d2881d19..00da287307 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java
@@ -16,6 +16,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.internal.prefs.JpaValidationPreferencesManager;
import org.eclipse.wst.validation.AbstractValidator;
import org.eclipse.wst.validation.ValidationResult;
import org.eclipse.wst.validation.ValidationState;
@@ -90,7 +91,7 @@ public class JpaValidator
this.clearMarkers(project);
for (IMessage message : messages) {
// check preferences for IGNORE
- if (JpaValidationPreferences.problemIsNotIgnored(project, message.getId())) {
+ if ((new JpaValidationPreferencesManager(project)).problemIsNotIgnored(message.getId())) {
reporter.addMessage(this, message);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpql/JpaJpqlQueryHelper.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpql/JpaJpqlQueryHelper.java
index e5af6f7bc3..0b1c7ee76f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpql/JpaJpqlQueryHelper.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpql/JpaJpqlQueryHelper.java
@@ -14,6 +14,7 @@
package org.eclipse.jpt.jpa.core.jpql;
import java.util.List;
+
import org.eclipse.core.resources.IResource;
import org.eclipse.jpt.common.core.internal.utility.SimpleTextRange;
import org.eclipse.jpt.common.core.utility.TextRange;
@@ -21,9 +22,9 @@ import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.NamedQuery;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.internal.prefs.JpaValidationPreferencesManager;
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
-import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationPreferences;
import org.eclipse.jpt.jpa.core.jpql.spi.JpaManagedTypeProvider;
import org.eclipse.jpt.jpa.core.jpql.spi.JpaQuery;
import org.eclipse.persistence.jpa.jpql.AbstractJPQLQueryHelper;
@@ -180,7 +181,7 @@ public abstract class JpaJpqlQueryHelper extends AbstractJPQLQueryHelper {
}
protected int getValidationPreference(NamedQuery namedQuery) {
- return JpaValidationPreferences.getProblemSeverityPreference(
+ return JpaValidationPreferencesManager.getProblemSeverityPreference(
namedQuery.getResource(),
JpaValidationMessages.JPQL_QUERY_VALIDATION
);
@@ -212,7 +213,7 @@ public abstract class JpaJpqlQueryHelper extends AbstractJPQLQueryHelper {
* @return The global severity for validating JPQL queries
*/
protected int severity(IResource targetObject) {
- return JpaValidationPreferences.getProblemSeverityPreference(
+ return JpaValidationPreferencesManager.getProblemSeverityPreference(
targetObject,
JpaValidationMessages.JPQL_QUERY_VALIDATION
);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/builder/StaticWeavingBuilderConfigurator.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/builder/StaticWeavingBuilderConfigurator.java
index 5759ec39fb..301fc9eeda 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/builder/StaticWeavingBuilderConfigurator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/builder/StaticWeavingBuilderConfigurator.java
@@ -17,19 +17,16 @@ import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jpt.common.utility.internal.StringTools;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.internal.prefs.JpaPreferencesManager;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.LoggingLevel;
-import org.osgi.service.prefs.BackingStoreException;
/**
* Configures and coordinates StaticWeaving builder behavior for the project.
* Also handles the builder preferences.
*/
-public class StaticWeavingBuilderConfigurator
+public class StaticWeavingBuilderConfigurator extends JpaPreferencesManager
{
public static final String BUILDER_ID = EclipselinkStaticWeavingBuilder.BUILDER_ID;
@@ -39,24 +36,19 @@ public class StaticWeavingBuilderConfigurator
public static final String TARGET = "TARGET"; //$NON-NLS-1$
public static final String LOG_LEVEL = "LOG_LEVEL"; //$NON-NLS-1$
public static final String PERSISTENCE_INFO = "PERSISTENCE_INFO"; //$NON-NLS-1$
-
- private final IProject project;
// ********** constructors **********
public StaticWeavingBuilderConfigurator(IProject project) {
- this.project = project;
- if(this.project == null) {
- throw new RuntimeException("Project is null"); //$NON-NLS-1$
- }
+ super(project);
}
// ********** builder **********
public void addBuilder() {
try {
- IProjectDescription description = this.project.getDescription();
+ IProjectDescription description = this.getProject().getDescription();
ICommand[] commands = description.getBuildSpec();
ICommand newCommand = description.newCommand();
@@ -73,7 +65,7 @@ public class StaticWeavingBuilderConfigurator
newCommands[0] = newCommand;
}
description.setBuildSpec(newCommands);
- this.project.setDescription(description, null);
+ this.getProject().setDescription(description, null);
}
catch(CoreException ce) {
// if we can't read the information, the project isn't open
@@ -84,7 +76,7 @@ public class StaticWeavingBuilderConfigurator
public boolean projectHasStaticWeavingBuilder() {
try {
- IProjectDescription description = this.project.getDescription();
+ IProjectDescription description = this.getProject().getDescription();
ICommand[] commands = description.getBuildSpec();
if(commands.length == 0)
return false;
@@ -103,7 +95,7 @@ public class StaticWeavingBuilderConfigurator
public void removeBuilder() {
try {
- IProjectDescription description = this.project.getDescription();
+ IProjectDescription description = this.getProject().getDescription();
ICommand[] commands = description.getBuildSpec();
if(commands.length == 0)
return;
@@ -125,7 +117,7 @@ public class StaticWeavingBuilderConfigurator
newCommands[j++] = commands[i];
}
description.setBuildSpec(newCommands);
- this.project.setDescription(description, IResource.NONE, null);
+ this.getProject().setDescription(description, IResource.NONE, null);
}
catch(CoreException ce) {
// if we can't read the information, the project isn't open
@@ -139,22 +131,22 @@ public class StaticWeavingBuilderConfigurator
public String getSourceLocationPreference() {
- return this.getPreference(SOURCE, this.getDefaultSourceLocation());
+ return this.getProjectPreference(this.appendPrefix(SOURCE), this.getDefaultSourceLocation());
}
public String getTargetLocationPreference() {
- return this.getPreference(TARGET, this.getDefaultTargetLocation());
+ return this.getProjectPreference(this.appendPrefix(TARGET), this.getDefaultTargetLocation());
}
public String getPersistenceInfoPreference() {
- return this.getPreference(PERSISTENCE_INFO, this.getDefaultPersistenceInfo());
+ return this.getProjectPreference(this.appendPrefix(PERSISTENCE_INFO), this.getDefaultPersistenceInfo());
}
public String getLogLevelPreference() {
- return this.getPreference(LOG_LEVEL, this.getDefaultLogLevel());
+ return this.getProjectPreference(this.appendPrefix(LOG_LEVEL), this.getDefaultLogLevel());
}
// default preferences value
@@ -183,76 +175,35 @@ public class StaticWeavingBuilderConfigurator
// setting and removing preferences
public void setSourceLocationPreference(String location) {
- this.setPreference(SOURCE, location);
+ this.setProjectPreference(this.appendPrefix(SOURCE), location);
}
public void removeSourceLocationPreference() {
- this.setPreference(SOURCE, null);
+ this.setProjectPreference(this.appendPrefix(SOURCE), null);
}
public void setTargetLocationPreference(String location) {
- this.setPreference(TARGET, location);
+ this.setProjectPreference(this.appendPrefix(TARGET), location);
}
public void removeTargetLocationPreference() {
- this.setPreference(TARGET, null);
+ this.setProjectPreference(this.appendPrefix(TARGET), null);
}
public void setLogLevelPreference(String logLevel) {
- this.setPreference(LOG_LEVEL, logLevel);
+ this.setProjectPreference(this.appendPrefix(LOG_LEVEL), logLevel);
}
public void removeLogLevelPreference() {
- this.setPreference(LOG_LEVEL, null);
+ this.setProjectPreference(this.appendPrefix(LOG_LEVEL), null);
}
public void setPersistenceInfoPreference(String persistenceInfo) {
- this.setPreference(PERSISTENCE_INFO, persistenceInfo);
+ this.setProjectPreference(this.appendPrefix(PERSISTENCE_INFO), persistenceInfo);
}
public void removePersistenceInfoPreference() {
- this.setPreference(PERSISTENCE_INFO, null);
- }
-
- // fush preferences
-
- public void flush(IEclipsePreferences prefs) {
- try {
- prefs.flush();
- }
- catch(BackingStoreException ex) {
- JptJpaCorePlugin.log(ex);
- }
- }
-
- // ********** preferences private methods **********
-
- private String getPreference(String id, String defaultValue) {
- return this.getPreference_(JptJpaCorePlugin.getProjectPreferences(this.project), id, defaultValue);
- }
-
- private String getPreference_(IEclipsePreferences prefs, String id, String defaultValue) {
- return prefs.get(this.appendStaticWeavePrefix(id), defaultValue);
- }
-
- private String appendStaticWeavePrefix(String id) {
- return STATIC_WEAVE_PREFIX + id;
- }
-
- private void setPreference(String id, String staticWeavePreference) {
- IEclipsePreferences projectPrefs = JptJpaCorePlugin.getProjectPreferences(this.project);
-
- this.setPreference_(projectPrefs, id, staticWeavePreference);
- this.flush(projectPrefs);
- }
-
- private void setPreference_(IEclipsePreferences preferences, String id, String staticWeavePreference) {
- if(StringTools.stringIsEmpty(staticWeavePreference)) {
- preferences.remove(this.appendStaticWeavePrefix(id));
- }
- else {
- preferences.put(this.appendStaticWeavePrefix(id), staticWeavePreference);
- }
+ this.setProjectPreference(this.appendPrefix(PERSISTENCE_INFO), null);
}
// ********** private methods **********
@@ -273,14 +224,18 @@ public class StaticWeavingBuilderConfigurator
IPath outputLocation = this.getJavaProject().getOutputLocation();
String projectName = outputLocation.segment(0);
- if(this.project.getName().equals(projectName)) {
+ if(this.getProject().getName().equals(projectName)) {
outputLocation = outputLocation.removeFirstSegments(1);
}
return outputLocation;
}
private IJavaProject getJavaProject() {
- return JavaCore.create(this.project);
+ return JavaCore.create(this.getProject());
+ }
+
+ private String appendPrefix(String id) {
+ return STATIC_WEAVE_PREFIX + id;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/weave/EclipselinkPreferencePage.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/weave/EclipselinkPreferencePage.java
index 39e681803c..1c684cdd58 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/weave/EclipselinkPreferencePage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/weave/EclipselinkPreferencePage.java
@@ -62,7 +62,7 @@ public class EclipselinkPreferencePage extends PropertyPage {
}
return true;
}
-
+
@Override
protected Control createContents(Composite parent) {
this.configurator = new StaticWeavingBuilderConfigurator(this.getProject());
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java
index 0891871651..8705f4782d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
@@ -21,7 +22,6 @@ import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage;
import org.eclipse.jdt.internal.ui.preferences.ScrolledPageContent;
@@ -31,9 +31,8 @@ import org.eclipse.jface.layout.PixelConverter;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.internal.prefs.JpaValidationPreferencesManager;
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
-import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationPreferences;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
import org.eclipse.jpt.jpa.ui.internal.JptUiValidationPreferenceMessages;
@@ -151,6 +150,9 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
*/
public static final String SETTINGS_SECTION_NAME = "JpaProblemSeveritiesPage"; //$NON-NLS-1$
+
+ private JpaValidationPreferencesManager preferencesManager;
+
private Boolean hasProjectSpecificPreferences = null;
/**
@@ -166,7 +168,17 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
this.setPreferenceStore(JptJpaUiPlugin.instance().getPreferenceStore());
this.setDescription(JptUiMessages.JpaProblemSeveritiesPage_Description);
}
-
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Control control = super.createContents(parent);
+
+ if(this.isProjectPreferencePage()) {
+ this.preferencesManager = new JpaValidationPreferencesManager(this.getProject());
+ }
+ return control;
+ }
+
protected void initialize() {
this.combos = new ArrayList<Combo>();
this.expandablePanes = new ArrayList<ExpandableComposite>();
@@ -179,22 +191,22 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
protected Map<String, String> buildDefaultSeverities() {
Map<String, String> result = new HashMap<String, String>();
- result.put(JpaValidationMessages.PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.PROJECT_NO_CONNECTION, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.PROJECT_INVALID_CONNECTION, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.PROJECT_INACTIVE_CONNECTION, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.MAPPING_FILE_EXTRANEOUS_PERSISTENCE_UNIT_METADATA, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.PERSISTENT_TYPE_DUPLICATE_CLASS, JpaValidationPreferences.WARNING); //3.0 M7
- result.put(JpaValidationMessages.PERSISTENCE_UNIT_JAR_FILE_DEPLOYMENT_PATH_WARNING, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.PERSISTENT_TYPE_ANNOTATED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_VERSION_MAPPING_TYPE, JpaValidationPreferences.WARNING); //3.0 M7
- result.put(JpaValidationMessages.ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED, JpaValidationPreferences.WARNING);
- result.put(JpaValidationMessages.ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM, JpaValidationPreferences.WARNING);
-
- result.put(JpaValidationMessages.XML_VERSION_NOT_LATEST, JpaValidationPreferences.INFO);
- result.put(JpaValidationMessages.PERSISTENCE_UNIT_REDUNDANT_CLASS, JpaValidationPreferences.INFO);
+ result.put(JpaValidationMessages.PERSISTENCE_MULTIPLE_PERSISTENCE_UNITS, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.PROJECT_NO_CONNECTION, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.PROJECT_INVALID_CONNECTION, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.PROJECT_INACTIVE_CONNECTION, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.MAPPING_FILE_EXTRANEOUS_PERSISTENCE_UNIT_METADATA, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.PERSISTENT_TYPE_DUPLICATE_CLASS, JpaValidationPreferencesManager.WARNING); //3.0 M7
+ result.put(JpaValidationMessages.PERSISTENCE_UNIT_JAR_FILE_DEPLOYMENT_PATH_WARNING, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.PERSISTENT_TYPE_ANNOTATED_BUT_NOT_INCLUDED_IN_PERSISTENCE_UNIT, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_VERSION_MAPPING_TYPE, JpaValidationPreferencesManager.WARNING); //3.0 M7
+ result.put(JpaValidationMessages.ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED, JpaValidationPreferencesManager.WARNING);
+ result.put(JpaValidationMessages.ENTITY_TABLE_PER_CLASS_NOT_PORTABLE_ON_PLATFORM, JpaValidationPreferencesManager.WARNING);
+
+ result.put(JpaValidationMessages.XML_VERSION_NOT_LATEST, JpaValidationPreferencesManager.INFO);
+ result.put(JpaValidationMessages.PERSISTENCE_UNIT_REDUNDANT_CLASS, JpaValidationPreferencesManager.INFO);
return result;
}
@@ -672,12 +684,12 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
protected String getPreferenceValue(String preferenceKey) {
String preference = null;
- if (isProjectPreferencePage() && hasProjectSpecificOptions(getProject())) { //useProjectSettings() won't work since the page is being built
- preference = JpaValidationPreferences.getProjectLevelProblemPreference(getProject(), preferenceKey);
+ if (this.isProjectPreferencePage() && this.hasProjectSpecificOptions(this.getProject())) { //useProjectSettings() won't work since the page is being built
+ preference = this.preferencesManager.getProjectLevelProblemPreference(preferenceKey);
}
else {
//don't get the workspace preference when the project has overridden workspace preferences
- preference = JpaValidationPreferences.getWorkspaceLevelProblemPreference(preferenceKey);
+ preference = JpaValidationPreferencesManager.getWorkspaceLevelProblemPreference(preferenceKey);
}
if (preference == null) {
preference = getDefaultPreferenceValue(preferenceKey);
@@ -690,20 +702,20 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
*/
protected String getDefaultPreferenceValue(String preferenceKey) {
String preference = this.defaultSeverities.get(preferenceKey);
- return preference == null ? JpaValidationPreferences.ERROR : preference;
+ return preference == null ? JpaValidationPreferencesManager.ERROR : preference;
}
protected int convertPreferenceValueToComboIndex(String preferenceValue) {
- if (JpaValidationPreferences.ERROR.equals(preferenceValue)) {
+ if (JpaValidationPreferencesManager.ERROR.equals(preferenceValue)) {
return ERROR_INDEX;
}
- if (JpaValidationPreferences.WARNING.equals(preferenceValue)) {
+ if (JpaValidationPreferencesManager.WARNING.equals(preferenceValue)) {
return WARNING_INDEX;
}
- if (JpaValidationPreferences.INFO.equals(preferenceValue)) {
+ if (JpaValidationPreferencesManager.INFO.equals(preferenceValue)) {
return INFO_INDEX;
}
- if (JpaValidationPreferences.IGNORE.equals(preferenceValue)) {
+ if (JpaValidationPreferencesManager.IGNORE.equals(preferenceValue)) {
return IGNORE_INDEX;
}
throw new IllegalStateException();
@@ -711,10 +723,10 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
protected String convertToPreferenceValue(int selectionIndex) {
switch (selectionIndex) {
- case ERROR_INDEX: return JpaValidationPreferences.ERROR;
- case WARNING_INDEX: return JpaValidationPreferences.WARNING;
- case INFO_INDEX: return JpaValidationPreferences.INFO;
- case IGNORE_INDEX: return JpaValidationPreferences.IGNORE;
+ case ERROR_INDEX: return JpaValidationPreferencesManager.ERROR;
+ case WARNING_INDEX: return JpaValidationPreferencesManager.WARNING;
+ case INFO_INDEX: return JpaValidationPreferencesManager.INFO;
+ case IGNORE_INDEX: return JpaValidationPreferencesManager.IGNORE;
default: return null;
}
}
@@ -738,14 +750,9 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
return JPT_PROPERTY_PAGES_PROBLEM_SEVERITIES_ID;
}
- protected IEclipsePreferences getProjectPreferences(IProject project) {
- return JptJpaCorePlugin.getProjectPreferences(project);
- }
-
@Override
protected boolean hasProjectSpecificOptions(IProject project) {
- IEclipsePreferences projectPreferences = getProjectPreferences(project);
- return projectPreferences.getBoolean(JpaValidationPreferences.WORKSPACE_PREFERENCES_OVERRIDEN, false);
+ return this.preferencesManager.projectHasSpecificOptions();
}
@Override
@@ -795,7 +802,7 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
protected void overrideWorkspacePreferences() {
for (Combo combo : this.combos) {
String preferenceKey = (String) combo.getData(PREFERENCE_KEY);
- String workspacePreference = JpaValidationPreferences.getWorkspaceLevelProblemPreference(preferenceKey);
+ String workspacePreference = JpaValidationPreferencesManager.getWorkspaceLevelProblemPreference(preferenceKey);
String defaultPreference = getDefaultPreferenceValue(preferenceKey);
if (workspacePreference != null && !workspacePreference.equals(defaultPreference)) {
combo.select(convertPreferenceValueToComboIndex(workspacePreference));
@@ -814,17 +821,10 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
public boolean performOk() {
super.performOk();
if (this.hasProjectSpecificPreferences != null) {
- IEclipsePreferences projectPreferences = getProjectPreferences(getProject());
- if (this.hasProjectSpecificPreferences.booleanValue()) {
- projectPreferences.putBoolean(JpaValidationPreferences.WORKSPACE_PREFERENCES_OVERRIDEN, true);
- }
- else {
- projectPreferences.remove(JpaValidationPreferences.WORKSPACE_PREFERENCES_OVERRIDEN);
- }
- JpaValidationPreferences.flush(projectPreferences);
+ this.preferencesManager.setProjectHasSpecificOptions(this.hasProjectSpecificPreferences.booleanValue());
}
for (String validationPreferenceKey : this.severityLevels.keySet()) {
- updatePreference(validationPreferenceKey, this.severityLevels.get(validationPreferenceKey));
+ this.updatePreference(validationPreferenceKey, this.severityLevels.get(validationPreferenceKey));
}
try {
// true=fork; false=uncancellable
@@ -843,11 +843,11 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
}
protected void updatePreference(String preferenceKey, String value) {
- if (isProjectPreferencePage()) {
- JpaValidationPreferences.setProjectLevelProblemPreference(getProject(), preferenceKey, value);
+ if (this.isProjectPreferencePage()) {
+ this.preferencesManager.setProjectLevelProblemPreference(preferenceKey, value);
}
else {
- JpaValidationPreferences.setWorkspaceLevelProblemPreference(preferenceKey, value);
+ JpaValidationPreferencesManager.setWorkspaceLevelProblemPreference(preferenceKey, value);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
index fa5aac3462..9c692005a3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
@@ -262,7 +262,7 @@ public class NewEntityClassOperation extends AbstractDataModelOperation {
}
if (tempModel.isArtifactsAnnotated()) {
- if ( ! JptJpaCorePlugin.discoverAnnotatedClasses(project)) {
+ if ( ! JptJpaCorePlugin.getDiscoverAnnotatedClasses(project)) {
registerClassInPersistenceXml(tempModel, project).schedule();
}
} else {
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java
index dd1ef03c55..f3b96b3b39 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java
@@ -14,6 +14,7 @@ import org.eclipse.core.runtime.Plugin;
import org.eclipse.jpt.common.utility.internal.ReflectionTools;
import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.internal.prefs.JpaPreferencesManager;
import org.osgi.framework.BundleContext;
/**
@@ -51,7 +52,7 @@ public class JptJpaCoreTestsPlugin
JpaProjectManager jpaProjectManager = this.getJpaProjectManager();
ReflectionTools.executeMethod(jpaProjectManager, "executeCommandsSynchronously");
ReflectionTools.setFieldValue(jpaProjectManager, "test", Boolean.TRUE);
- ReflectionTools.executeStaticMethod(JptJpaCorePlugin.class, "doNotFlushPreferences");
+ ReflectionTools.executeStaticMethod(JpaPreferencesManager.class, "doNotFlushPreferences");
}
private JpaProjectManager getJpaProjectManager() {
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/ContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/ContextModelTestCase.java
index c21bb21b2c..f79ef43756 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/ContextModelTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/ContextModelTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -31,6 +31,7 @@ import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetDataModelProperties;
import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProperties;
import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProvider;
+import org.eclipse.jpt.jpa.core.internal.prefs.JpaPreferencesManager;
import org.eclipse.jpt.jpa.core.platform.GenericPlatform;
import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings;
@@ -72,7 +73,7 @@ public abstract class ContextModelTestCase extends AnnotationTestCase
protected void tearDown() throws Exception {
this.persistenceXmlResource = null;
this.ormXmlResource = null;
- JptJpaCorePlugin.getWorkspacePreferences().clear();
+ JpaPreferencesManager.clearWorkspacePreferences();
this.waitForWorkspaceJobsToFinish();
super.tearDown();
}

Back to the top