Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornhauge2009-10-28 21:33:10 +0000
committernhauge2009-10-28 21:33:10 +0000
commitef54878f1d792e3e8d4b5da976c157dbefb95cff (patch)
tree49d4737b22e3c671ed8ecb8348eaad8ac184bbae
parenta57d3501feb0470e57f72e5a9810a50bd2dc57ea (diff)
downloadwebtools.dali-ef54878f1d792e3e8d4b5da976c157dbefb95cff.tar.gz
webtools.dali-ef54878f1d792e3e8d4b5da976c157dbefb95cff.tar.xz
webtools.dali-ef54878f1d792e3e8d4b5da976c157dbefb95cff.zip
285895 - Add JDT style problem preferences. Base utility. Still need to add ignore-check to every existing problem built in the model.
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/DefaultJpaValidationMessages.java23
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationPreferences.java101
2 files changed, 116 insertions, 8 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/DefaultJpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/DefaultJpaValidationMessages.java
index ae30b69460..2136e52e5e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/DefaultJpaValidationMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/DefaultJpaValidationMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2009 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.
@@ -20,22 +20,29 @@ public class DefaultJpaValidationMessages {
private static TextRange DEFAULT_TEXT_RANGE = TextRange.Empty.instance();
public static IMessage buildMessage(
- int severity, String messageId, Object targetObject) {
- return buildMessage(severity, messageId, DEFAULT_PARMS, targetObject);
+ int defaultSeverity, String messageId, Object targetObject) {
+ return buildMessage(defaultSeverity, messageId, DEFAULT_PARMS, targetObject);
}
public static IMessage buildMessage(
- int severity, String messageId, String[] parms, Object targetObject) {
- return buildMessage(severity, messageId, parms, targetObject, DEFAULT_TEXT_RANGE);
+ int defaultSeverity, String messageId, String[] parms, Object targetObject) {
+ return buildMessage(defaultSeverity, messageId, parms, targetObject, DEFAULT_TEXT_RANGE);
}
public static IMessage buildMessage(
- int severity, String messageId, Object targetObject, TextRange textRange) {
- return buildMessage(severity, messageId, DEFAULT_PARMS, targetObject, textRange);
+ int defaultSeverity, String messageId, Object targetObject, TextRange textRange) {
+ return buildMessage(defaultSeverity, messageId, DEFAULT_PARMS, targetObject, textRange);
}
public static IMessage buildMessage(
- int severity, String messageId, String[] parms, Object targetObject, TextRange textRange) {
+ int defaultSeverity, String messageId, String[] parms, Object targetObject, TextRange textRange) {
+
+ //determine whether default severity should be overridden
+ int severity = defaultSeverity;
+ int severityPreference = JpaValidationPreferences.getProblemSeverityPreference(targetObject, messageId);
+ if (severityPreference!=JpaValidationPreferences.NO_SEVERITY_PREFERENCE){
+ severity = severityPreference;
+ }
IMessage message = new Message(JpaValidationMessages.BUNDLE_NAME, severity, messageId, parms, targetObject);
if (textRange == null) {
//log an exception and then continue without setting location information
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationPreferences.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationPreferences.java
new file mode 100644
index 0000000000..b43ed7928e
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationPreferences.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2009 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.core.internal.validation;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jpt.core.IResourcePart;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+
+public class JpaValidationPreferences {
+
+ static String HIGH_SEVERITY = "error";
+ static String NORMAL_SEVERITY = "warning";
+ static String LOW_SEVERITY = "info";
+ static String IGNORE = "ignore";
+
+ static int NO_SEVERITY_PREFERENCE = -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(Object targetObject, String messageId) {
+
+ IAdaptable target = (IAdaptable)targetObject;
+ IResource resource = ((IResourcePart) target.getAdapter(IResourcePart.class)).getResource();
+ IProject project = resource.getProject();
+
+ String problemPreference = getPreference(project, messageId);
+
+ if (problemPreference==null){
+ return NO_SEVERITY_PREFERENCE;
+ }else if (problemPreference.equals(HIGH_SEVERITY)){
+ return IMessage.HIGH_SEVERITY;
+ } else if (problemPreference.equals(NORMAL_SEVERITY)){
+ return IMessage.NORMAL_SEVERITY;
+ } else if (problemPreference.equals(LOW_SEVERITY)){
+ return IMessage.LOW_SEVERITY;
+ }
+ return NO_SEVERITY_PREFERENCE;
+ }
+
+ /**
+ * Returns whether or not this problem should be ignored based on project or
+ * workspace preferences
+ */
+ public static boolean isProblemIgnored(IProject project, String messageId){
+ String problemPreference = getPreference(project, messageId);
+ if (problemPreference.equals(IGNORE)){
+ return true;
+ }
+ return false;
+ }
+
+ 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){
+ IEclipsePreferences projectPreferences = JptCorePlugin.getProjectPreferences(project);
+ return projectPreferences.get(messageId, null);
+ }
+
+ public static void setProjectLevelProblemPreference(IProject project, String messageId, String problemPreference) {
+ IEclipsePreferences projectPreferences = JptCorePlugin.getProjectPreferences(project);
+ projectPreferences.put(messageId, problemPreference);
+ }
+
+ /**
+ * Returns the String value of the problem preference from the workspace preferences
+ */
+ public static String getWorkspaceLevelProblemPreference(String messageId){
+ IEclipsePreferences workspacePreferences = JptCorePlugin.getWorkspacePreferences();
+ return workspacePreferences.get(messageId, null);
+ }
+
+ public static void setWorkspaceLevelProblemPreference(String messageId, String problemPreference) {
+ IEclipsePreferences workspacePreferences = JptCorePlugin.getWorkspacePreferences();
+ workspacePreferences.put(messageId, problemPreference);
+ }
+}

Back to the top