KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > cheatsheets > CheatSheetExtensionFactory


1 /*******************************************************************************
2  * Copyright (c) 2005 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 package org.eclipse.ui.cheatsheets;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.core.runtime.IExecutableExtension;
16 import org.eclipse.core.runtime.IExecutableExtensionFactory;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.internal.cheatsheets.actions.CheatSheetHelpMenuAction;
21
22 /**
23  * Factory for the cheat sheet's public extensions.
24  * <p>
25  * This allows the extensions to be made available for use by RCP applications
26  * without exposing their concrete implementation classes.
27  * </p>
28  *
29  * @since 3.1
30  */

31
32 public class CheatSheetExtensionFactory implements IExecutableExtensionFactory,
33         IExecutableExtension {
34     /**
35      * Factory ID for the Help menu cheat sheet action.
36      */

37     public static final String JavaDoc HELP_MENU_ACTION = "helpMenuAction"; //$NON-NLS-1$
38

39     private IConfigurationElement config;
40
41     private String JavaDoc id;
42
43     private String JavaDoc propertyName;
44
45     /**
46      * The default constructor.
47      */

48     public CheatSheetExtensionFactory() {
49         // do nothing
50
}
51
52     /*
53      * (non-Javadoc)
54      *
55      * @see org.eclipse.core.runtime.IExecutableExtensionFactory#create()
56      */

57     public Object JavaDoc create() throws CoreException {
58         if (HELP_MENU_ACTION.equals(id))
59             return configure(new CheatSheetHelpMenuAction());
60         throw new CoreException(new Status(IStatus.ERROR,
61                 "org.eclipse.ui.cheatsheets", //$NON-NLS-1$
62
0, "Unknown id in data argument for " + getClass(), null)); //$NON-NLS-1$
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,
72             String JavaDoc propertyName, Object JavaDoc data) throws CoreException {
73         if (data instanceof String JavaDoc)
74             id = (String JavaDoc) data;
75         else
76             throw new CoreException(new Status(IStatus.ERROR,
77                     PlatformUI.PLUGIN_ID, 0,
78                     "Data argument must be a String for " + getClass(), null)); //$NON-NLS-1$
79
this.config = config;
80         this.propertyName = propertyName;
81     }
82
83     private Object JavaDoc configure(Object JavaDoc obj) throws CoreException {
84         if (obj instanceof IExecutableExtension) {
85             ((IExecutableExtension) obj).setInitializationData(config,
86                     propertyName, null);
87         }
88         return obj;
89     }
90 }
Popular Tags