Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal')
-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
8 files changed, 498 insertions, 147 deletions
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);
}
}

Back to the top