1 11 package org.eclipse.jdt.internal.ui.preferences.formatter; 12 13 import java.util.ArrayList ; 14 import java.util.Collections ; 15 import java.util.List ; 16 import java.util.Map ; 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 ECLIPSE21_PROFILE= "org.eclipse.jdt.ui.default_profile"; public final static String ECLIPSE_PROFILE= "org.eclipse.jdt.ui.default.eclipse_profile"; public final static String JAVA_PROFILE= "org.eclipse.jdt.ui.default.sun_profile"; 36 public final static String DEFAULT_PROFILE= ECLIPSE_PROFILE; 37 38 private final static KeySet[] KEY_SETS= new KeySet[] { 39 new KeySet(JavaCore.PLUGIN_ID, new ArrayList (DefaultCodeFormatterConstants.getJavaConventionsSettings().keySet())), 40 new KeySet(JavaUI.ID_PLUGIN, Collections.EMPTY_LIST) 41 }; 42 43 private final static String PROFILE_KEY= PreferenceConstants.FORMATTER_PROFILE; 44 private final static String FORMATTER_SETTINGS_VERSION= "formatter_settings_version"; 46 public FormatterProfileManager(List 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 addBuiltinProfiles(List 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 66 public static Map getEclipse21Settings() { 67 final Map options= DefaultCodeFormatterConstants.getEclipse21Settings(); 68 69 ProfileVersioner.setLatestCompliance(options); 70 return options; 71 } 72 73 76 public static Map getEclipseSettings() { 77 final Map options= DefaultCodeFormatterConstants.getEclipseDefaultSettings(); 78 79 ProfileVersioner.setLatestCompliance(options); 80 return options; 81 } 82 83 86 public static Map getJavaSettings() { 87 final Map options= DefaultCodeFormatterConstants.getJavaConventionsSettings(); 88 89 ProfileVersioner.setLatestCompliance(options); 90 return options; 91 } 92 93 96 public static Map getDefaultSettings() { 97 return getEclipseSettings(); 98 } 99 100 101 104 protected String getSelectedProfileId(IScopeContext instanceScope) { 105 String profileId= instanceScope.getNode(JavaUI.ID_PLUGIN).get(PROFILE_KEY, null); 106 if (profileId == null) { 107 profileId= new DefaultScope().getNode(JavaUI.ID_PLUGIN).get(PROFILE_KEY, null); 109 if (DEFAULT_PROFILE.equals(profileId)) { IEclipsePreferences node= instanceScope.getNode(JavaCore.PLUGIN_ID); 112 if (node != null) { 113 String 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 127 public Profile getDefaultProfile() { 128 return getProfile(DEFAULT_PROFILE); 129 } 130 131 } 132 | Popular Tags |