~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to xlc/org.eclipse.cdt.core.lrparser.xlc/parser/org/eclipse/cdt/core/lrparser/xlc/preferences/XlcLanguagePreferences.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.core.lrparser.xlc.preferences;
 
12
 
 
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;
 
21
 
 
22
/**
 
23
 * TODO trigger the indexer?
 
24
 * 
 
25
 * @author Mike Kucera
 
26
 */
 
27
public class XlcLanguagePreferences  {
 
28
 
 
29
        private static final String QUALIFIER = XlcParserPlugin.PLUGIN_ID;
 
30
        private static final String XLC_PREFERENCES_NODE = "xlc.preferences";
 
31
 
 
32
 
 
33
        static void initializeDefaultPreferences() {
 
34
                Preferences defaultNode = getDefaultPreferences();
 
35
                
 
36
                for(XlcPref p : XlcPref.values()) {
 
37
                        defaultNode.put(p.toString(), p.getDefaultValue());
 
38
                }
 
39
        }
 
40
        
 
41
        
 
42
        
 
43
        public static void setProjectPreference(XlcPref key, String value, IProject project) {
 
44
                getProjectPreferences(project).put(key.toString(), value);
 
45
        }
 
46
        
 
47
        public static void setWorkspacePreference(XlcPref key, String value) {
 
48
                getWorkspacePreferences().put(key.toString(), value);
 
49
        }
 
50
        
 
51
        
 
52
        
 
53
        public static String getProjectPreference(XlcPref key, IProject project) {
 
54
                return getProjectPreferences(project).get(key.toString(), null);
 
55
        }
 
56
 
 
57
        public static String getWorkspacePreference(XlcPref key) {
 
58
                return getWorkspacePreferences().get(key.toString(), null);
 
59
        }
 
60
        
 
61
        public static String getDefaultPreference(XlcPref key) {
 
62
                return getDefaultPreferences().get(key.toString(), null);
 
63
        }
 
64
        
 
65
 
 
66
        /**
 
67
         * Returns the preference for the given key.
 
68
         * 
 
69
         * @param project If null then just the workspace and default preferences will be checked.
 
70
         */
 
71
        public static String get(XlcPref key, IProject project) {
 
72
                return Platform.getPreferencesService().get(key.toString(), null, getPreferences(project));
 
73
        }
 
74
 
 
75
        private static Preferences[] getPreferences(IProject project) {
 
76
                if(project == null) {
 
77
                        return new Preferences[] {
 
78
                                getWorkspacePreferences(),
 
79
                                getDefaultPreferences()
 
80
                        };
 
81
                }
 
82
                else {
 
83
                        return new Preferences[] {
 
84
                                getProjectPreferences(project),
 
85
                                getWorkspacePreferences(),
 
86
                                getDefaultPreferences()
 
87
                        };
 
88
                }
 
89
        }
 
90
        
 
91
        
 
92
        
 
93
        private static Preferences getDefaultPreferences() {
 
94
                return getPreferences(new DefaultScope());
 
95
        }
 
96
        
 
97
        private static Preferences getWorkspacePreferences() {
 
98
                return getPreferences(new InstanceScope());
 
99
        }
 
100
        
 
101
        private static Preferences getProjectPreferences(IProject project) {
 
102
                return getPreferences(new ProjectScope(project));
 
103
        }
 
104
 
 
105
        private static Preferences getPreferences(IScopeContext scope) {
 
106
                return scope.getNode(QUALIFIER).node(XLC_PREFERENCES_NODE);
 
107
        }
 
108
 
 
109
 
 
110
        
 
111
}