1
/*******************************************************************************
2
* Copyright (c) 2009 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.core.lrparser.xlc.preferences;
13
import org.eclipse.cdt.core.lrparser.xlc.activator.XlcParserPlugin;
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.ProjectScope;
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.preferences.DefaultScope;
18
import org.eclipse.core.runtime.preferences.IScopeContext;
19
import org.eclipse.core.runtime.preferences.InstanceScope;
20
import org.osgi.service.prefs.Preferences;
23
* TODO trigger the indexer?
27
public class XlcLanguagePreferences {
29
private static final String QUALIFIER = XlcParserPlugin.PLUGIN_ID;
30
private static final String XLC_PREFERENCES_NODE = "xlc.preferences";
33
static void initializeDefaultPreferences() {
34
Preferences defaultNode = getDefaultPreferences();
36
for(XlcPref p : XlcPref.values()) {
37
defaultNode.put(p.toString(), p.getDefaultValue());
43
public static void setProjectPreference(XlcPref key, String value, IProject project) {
44
getProjectPreferences(project).put(key.toString(), value);
47
public static void setWorkspacePreference(XlcPref key, String value) {
48
getWorkspacePreferences().put(key.toString(), value);
53
public static String getProjectPreference(XlcPref key, IProject project) {
54
return getProjectPreferences(project).get(key.toString(), null);
57
public static String getWorkspacePreference(XlcPref key) {
58
return getWorkspacePreferences().get(key.toString(), null);
61
public static String getDefaultPreference(XlcPref key) {
62
return getDefaultPreferences().get(key.toString(), null);
67
* Returns the preference for the given key.
69
* @param project If null then just the workspace and default preferences will be checked.
71
public static String get(XlcPref key, IProject project) {
72
return Platform.getPreferencesService().get(key.toString(), null, getPreferences(project));
75
private static Preferences[] getPreferences(IProject project) {
77
return new Preferences[] {
78
getWorkspacePreferences(),
79
getDefaultPreferences()
83
return new Preferences[] {
84
getProjectPreferences(project),
85
getWorkspacePreferences(),
86
getDefaultPreferences()
93
private static Preferences getDefaultPreferences() {
94
return getPreferences(new DefaultScope());
97
private static Preferences getWorkspacePreferences() {
98
return getPreferences(new InstanceScope());
101
private static Preferences getProjectPreferences(IProject project) {
102
return getPreferences(new ProjectScope(project));
105
private static Preferences getPreferences(IScopeContext scope) {
106
return scope.getNode(QUALIFIER).node(XLC_PREFERENCES_NODE);