KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > ExtensionFactory


1 /*******************************************************************************
2  * Copyright (c) 2005, 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
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 /**
35  * Factory for the workbench's public extensions.
36  * <p>
37  * This allows the extensions to be made available for use by RCP applications
38  * without exposing their concrete implementation classes.
39  * </p>
40  *
41  * @since 3.1
42  */

43 public class ExtensionFactory implements IExecutableExtensionFactory,
44         IExecutableExtension {
45
46     /**
47      * Factory ID for the Appearance preference page.
48      */

49     public static final String JavaDoc APPEARANCE_PREFERENCE_PAGE = "appearancePreferencePage"; //$NON-NLS-1$
50

51     /**
52      * Factory ID for the Colors and Fonts preference page.
53      */

54     public static final String JavaDoc COLORS_AND_FONTS_PREFERENCE_PAGE = "colorsAndFontsPreferencePage"; //$NON-NLS-1$
55

56     /**
57      * Factory ID for the Decorators preference page.
58      */

59     public static final String JavaDoc DECORATORS_PREFERENCE_PAGE = "decoratorsPreferencePage"; //$NON-NLS-1$
60

61     /**
62      * Factory ID for the Editors preference page.
63      */

64     public static final String JavaDoc EDITORS_PREFERENCE_PAGE = "editorsPreferencePage"; //$NON-NLS-1$
65

66     /**
67      * Factory ID for the File Associations preference page.
68      */

69     public static final String JavaDoc FILE_ASSOCIATIONS_PREFERENCE_PAGE = "fileAssociationsPreferencePage"; //$NON-NLS-1$
70

71     /**
72      * Factory ID for the Keys preference page.
73      */

74     public static final String JavaDoc KEYS_PREFERENCE_PAGE = "keysPreferencePage"; //$NON-NLS-1$
75

76     /**
77      * Factory ID for the new (and improved) keys preference page.
78      *
79      * @since 3.2
80      */

81     public static final String JavaDoc NEW_KEYS_PREFERENCE_PAGE = "newKeysPreferencePage"; //$NON-NLS-1$
82

83     /**
84      * Factory ID for the Perspectives preference page.
85      */

86     public static final String JavaDoc PERSPECTIVES_PREFERENCE_PAGE = "perspectivesPreferencePage"; //$NON-NLS-1$
87

88     /**
89      * Factory ID for the Preferences export wizard.
90      */

91     public static final String JavaDoc PREFERENCES_EXPORT_WIZARD = "preferencesExportWizard"; //$//$NON-NLS-1$
92

93     /**
94      * Factory ID for the Preferences import wizard.
95      */

96     public static final String JavaDoc PREFERENCES_IMPORT_WIZARD = "preferencesImportWizard"; //$//$NON-NLS-1$
97

98     /**
99      * Factory ID for the Progress view.
100      */

101     public static final String JavaDoc PROGRESS_VIEW = "progressView"; //$NON-NLS-1$
102

103     /**
104      * Factory ID for the Workbench preference page.
105      */

106     public static final String JavaDoc WORKBENCH_PREFERENCE_PAGE = "workbenchPreferencePage"; //$NON-NLS-1$
107

108     /**
109      * Factory ID for the ContentTypes preference page.
110      */

111     public static final String JavaDoc CONTENT_TYPES_PREFERENCE_PAGE = "contentTypesPreferencePage"; //$NON-NLS-1$
112

113     private IConfigurationElement config;
114
115     private String JavaDoc id;
116
117     private String JavaDoc propertyName;
118
119     /**
120      * Constructs a new workbench extension factory.
121      */

122     public ExtensionFactory() {
123         // do nothing
124
}
125
126     private Object JavaDoc configure(Object JavaDoc obj) throws CoreException {
127         if (obj instanceof IExecutableExtension) {
128             ((IExecutableExtension) obj).setInitializationData(config,
129                     propertyName, null);
130         }
131         return obj;
132     }
133
134     /**
135      * Creates the object referenced by the factory id obtained from the extension data.
136      */

137     public Object JavaDoc 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)); //$NON-NLS-1$
180
}
181
182     /*
183      * (non-Javadoc)
184      *
185      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
186      * java.lang.String, java.lang.Object)
187      */

188     public void setInitializationData(IConfigurationElement config,
189             String JavaDoc propertyName, Object JavaDoc data) throws CoreException {
190         if (data instanceof String JavaDoc) {
191             id = (String JavaDoc) 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)); //$NON-NLS-1$
196
}
197         this.config = config;
198         this.propertyName = propertyName;
199     }
200 }
201
Popular Tags