-
Notifications
You must be signed in to change notification settings - Fork 7
/
EMFModelValidationPreferences.java
94 lines (81 loc) · 2.79 KB
/
EMFModelValidationPreferences.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/******************************************************************************
* Copyright (c) 2003, 2007 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
****************************************************************************/
package org.eclipse.emf.validation.preferences;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.emf.validation.internal.EMFModelValidationPlugin;
import org.eclipse.emf.validation.service.ConstraintRegistry;
import org.eclipse.emf.validation.service.IConstraintDescriptor;
/**
* Preferences manager for the EMF model validation plug-in.
*
* @author Christian W. Damus (cdamus)
*/
public class EMFModelValidationPreferences {
static final String CONSTRAINT_DISABLED_PREFIX = "con.disabled/"; //$NON-NLS-1$
private static final Preferences prefs = EMFModelValidationPlugin.getPlugin().getPluginPreferences();
/**
* Not instantiable, as all features are static.
*/
private EMFModelValidationPreferences() {
super();
}
/**
* Saves the preferences.
*/
public static void save() {
EMFModelValidationPlugin.getPlugin().savePluginPreferences();
}
/**
* Queries whether the specified constraint <code>ID</code> is disabled.
*
* @param id the constraint ID
* @return whether it is disabled
*/
public static boolean isConstraintDisabled(String id) {
return prefs.getBoolean(CONSTRAINT_DISABLED_PREFIX + id);
}
/**
* Queries whether the specified constraint <code>ID</code> is disabled by
* default.
*
* @param id the constraint ID
* @return whether it is disabled
*/
public static boolean isConstraintDisabledByDefault(String id) {
return prefs.getDefaultBoolean(CONSTRAINT_DISABLED_PREFIX + id);
}
/**
* Sets whether the specified constraint <code>id</code> is disabled.
*
* @param id the constraint ID
* @param disabled whether it is disabled
*/
public static void setConstraintDisabled(String id, boolean disabled) {
final String prefName = CONSTRAINT_DISABLED_PREFIX + id;
final IConstraintDescriptor constraint = ConstraintRegistry.getInstance().getDescriptor(id);
prefs.setValue(prefName, disabled);
if (constraint != null) {
// set its enablement from the new preference value
constraint.setEnabled(!disabled);
} else {
// remove this preference to declutter the prefs.ini file
prefs.setToDefault(prefName);
}
}
/**
* @since 1.4
*/
public static void setConstraintDisabledDefault(String id, boolean disabled) {
final String prefName = CONSTRAINT_DISABLED_PREFIX + id;
prefs.setDefault(prefName, disabled);
}
}