KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > templates > IntroTemplate


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
12 package org.eclipse.pde.internal.ui.wizards.templates;
13
14 import java.io.File JavaDoc;
15 import java.util.ArrayList JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.wizard.Wizard;
20 import org.eclipse.jface.wizard.WizardPage;
21 import org.eclipse.pde.core.plugin.IPluginBase;
22 import org.eclipse.pde.core.plugin.IPluginElement;
23 import org.eclipse.pde.core.plugin.IPluginExtension;
24 import org.eclipse.pde.core.plugin.IPluginModelBase;
25 import org.eclipse.pde.core.plugin.IPluginModelFactory;
26 import org.eclipse.pde.core.plugin.IPluginReference;
27 import org.eclipse.pde.internal.core.plugin.PluginBase;
28 import org.eclipse.pde.internal.ui.IHelpContextIds;
29 import org.eclipse.pde.internal.ui.PDEUIMessages;
30 import org.eclipse.pde.ui.IFieldData;
31 import org.eclipse.pde.ui.templates.TemplateOption;
32
33 public class IntroTemplate extends PDETemplateSection {
34     
35     private static final String JavaDoc DYNAMIC_SELECTED = "dynamic"; //$NON-NLS-1$
36

37     private static final String JavaDoc STATIC_SELECTED = "static"; //$NON-NLS-1$
38

39     private static final String JavaDoc KEY_PRODUCT_ID = "IntroTemplate.productID"; //$NON-NLS-1$
40

41     private static final String JavaDoc KEY_PRODUCT_NAME = "productName"; //$NON-NLS-1$
42

43     private static final String JavaDoc KEY_APPLICATION_ID = "IntroTemplate.application"; //$NON-NLS-1$
44

45     private static final String JavaDoc KEY_GENERATE_DYNAMIC_CONTENT = "IntroTemplate.generateDynamicContent"; //$NON-NLS-1$
46

47     public static final String JavaDoc CLASS_NAME = "SampleXHTMLContentProvider"; //$NON-NLS-1$
48

49     public static final String JavaDoc KEY_PERSPECTIVE_NAME = "perspectiveName"; //$NON-NLS-1$
50

51     private String JavaDoc packageName;
52     private String JavaDoc introID;
53     private String JavaDoc perspectiveName;
54     private static final String JavaDoc APPLICATION_CLASS = "Application"; //$NON-NLS-1$
55

56     public IntroTemplate() {
57         super();
58         setPageCount(1);
59         createOptions();
60     }
61
62     private void createOptions() {
63
64         // product options
65
addOption(KEY_PRODUCT_ID, PDEUIMessages.IntroTemplate_productID,
66                 "product", 0); //$NON-NLS-1$
67
addOption(KEY_PRODUCT_NAME, PDEUIMessages.IntroTemplate_productName,
68                 "My New Product", 0); //$NON-NLS-1$
69
addOption(KEY_APPLICATION_ID, PDEUIMessages.IntroTemplate_application,
70                 "application", 0); //$NON-NLS-1$
71

72         addOption( KEY_GENERATE_DYNAMIC_CONTENT,
73                 PDEUIMessages.IntroTemplate_generate,
74                 new String JavaDoc[][] { {STATIC_SELECTED, PDEUIMessages.IntroTemplate_generateStaticContent},
75                                  {DYNAMIC_SELECTED, PDEUIMessages.IntroTemplate_generateDynamicContent}},
76                 STATIC_SELECTED, 0);
77     }
78     
79     public void addPages(Wizard wizard) {
80         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_INTRO);
81         page.setTitle(PDEUIMessages.IntroTemplate_title);
82         page.setDescription(PDEUIMessages.IntroTemplate_desc);
83         wizard.addPage(page);
84         markPagesAdded();
85     }
86
87     public boolean isDependentOnParentWizard() {
88         return true;
89     }
90
91     public String JavaDoc getSectionId() {
92         return "intro"; //$NON-NLS-1$
93
}
94     
95     protected void initializeFields(IFieldData data) {
96         // In a new project wizard, we don't know this yet - the
97
// model has not been created
98
String JavaDoc pluginId = data.getId();
99         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId) + ".intro"); //$NON-NLS-1$
100
initializeOption(KEY_APPLICATION_ID, getFormattedPackageName(pluginId) + ".application"); //$NON-NLS-1$
101
initializeOption(KEY_PERSPECTIVE_NAME, getFormattedPackageName(pluginId) + " Perspective"); //$NON-NLS-1$
102
perspectiveName = getFormattedPackageName(pluginId) + ".perspective"; //$NON-NLS-1$
103
packageName = getFormattedPackageName(pluginId) + ".intro"; //$NON-NLS-1$
104
introID = getFormattedPackageName(pluginId) + ".intro"; //$NON-NLS-1$
105
}
106     public void initializeFields(IPluginModelBase model) {
107         // In the new extension wizard, the model exists so
108
// we can initialize directly from it
109
String JavaDoc pluginId = model.getPluginBase().getId();
110         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId) + ".intro"); //$NON-NLS-1$
111
initializeOption(KEY_APPLICATION_ID, getFormattedPackageName(pluginId) + ".application"); //$NON-NLS-1$
112
initializeOption(KEY_PERSPECTIVE_NAME, getFormattedPackageName(pluginId) + " Perspective"); //$NON-NLS-1$
113
perspectiveName = getFormattedPackageName(pluginId) + ".perspective"; //$NON-NLS-1$
114
packageName = getFormattedPackageName(pluginId) + ".intro"; //$NON-NLS-1$
115
introID = getFormattedPackageName(pluginId) + ".intro"; //$NON-NLS-1$
116
}
117
118     public void validateOptions(TemplateOption source) {
119         
120         if (source.isRequired() && source.isEmpty()) {
121             flagMissingRequiredOption(source);
122         } else {
123             validateContainerPage(source);
124         }
125     }
126
127     private void validateContainerPage(TemplateOption source) {
128         TemplateOption[] allPageOptions = getOptions(0);
129         for (int i = 0; i < allPageOptions.length; i++) {
130             TemplateOption nextOption = allPageOptions[i];
131             if (nextOption.isRequired() && nextOption.isEmpty()) {
132                     flagMissingRequiredOption(nextOption);
133                     return;
134             }
135         }
136         resetPageState();
137     }
138
139     protected void updateModel(IProgressMonitor monitor) throws CoreException {
140
141         IPluginBase plugin = model.getPluginBase();
142         IPluginModelFactory factory = model.getPluginFactory();
143                 
144         // org.eclipse.core.runtime.applications
145
IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
146
extension.setId(getStringOption(KEY_APPLICATION_ID));
147         
148         IPluginElement element = model.getPluginFactory().createElement(extension);
149         element.setName("application"); //$NON-NLS-1$
150
extension.add(element);
151         
152         IPluginElement run = model.getPluginFactory().createElement(element);
153         run.setName("run"); //$NON-NLS-1$
154
run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + APPLICATION_CLASS); //$NON-NLS-1$ //$NON-NLS-2$
155
element.add(run);
156         
157         if (!extension.isInTheModel())
158             plugin.add(extension);
159         
160         
161         // org.eclipse.ui.perspectives
162
IPluginExtension perspectivesExtension = createExtension("org.eclipse.ui.perspectives", true); //$NON-NLS-1$
163
IPluginElement perspectiveElement = model.getPluginFactory().createElement(perspectivesExtension);
164         perspectiveElement.setName("perspective"); //$NON-NLS-1$
165
perspectiveElement.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
166
perspectiveElement.setAttribute("name", getStringOption(KEY_PERSPECTIVE_NAME)); //$NON-NLS-1$
167
perspectiveElement.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$
168
perspectivesExtension.add(perspectiveElement);
169         
170         if (!perspectivesExtension.isInTheModel())
171             plugin.add(perspectivesExtension);
172
173
174         // org.eclipse.core.runtime.products
175
IPluginExtension extension1 = createExtension(
176                 "org.eclipse.core.runtime.products", true); //$NON-NLS-1$
177
extension1.setId(getStringOption(KEY_PRODUCT_ID));
178         //extension1.setName("org.eclipse.core.runtime.products"); //$NON-NLS-1$
179

180         IPluginElement productElement = factory.createElement(extension1);
181         productElement.setName("product"); //$NON-NLS-1$
182
productElement.setAttribute("name", getStringOption(KEY_PRODUCT_NAME)); //$NON-NLS-1$
183
productElement.setAttribute(
184                 "application", plugin.getId() + "." + getStringOption(KEY_APPLICATION_ID)); //$NON-NLS-1$ //$NON-NLS-2$
185
extension1.add(productElement);
186
187         if (!extension1.isInTheModel())
188             plugin.add(extension1);
189
190         // org.eclipse.ui.intro
191
IPluginExtension extension2 = createExtension(
192                 "org.eclipse.ui.intro", true); //$NON-NLS-1$
193

194         IPluginElement introElement = factory.createElement(extension2);
195         introElement.setName("intro"); //$NON-NLS-1$
196
introElement.setAttribute("id", introID); //$NON-NLS-1$
197
introElement.setAttribute("class", //$NON-NLS-1$
198
"org.eclipse.ui.intro.config.CustomizableIntroPart"); //$NON-NLS-1$
199
extension2.add(introElement);
200
201         IPluginElement introProductBindingElement = factory
202                 .createElement(extension2);
203         introProductBindingElement.setName("introProductBinding"); //$NON-NLS-1$
204
introProductBindingElement.setAttribute("introId", introID);//$NON-NLS-1$
205

206         introProductBindingElement.setAttribute("productId", plugin.getId() //$NON-NLS-1$
207
+ '.' + getStringOption(KEY_PRODUCT_ID));
208         extension2.add(introProductBindingElement);
209
210         if (!extension2.isInTheModel())
211             plugin.add(extension2);
212
213         // org.eclipse.ui.intro.config
214
IPluginExtension extension3 = createExtension(
215                 "org.eclipse.ui.intro.config", true); //$NON-NLS-1$
216

217         IPluginElement configurationElement = factory.createElement(extension3);
218         configurationElement.setName("config"); //$NON-NLS-1$
219
configurationElement.setAttribute("id", plugin.getId() + '.' //$NON-NLS-1$
220
+ "configId"); //$NON-NLS-1$
221
configurationElement.setAttribute("introId", introID);//$NON-NLS-1$
222
configurationElement.setAttribute("content", "introContent.xml"); //$NON-NLS-1$ //$NON-NLS-2$
223
IPluginElement presentationElement = factory
224                 .createElement(configurationElement);
225         presentationElement.setName("presentation"); //$NON-NLS-1$
226
presentationElement.setAttribute("home-page-id", "root"); //$NON-NLS-1$ //$NON-NLS-2$
227
IPluginElement implementationElement = factory
228                 .createElement(presentationElement);
229         implementationElement.setName("implementation"); //$NON-NLS-1$
230
implementationElement.setAttribute("os", "win32,linux,macosx"); //$NON-NLS-1$ //$NON-NLS-2$
231
if ( ((PluginBase)plugin).getTargetVersion().equals("3.0")) { //$NON-NLS-1$
232
implementationElement.setAttribute("style", "content/shared.css"); //$NON-NLS-1$//$NON-NLS-2$
233
}
234         implementationElement.setAttribute("kind", "html"); //$NON-NLS-1$ //$NON-NLS-2$
235
presentationElement.add(implementationElement);
236         configurationElement.add(presentationElement);
237         extension3.add(configurationElement);
238
239         if (!extension3.isInTheModel())
240             plugin.add(extension3);
241         
242         // org.eclipse.ui.intro.configExtension
243
if (getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(DYNAMIC_SELECTED)) {
244             IPluginExtension extension4 = createExtension(
245                 "org.eclipse.ui.intro.configExtension", true); //$NON-NLS-1$
246

247             IPluginElement configExtensionElement = factory.createElement(extension4);
248             configExtensionElement.setName("configExtension"); //$NON-NLS-1$
249
configExtensionElement.setAttribute("configId", plugin.getId() + '.' + "configId"); //$NON-NLS-1$ //$NON-NLS-2$
250
configExtensionElement.setAttribute("content", "ext.xml"); //$NON-NLS-1$ //$NON-NLS-2$
251
extension4.add(configExtensionElement);
252
253             if (!extension4.isInTheModel())
254                 plugin.add(extension4);
255         }
256
257
258     }
259
260     protected boolean isOkToCreateFolder(File JavaDoc sourceFolder) {
261         return true;
262     }
263
264     /**
265      * @see AbstractTemplateSection#isOkToCreateFile(File)
266      */

267     protected boolean isOkToCreateFile(File JavaDoc sourceFile) {
268
269         if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(STATIC_SELECTED) &&
270                 (sourceFile.getName().equals("DynamicContentProvider.java") || //$NON-NLS-1$
271
sourceFile.getName().equals("concept3.xhtml") || //$NON-NLS-1$
272
sourceFile.getName().equals("extContent.xhtml") || //$NON-NLS-1$
273
sourceFile.getName().equals("ext.xml") ) ) { //$NON-NLS-1$
274
return false;
275         }
276         
277         return true;
278     }
279
280     public String JavaDoc getUsedExtensionPoint() {
281         return "org.eclipse.ui.intro"; // need more then one extension point //$NON-NLS-1$
282
}
283
284     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
285         ArrayList JavaDoc result = new ArrayList JavaDoc();
286
287         result.add(new PluginReference("org.eclipse.ui.intro", null, 0)); //$NON-NLS-1$
288
result.add(new PluginReference("org.eclipse.core.runtime", null, 0)); //$NON-NLS-1$
289
result.add(new PluginReference("org.eclipse.ui", null, 0)); //$NON-NLS-1$
290

291         if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(DYNAMIC_SELECTED)) {
292             result.add(new PluginReference("org.eclipse.ui.forms", null, 0)); //$NON-NLS-1$
293
result.add(new PluginReference("org.eclipse.swt", null, 0)); //$NON-NLS-1$
294
}
295
296         return (IPluginReference[]) result.toArray(new IPluginReference[result
297                 .size()]);
298     }
299
300     public int getNumberOfWorkUnits() {
301         return super.getNumberOfWorkUnits() + 1;
302     }
303     
304     public Object JavaDoc getValue(String JavaDoc valueName) {
305         
306         if (valueName.equals(KEY_PACKAGE_NAME)) {
307             return packageName;
308         }
309         
310         return super.getValue(valueName);
311     }
312     
313     public String JavaDoc getStringOption(String JavaDoc name) {
314         
315         if (name.equals(KEY_PERSPECTIVE_NAME)) {
316             return perspectiveName;
317         } else if ( name.equals(KEY_PACKAGE_NAME)) {
318             return packageName;
319         }
320         
321         return super.getStringOption(name);
322     }
323
324     public String JavaDoc[] getNewFiles() {
325         
326        if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(STATIC_SELECTED)) {
327            return new String JavaDoc[] {"content/", "splash.bmp", "introContent.xml"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
328
}
329            
330        return new String JavaDoc[] {"content/", "splash.bmp", "introContent.xml", "ext.xml"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
331

332     }
333 }
334
Popular Tags