001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IConfigurationElement;
014: import org.eclipse.core.runtime.IExecutableExtension;
015: import org.eclipse.core.runtime.IExecutableExtensionFactory;
016: import org.eclipse.core.runtime.IStatus;
017: import org.eclipse.core.runtime.Status;
018: import org.eclipse.ui.internal.dialogs.ContentTypesPreferencePage;
019: import org.eclipse.ui.internal.dialogs.DecoratorsPreferencePage;
020: import org.eclipse.ui.internal.dialogs.EditorsPreferencePage;
021: import org.eclipse.ui.internal.dialogs.FileEditorsPreferencePage;
022: import org.eclipse.ui.internal.dialogs.PerspectivesPreferencePage;
023: import org.eclipse.ui.internal.dialogs.ViewsPreferencePage;
024: import org.eclipse.ui.internal.dialogs.WorkbenchPreferencePage;
025: import org.eclipse.ui.internal.keys.KeysPreferencePage;
026: import org.eclipse.ui.internal.keys.NewKeysPreferencePage;
027: import org.eclipse.ui.internal.progress.ProgressView;
028: import org.eclipse.ui.internal.themes.ColorsAndFontsPreferencePage;
029: import org.eclipse.ui.internal.wizards.preferences.PreferencesExportWizard;
030: import org.eclipse.ui.internal.wizards.preferences.PreferencesImportWizard;
031:
032: /**
033: * Factory for the workbench's public extensions.
034: * <p>
035: * This allows the extensions to be made available for use by RCP applications
036: * without exposing their concrete implementation classes.
037: * </p>
038: *
039: * @since 3.1
040: */
041: public class ExtensionFactory implements IExecutableExtensionFactory,
042: IExecutableExtension {
043:
044: /**
045: * Factory ID for the Appearance preference page.
046: */
047: public static final String APPEARANCE_PREFERENCE_PAGE = "appearancePreferencePage"; //$NON-NLS-1$
048:
049: /**
050: * Factory ID for the Colors and Fonts preference page.
051: */
052: public static final String COLORS_AND_FONTS_PREFERENCE_PAGE = "colorsAndFontsPreferencePage"; //$NON-NLS-1$
053:
054: /**
055: * Factory ID for the Decorators preference page.
056: */
057: public static final String DECORATORS_PREFERENCE_PAGE = "decoratorsPreferencePage"; //$NON-NLS-1$
058:
059: /**
060: * Factory ID for the Editors preference page.
061: */
062: public static final String EDITORS_PREFERENCE_PAGE = "editorsPreferencePage"; //$NON-NLS-1$
063:
064: /**
065: * Factory ID for the File Associations preference page.
066: */
067: public static final String FILE_ASSOCIATIONS_PREFERENCE_PAGE = "fileAssociationsPreferencePage"; //$NON-NLS-1$
068:
069: /**
070: * Factory ID for the Keys preference page.
071: */
072: public static final String KEYS_PREFERENCE_PAGE = "keysPreferencePage"; //$NON-NLS-1$
073:
074: /**
075: * Factory ID for the new (and improved) keys preference page.
076: *
077: * @since 3.2
078: */
079: public static final String NEW_KEYS_PREFERENCE_PAGE = "newKeysPreferencePage"; //$NON-NLS-1$
080:
081: /**
082: * Factory ID for the Perspectives preference page.
083: */
084: public static final String PERSPECTIVES_PREFERENCE_PAGE = "perspectivesPreferencePage"; //$NON-NLS-1$
085:
086: /**
087: * Factory ID for the Preferences export wizard.
088: */
089: public static final String PREFERENCES_EXPORT_WIZARD = "preferencesExportWizard"; //$//$NON-NLS-1$
090:
091: /**
092: * Factory ID for the Preferences import wizard.
093: */
094: public static final String PREFERENCES_IMPORT_WIZARD = "preferencesImportWizard"; //$//$NON-NLS-1$
095:
096: /**
097: * Factory ID for the Progress view.
098: */
099: public static final String PROGRESS_VIEW = "progressView"; //$NON-NLS-1$
100:
101: /**
102: * Factory ID for the Workbench preference page.
103: */
104: public static final String WORKBENCH_PREFERENCE_PAGE = "workbenchPreferencePage"; //$NON-NLS-1$
105:
106: /**
107: * Factory ID for the ContentTypes preference page.
108: */
109: public static final String CONTENT_TYPES_PREFERENCE_PAGE = "contentTypesPreferencePage"; //$NON-NLS-1$
110:
111: private IConfigurationElement config;
112:
113: private String id;
114:
115: private String propertyName;
116:
117: /**
118: * Constructs a new workbench extension factory.
119: */
120: public ExtensionFactory() {
121: // do nothing
122: }
123:
124: private Object configure(Object obj) throws CoreException {
125: if (obj instanceof IExecutableExtension) {
126: ((IExecutableExtension) obj).setInitializationData(config,
127: propertyName, null);
128: }
129: return obj;
130: }
131:
132: /**
133: * Creates the object referenced by the factory id obtained from the extension data.
134: */
135: public Object create() throws CoreException {
136: if (APPEARANCE_PREFERENCE_PAGE.equals(id)) {
137: return configure(new ViewsPreferencePage());
138: }
139: if (COLORS_AND_FONTS_PREFERENCE_PAGE.equals(id)) {
140: return configure(new ColorsAndFontsPreferencePage());
141: }
142: if (DECORATORS_PREFERENCE_PAGE.equals(id)) {
143: return configure(new DecoratorsPreferencePage());
144: }
145: if (EDITORS_PREFERENCE_PAGE.equals(id)) {
146: return configure(new EditorsPreferencePage());
147: }
148: if (FILE_ASSOCIATIONS_PREFERENCE_PAGE.equals(id)) {
149: return configure(new FileEditorsPreferencePage());
150: }
151: if (KEYS_PREFERENCE_PAGE.equals(id)) {
152: return configure(new KeysPreferencePage());
153: }
154: if (NEW_KEYS_PREFERENCE_PAGE.equals(id)) {
155: return configure(new NewKeysPreferencePage());
156: }
157: if (PERSPECTIVES_PREFERENCE_PAGE.equals(id)) {
158: return configure(new PerspectivesPreferencePage());
159: }
160: if (PREFERENCES_EXPORT_WIZARD.equals(id)) {
161: return configure(new PreferencesExportWizard());
162: }
163: if (PREFERENCES_IMPORT_WIZARD.equals(id)) {
164: return configure(new PreferencesImportWizard());
165: }
166: if (PROGRESS_VIEW.equals(id)) {
167: return configure(new ProgressView());
168: }
169: if (WORKBENCH_PREFERENCE_PAGE.equals(id)) {
170: return configure(new WorkbenchPreferencePage());
171: }
172: if (CONTENT_TYPES_PREFERENCE_PAGE.equals(id)) {
173: return configure(new ContentTypesPreferencePage());
174: }
175:
176: throw new CoreException(new Status(IStatus.ERROR,
177: PlatformUI.PLUGIN_ID, 0,
178: "Unknown id in data argument for " + getClass(), null)); //$NON-NLS-1$
179: }
180:
181: /*
182: * (non-Javadoc)
183: *
184: * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
185: * java.lang.String, java.lang.Object)
186: */
187: public void setInitializationData(IConfigurationElement config,
188: String propertyName, Object data) throws CoreException {
189: if (data instanceof String) {
190: id = (String) data;
191: } else {
192: throw new CoreException(
193: new Status(
194: IStatus.ERROR,
195: PlatformUI.PLUGIN_ID,
196: 0,
197: "Data argument must be a String for " + getClass(), null)); //$NON-NLS-1$
198: }
199: this.config = config;
200: this.propertyName = propertyName;
201: }
202: }
|