KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > templates > ide > HelloWorldTemplate


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.pde.internal.ui.templates.ide;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.jface.wizard.Wizard;
16 import org.eclipse.jface.wizard.WizardPage;
17 import org.eclipse.pde.core.plugin.IPluginBase;
18 import org.eclipse.pde.core.plugin.IPluginElement;
19 import org.eclipse.pde.core.plugin.IPluginExtension;
20 import org.eclipse.pde.core.plugin.IPluginModelBase;
21 import org.eclipse.pde.core.plugin.IPluginModelFactory;
22 import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
23 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
24 import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
25 import org.eclipse.pde.ui.IFieldData;
26
27 public class HelloWorldTemplate extends PDETemplateSection {
28     public static final String JavaDoc KEY_CLASS_NAME = "className"; //$NON-NLS-1$
29
public static final String JavaDoc KEY_MESSAGE = "message"; //$NON-NLS-1$
30
public static final String JavaDoc CLASS_NAME = "SampleAction"; //$NON-NLS-1$
31

32     /**
33      * Constructor for HelloWorldTemplate.
34      */

35     public HelloWorldTemplate() {
36         setPageCount(1);
37         createOptions();
38     }
39
40     public String JavaDoc getSectionId() {
41         return "helloWorld"; //$NON-NLS-1$
42
}
43     /*
44      * @see ITemplateSection#getNumberOfWorkUnits()
45      */

46     public int getNumberOfWorkUnits() {
47         return super.getNumberOfWorkUnits() + 1;
48     }
49     
50     private void createOptions() {
51         addOption(
52             KEY_PACKAGE_NAME,
53             PDETemplateMessages.HelloWorldTemplate_packageName,
54             (String JavaDoc) null,
55             0);
56         addOption(
57             KEY_CLASS_NAME,
58             PDETemplateMessages.HelloWorldTemplate_className,
59             CLASS_NAME,
60             0);
61         addOption(
62             KEY_MESSAGE,
63             PDETemplateMessages.HelloWorldTemplate_messageText,
64             PDETemplateMessages.HelloWorldTemplate_defaultMessage,
65             0);
66     }
67
68     public void addPages(Wizard wizard) {
69         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_HELLO_WORLD);
70         page.setTitle(PDETemplateMessages.HelloWorldTemplate_title);
71         page.setDescription(PDETemplateMessages.HelloWorldTemplate_desc);
72         wizard.addPage(page);
73         markPagesAdded();
74     }
75
76     public boolean isDependentOnParentWizard() {
77         return true;
78     }
79
80     protected void initializeFields(IFieldData data) {
81         // In a new project wizard, we don't know this yet - the
82
// model has not been created
83
String JavaDoc id = data.getId();
84         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
85     }
86     public void initializeFields(IPluginModelBase model) {
87         // In the new extension wizard, the model exists so
88
// we can initialize directly from it
89
String JavaDoc pluginId = model.getPluginBase().getId();
90         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId));
91     }
92
93     public String JavaDoc getUsedExtensionPoint() {
94         return "org.eclipse.ui.actionSets"; //$NON-NLS-1$
95
}
96
97     protected void updateModel(IProgressMonitor monitor) throws CoreException {
98         IPluginBase plugin = model.getPluginBase();
99         IPluginExtension extension = createExtension("org.eclipse.ui.actionSets", true); //$NON-NLS-1$
100
IPluginModelFactory factory = model.getPluginFactory();
101
102         IPluginElement setElement = factory.createElement(extension);
103         setElement.setName("actionSet"); //$NON-NLS-1$
104
setElement.setAttribute("id", plugin.getId() + ".actionSet"); //$NON-NLS-1$ //$NON-NLS-2$
105
setElement.setAttribute("label", PDETemplateMessages.HelloWorldTemplate_sampleActionSet); //$NON-NLS-1$
106
setElement.setAttribute("visible", "true"); //$NON-NLS-1$ //$NON-NLS-2$
107

108         IPluginElement menuElement = factory.createElement(setElement);
109         menuElement.setName("menu"); //$NON-NLS-1$
110
menuElement.setAttribute("label", PDETemplateMessages.HelloWorldTemplate_sampleMenu); //$NON-NLS-1$
111
menuElement.setAttribute("id", "sampleMenu"); //$NON-NLS-1$ //$NON-NLS-2$
112

113         IPluginElement groupElement = factory.createElement(menuElement);
114         groupElement.setName("separator"); //$NON-NLS-1$
115
groupElement.setAttribute("name", "sampleGroup"); //$NON-NLS-1$ //$NON-NLS-2$
116
menuElement.add(groupElement);
117         setElement.add(menuElement);
118
119         String JavaDoc fullClassName =
120             getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_CLASS_NAME); //$NON-NLS-1$
121

122         IPluginElement actionElement = factory.createElement(setElement);
123         actionElement.setName("action"); //$NON-NLS-1$
124
actionElement.setAttribute("id", fullClassName); //$NON-NLS-1$
125
actionElement.setAttribute("label", PDETemplateMessages.HelloWorldTemplate_sampleAction); //$NON-NLS-1$
126
actionElement.setAttribute("menubarPath", "sampleMenu/sampleGroup"); //$NON-NLS-1$ //$NON-NLS-2$
127
actionElement.setAttribute("toolbarPath", "sampleGroup"); //$NON-NLS-1$ //$NON-NLS-2$
128
actionElement.setAttribute("icon", "icons/sample.gif"); //$NON-NLS-1$ //$NON-NLS-2$
129
actionElement.setAttribute("tooltip", PDETemplateMessages.HelloWorldTemplate_defaultMessage); //$NON-NLS-1$
130
actionElement.setAttribute("class", fullClassName); //$NON-NLS-1$
131
setElement.add(actionElement);
132         extension.add(setElement);
133         if (!extension.isInTheModel())
134             plugin.add(extension);
135     }
136     
137     /* (non-Javadoc)
138      * @see org.eclipse.pde.ui.templates.ITemplateSection#getFoldersToInclude()
139      */

140     public String JavaDoc[] getNewFiles() {
141         return new String JavaDoc[] {"icons/"}; //$NON-NLS-1$
142
}
143     
144     /* (non-Javadoc)
145      * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#formatPackageName(java.lang.String)
146      */

147     protected String JavaDoc getFormattedPackageName(String JavaDoc id) {
148         String JavaDoc packageName = super.getFormattedPackageName(id);
149         if (packageName.length() != 0)
150             return packageName + ".actions"; //$NON-NLS-1$
151
return "actions"; //$NON-NLS-1$
152
}
153 }
154
Popular Tags