Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1e2014830419796f4ba05a8bd017dcc8f76812f4 (plain) (blame)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.preferences;

import org.eclipse.cdt.core.lrparser.xlc.activator.XlcParserPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.Preferences;

/**
 * TODO trigger the indexer?
 * 
 * @author Mike Kucera
 */
public class XlcLanguagePreferences  {

	private static final String QUALIFIER = XlcParserPlugin.PLUGIN_ID;
	private static final String XLC_PREFERENCES_NODE = "xlc.preferences";


	static void initializeDefaultPreferences() {
		Preferences defaultNode = getDefaultPreferences();
		
		for(XlcPref p : XlcPref.values()) {
			defaultNode.put(p.toString(), p.getDefaultValue());
		}
	}
	
	
	
	public static void setProjectPreference(XlcPref key, String value, IProject project) {
		getProjectPreferences(project).put(key.toString(), value);
	}
	
	public static void setWorkspacePreference(XlcPref key, String value) {
		getWorkspacePreferences().put(key.toString(), value);
	}
	
	
	
	public static String getProjectPreference(XlcPref key, IProject project) {
		return getProjectPreferences(project).get(key.toString(), null);
	}

	public static String getWorkspacePreference(XlcPref key) {
		return getWorkspacePreferences().get(key.toString(), null);
	}
	
	public static String getDefaultPreference(XlcPref key) {
		return getDefaultPreferences().get(key.toString(), null);
	}
	

	/**
	 * Returns the preference for the given key.
	 * 
	 * @param project If null then just the workspace and default preferences will be checked.
	 */
	public static String get(XlcPref key, IProject project) {
		return Platform.getPreferencesService().get(key.toString(), null, getPreferences(project));
	}

	private static Preferences[] getPreferences(IProject project) {
		if(project == null) {
			return new Preferences[] {
				getWorkspacePreferences(),
				getDefaultPreferences()
			};
		}
		else {
			return new Preferences[] {
				getProjectPreferences(project),
				getWorkspacePreferences(),
				getDefaultPreferences()
			};
		}
	}
	
	
	
	private static Preferences getDefaultPreferences() {
		return getPreferences(new DefaultScope());
	}
	
	private static Preferences getWorkspacePreferences() {
		return getPreferences(new InstanceScope());
	}
	
	private static Preferences getProjectPreferences(IProject project) {
		return getPreferences(new ProjectScope(project));
	}

	private static Preferences getPreferences(IScopeContext scope) {
		return scope.getNode(QUALIFIER).node(XLC_PREFERENCES_NODE);
	}


	
}

Back to the top