KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > wizards > OpenTypeWizardAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.ui.wizards;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.Platform;
19
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.jface.wizard.Wizard;
22
23 import org.eclipse.jdt.internal.ui.JavaPlugin;
24 import org.eclipse.jdt.internal.ui.util.CoreUtility;
25
26 public class OpenTypeWizardAction extends AbstractOpenWizardAction {
27
28     private final static String JavaDoc ATT_NAME = "name";//$NON-NLS-1$
29
private final static String JavaDoc ATT_CLASS = "class";//$NON-NLS-1$
30
private final static String JavaDoc ATT_ICON = "icon";//$NON-NLS-1$
31
private static final String JavaDoc TAG_DESCRIPTION = "description"; //$NON-NLS-1$
32

33     private IConfigurationElement fConfigurationElement;
34
35     public OpenTypeWizardAction(IConfigurationElement element) {
36         fConfigurationElement= element;
37         setText(element.getAttribute(ATT_NAME));
38         
39         String JavaDoc description= getDescriptionFromConfig(fConfigurationElement);
40         setDescription(description);
41         setToolTipText(description);
42         setImageDescriptor(getIconFromConfig(fConfigurationElement));
43     }
44     
45     private String JavaDoc getDescriptionFromConfig(IConfigurationElement config) {
46         IConfigurationElement [] children = config.getChildren(TAG_DESCRIPTION);
47         if (children.length>=1) {
48             return children[0].getValue();
49         }
50         return ""; //$NON-NLS-1$
51
}
52
53     private ImageDescriptor getIconFromConfig(IConfigurationElement config) {
54         try {
55             String JavaDoc iconName = config.getAttribute(ATT_ICON);
56             if (iconName != null) {
57                 URL JavaDoc pluginInstallUrl = Platform.getBundle(config.getNamespace()).getEntry("/"); //$NON-NLS-1$
58
return ImageDescriptor.createFromURL(new URL JavaDoc(pluginInstallUrl, iconName));
59             }
60             return null;
61         } catch (MalformedURLException JavaDoc exception) {
62             JavaPlugin.logErrorMessage("Unable to load wizard icon"); //$NON-NLS-1$
63
}
64         return ImageDescriptor.getMissingImageDescriptor();
65         
66     }
67     
68     /* (non-Javadoc)
69      * @see org.eclipse.jdt.internal.ui.wizards.AbstractOpenWizardAction#createWizard()
70      */

71     protected Wizard createWizard() throws CoreException {
72         return (Wizard) CoreUtility.createExtension(fConfigurationElement, ATT_CLASS);
73     }
74 }
75
Popular Tags