KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > formatter > FormatterProfileManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.ui.preferences.formatter;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collections JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.eclipse.core.runtime.preferences.DefaultScope;
19 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20 import org.eclipse.core.runtime.preferences.IScopeContext;
21
22 import org.eclipse.jdt.core.JavaCore;
23 import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
24
25 import org.eclipse.jdt.ui.JavaUI;
26 import org.eclipse.jdt.ui.PreferenceConstants;
27
28 import org.eclipse.jdt.internal.ui.preferences.PreferencesAccess;
29
30 public class FormatterProfileManager extends ProfileManager {
31     
32     public final static String JavaDoc ECLIPSE21_PROFILE= "org.eclipse.jdt.ui.default_profile"; //$NON-NLS-1$
33
public final static String JavaDoc ECLIPSE_PROFILE= "org.eclipse.jdt.ui.default.eclipse_profile"; //$NON-NLS-1$
34
public final static String JavaDoc JAVA_PROFILE= "org.eclipse.jdt.ui.default.sun_profile"; //$NON-NLS-1$
35

36     public final static String JavaDoc DEFAULT_PROFILE= ECLIPSE_PROFILE;
37     
38     private final static KeySet[] KEY_SETS= new KeySet[] {
39         new KeySet(JavaCore.PLUGIN_ID, new ArrayList JavaDoc(DefaultCodeFormatterConstants.getJavaConventionsSettings().keySet())),
40         new KeySet(JavaUI.ID_PLUGIN, Collections.EMPTY_LIST)
41     };
42     
43     private final static String JavaDoc PROFILE_KEY= PreferenceConstants.FORMATTER_PROFILE;
44     private final static String JavaDoc FORMATTER_SETTINGS_VERSION= "formatter_settings_version"; //$NON-NLS-1$
45

46     public FormatterProfileManager(List JavaDoc profiles, IScopeContext context, PreferencesAccess preferencesAccess, IProfileVersioner profileVersioner) {
47         super(addBuiltinProfiles(profiles, profileVersioner), context, preferencesAccess, profileVersioner, KEY_SETS, PROFILE_KEY, FORMATTER_SETTINGS_VERSION);
48     }
49     
50     private static List JavaDoc addBuiltinProfiles(List JavaDoc profiles, IProfileVersioner profileVersioner) {
51         final Profile javaProfile= new BuiltInProfile(JAVA_PROFILE, FormatterMessages.ProfileManager_java_conventions_profile_name, getJavaSettings(), 1, profileVersioner.getCurrentVersion(), profileVersioner.getProfileKind());
52         profiles.add(javaProfile);
53         
54         final Profile eclipseProfile= new BuiltInProfile(ECLIPSE_PROFILE, FormatterMessages.ProfileManager_eclipse_profile_name, getEclipseSettings(), 2, profileVersioner.getCurrentVersion(), profileVersioner.getProfileKind());
55         profiles.add(eclipseProfile);
56         
57         final Profile eclipse21Profile= new BuiltInProfile(ECLIPSE21_PROFILE, FormatterMessages.ProfileManager_default_profile_name, getEclipse21Settings(), 3, profileVersioner.getCurrentVersion(), profileVersioner.getProfileKind());
58         profiles.add(eclipse21Profile);
59         return profiles;
60     }
61     
62     
63     /**
64      * @return Returns the settings for the default profile.
65      */

66     public static Map JavaDoc getEclipse21Settings() {
67         final Map JavaDoc options= DefaultCodeFormatterConstants.getEclipse21Settings();
68
69         ProfileVersioner.setLatestCompliance(options);
70         return options;
71     }
72     
73     /**
74      * @return Returns the settings for the new eclipse profile.
75      */

76     public static Map JavaDoc getEclipseSettings() {
77         final Map JavaDoc options= DefaultCodeFormatterConstants.getEclipseDefaultSettings();
78
79         ProfileVersioner.setLatestCompliance(options);
80         return options;
81     }
82
83     /**
84      * @return Returns the settings for the Java Conventions profile.
85      */

86     public static Map JavaDoc getJavaSettings() {
87         final Map JavaDoc options= DefaultCodeFormatterConstants.getJavaConventionsSettings();
88
89         ProfileVersioner.setLatestCompliance(options);
90         return options;
91     }
92     
93     /**
94      * @return Returns the default settings.
95      */

96     public static Map JavaDoc getDefaultSettings() {
97         return getEclipseSettings();
98     }
99
100
101     /* (non-Javadoc)
102      * @see org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager#getSelectedProfileId(org.eclipse.core.runtime.preferences.IScopeContext)
103      */

104     protected String JavaDoc getSelectedProfileId(IScopeContext instanceScope) {
105         String JavaDoc profileId= instanceScope.getNode(JavaUI.ID_PLUGIN).get(PROFILE_KEY, null);
106         if (profileId == null) {
107             // request from bug 129427
108
profileId= new DefaultScope().getNode(JavaUI.ID_PLUGIN).get(PROFILE_KEY, null);
109             // fix for bug 89739
110
if (DEFAULT_PROFILE.equals(profileId)) { // default default:
111
IEclipsePreferences node= instanceScope.getNode(JavaCore.PLUGIN_ID);
112                 if (node != null) {
113                     String JavaDoc tabSetting= node.get(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, null);
114                     if (JavaCore.SPACE.equals(tabSetting)) {
115                         profileId= JAVA_PROFILE;
116                     }
117                 }
118             }
119         }
120         return profileId;
121     }
122
123
124     /* (non-Javadoc)
125      * @see org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager#getDefaultProfile()
126      */

127     public Profile getDefaultProfile() {
128         return getProfile(DEFAULT_PROFILE);
129     }
130     
131 }
132
Popular Tags