KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***************************************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others. All rights reserved. This program and the
3  * accompanying materials are made available under the terms of the Eclipse Public License v1.0
4  * which accompanies this distribution, and is available at
5  * http://www.eclipse.org/legal/epl-v10.html
6  *
7  * Contributors: IBM Corporation - initial API and implementation
8  **************************************************************************************************/

9 package org.eclipse.ui.intro.universal;
10
11 import org.eclipse.core.runtime.CoreException;
12 import org.eclipse.core.runtime.IConfigurationElement;
13 import org.eclipse.core.runtime.IExecutableExtension;
14 import org.eclipse.core.runtime.IExecutableExtensionFactory;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.ui.internal.intro.universal.UniversalIntroPlugin;
18 import org.eclipse.ui.internal.intro.universal.WelcomeCustomizationPreferencePage;
19
20 /**
21  * Factory for the intro's public extensions.
22  * <p>
23  * This allows the extensions to be made available for use by RCP applications without exposing
24  * their concrete implementation classes.
25  * </p>
26  * <p>
27  * Currently supported plug-in extensions:
28  * <ul>
29  * <li>welcomeCustomization - a preference page that allows user customization of the shared
30  * Welcome.</li>
31  * </ul>
32  * <p>This class should be referenced in extensions but not subclassed
33  * or instantiated programmatically.
34  *
35  * @since 3.2
36  */

37
38 public class ExtensionFactory implements IExecutableExtensionFactory, IExecutableExtension {
39
40     private String JavaDoc id;
41     private IConfigurationElement config;
42     private String JavaDoc propertyName;
43     private static final String JavaDoc WELCOME_CUSTOMIZATION_PREFERENCE_PAGE = "welcomeCustomization"; //$NON-NLS-1$
44

45     /*
46      * (non-Javadoc)
47      *
48      * @see org.eclipse.core.runtime.IExecutableExtensionFactory#create()
49      */

50     public Object JavaDoc create() throws CoreException {
51         if (WELCOME_CUSTOMIZATION_PREFERENCE_PAGE.equals(id))
52             return configure(new WelcomeCustomizationPreferencePage());
53
54         throw new CoreException(new Status(IStatus.ERROR, UniversalIntroPlugin.PLUGIN_ID, 0,
55                 "Unknown id in data argument for " + getClass(), null)); //$NON-NLS-1$
56
}
57
58     private Object JavaDoc configure(Object JavaDoc obj) throws CoreException {
59         if (obj instanceof IExecutableExtension) {
60             ((IExecutableExtension) obj).setInitializationData(config, propertyName, null);
61         }
62         return obj;
63     }
64
65     /*
66      * (non-Javadoc)
67      *
68      * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
69      * java.lang.String, java.lang.Object)
70      */

71     public void setInitializationData(IConfigurationElement config, String JavaDoc propertyName, Object JavaDoc data)
72             throws CoreException {
73         if (data instanceof String JavaDoc)
74             id = (String JavaDoc) data;
75         else
76             throw new CoreException(new Status(IStatus.ERROR, UniversalIntroPlugin.PLUGIN_ID, 0,
77                     "Data argument must be a String for " + getClass(), null)); //$NON-NLS-1$
78
this.config = config;
79         this.propertyName = propertyName;
80     }
81 }
Popular Tags