1 11 12 package org.eclipse.ui; 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IConfigurationElement; 16 import org.eclipse.core.runtime.IExecutableExtension; 17 import org.eclipse.core.runtime.IExecutableExtensionFactory; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Status; 20 import org.eclipse.ui.internal.dialogs.ContentTypesPreferencePage; 21 import org.eclipse.ui.internal.dialogs.DecoratorsPreferencePage; 22 import org.eclipse.ui.internal.dialogs.EditorsPreferencePage; 23 import org.eclipse.ui.internal.dialogs.FileEditorsPreferencePage; 24 import org.eclipse.ui.internal.dialogs.PerspectivesPreferencePage; 25 import org.eclipse.ui.internal.dialogs.ViewsPreferencePage; 26 import org.eclipse.ui.internal.dialogs.WorkbenchPreferencePage; 27 import org.eclipse.ui.internal.keys.KeysPreferencePage; 28 import org.eclipse.ui.internal.keys.NewKeysPreferencePage; 29 import org.eclipse.ui.internal.progress.ProgressView; 30 import org.eclipse.ui.internal.themes.ColorsAndFontsPreferencePage; 31 import org.eclipse.ui.internal.wizards.preferences.PreferencesExportWizard; 32 import org.eclipse.ui.internal.wizards.preferences.PreferencesImportWizard; 33 34 43 public class ExtensionFactory implements IExecutableExtensionFactory, 44 IExecutableExtension { 45 46 49 public static final String APPEARANCE_PREFERENCE_PAGE = "appearancePreferencePage"; 51 54 public static final String COLORS_AND_FONTS_PREFERENCE_PAGE = "colorsAndFontsPreferencePage"; 56 59 public static final String DECORATORS_PREFERENCE_PAGE = "decoratorsPreferencePage"; 61 64 public static final String EDITORS_PREFERENCE_PAGE = "editorsPreferencePage"; 66 69 public static final String FILE_ASSOCIATIONS_PREFERENCE_PAGE = "fileAssociationsPreferencePage"; 71 74 public static final String KEYS_PREFERENCE_PAGE = "keysPreferencePage"; 76 81 public static final String NEW_KEYS_PREFERENCE_PAGE = "newKeysPreferencePage"; 83 86 public static final String PERSPECTIVES_PREFERENCE_PAGE = "perspectivesPreferencePage"; 88 91 public static final String PREFERENCES_EXPORT_WIZARD = "preferencesExportWizard"; 93 96 public static final String PREFERENCES_IMPORT_WIZARD = "preferencesImportWizard"; 98 101 public static final String PROGRESS_VIEW = "progressView"; 103 106 public static final String WORKBENCH_PREFERENCE_PAGE = "workbenchPreferencePage"; 108 111 public static final String CONTENT_TYPES_PREFERENCE_PAGE = "contentTypesPreferencePage"; 113 private IConfigurationElement config; 114 115 private String id; 116 117 private String propertyName; 118 119 122 public ExtensionFactory() { 123 } 125 126 private Object configure(Object obj) throws CoreException { 127 if (obj instanceof IExecutableExtension) { 128 ((IExecutableExtension) obj).setInitializationData(config, 129 propertyName, null); 130 } 131 return obj; 132 } 133 134 137 public Object create() throws CoreException { 138 if (APPEARANCE_PREFERENCE_PAGE.equals(id)) { 139 return configure(new ViewsPreferencePage()); 140 } 141 if (COLORS_AND_FONTS_PREFERENCE_PAGE.equals(id)) { 142 return configure(new ColorsAndFontsPreferencePage()); 143 } 144 if (DECORATORS_PREFERENCE_PAGE.equals(id)) { 145 return configure(new DecoratorsPreferencePage()); 146 } 147 if (EDITORS_PREFERENCE_PAGE.equals(id)) { 148 return configure(new EditorsPreferencePage()); 149 } 150 if (FILE_ASSOCIATIONS_PREFERENCE_PAGE.equals(id)) { 151 return configure(new FileEditorsPreferencePage()); 152 } 153 if (KEYS_PREFERENCE_PAGE.equals(id)) { 154 return configure(new KeysPreferencePage()); 155 } 156 if (NEW_KEYS_PREFERENCE_PAGE.equals(id)) { 157 return configure(new NewKeysPreferencePage()); 158 } 159 if (PERSPECTIVES_PREFERENCE_PAGE.equals(id)) { 160 return configure(new PerspectivesPreferencePage()); 161 } 162 if (PREFERENCES_EXPORT_WIZARD.equals(id)) { 163 return configure(new PreferencesExportWizard()); 164 } 165 if (PREFERENCES_IMPORT_WIZARD.equals(id)) { 166 return configure(new PreferencesImportWizard()); 167 } 168 if (PROGRESS_VIEW.equals(id)) { 169 return configure(new ProgressView()); 170 } 171 if (WORKBENCH_PREFERENCE_PAGE.equals(id)) { 172 return configure(new WorkbenchPreferencePage()); 173 } 174 if (CONTENT_TYPES_PREFERENCE_PAGE.equals(id)) { 175 return configure(new ContentTypesPreferencePage()); 176 } 177 178 throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 179 0, "Unknown id in data argument for " + getClass(), null)); } 181 182 188 public void setInitializationData(IConfigurationElement config, 189 String propertyName, Object data) throws CoreException { 190 if (data instanceof String ) { 191 id = (String ) data; 192 } else { 193 throw new CoreException(new Status(IStatus.ERROR, 194 PlatformUI.PLUGIN_ID, 0, 195 "Data argument must be a String for " + getClass(), null)); } 197 this.config = config; 198 this.propertyName = propertyName; 199 } 200 } 201 | Popular Tags |