diff options
author | tle | 2012-02-20 19:30:23 +0000 |
---|---|---|
committer | tle | 2012-02-20 19:30:23 +0000 |
commit | 17f02c829619fcf7e95e96d9c51aac6936f2c423 (patch) | |
tree | 9ef10076e2d2ecac2d1b8fdacbe4d57ef7374dc7 /jpa/plugins/org.eclipse.jpt.jpa.core/src | |
parent | 3c6ec5a8fb6843b0620c946dfa22f569f027afa9 (diff) | |
download | webtools.dali-17f02c829619fcf7e95e96d9c51aac6936f2c423.tar.gz webtools.dali-17f02c829619fcf7e95e96d9c51aac6936f2c423.tar.xz webtools.dali-17f02c829619fcf7e95e96d9c51aac6936f2c423.zip |
Refactored preferences support with JpaPreferencesManager
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core/src')
10 files changed, 531 insertions, 400 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 ); |