KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.templates.rcp;
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.ui.templates.IHelpContextIds;
28 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
29 import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
30 import org.eclipse.pde.internal.ui.templates.PluginReference;
31 import org.eclipse.pde.ui.IFieldData;
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_GENERATE_DYNAMIC_CONTENT = "IntroTemplate.generateDynamicContent"; //$NON-NLS-1$
40

41     private String JavaDoc packageName;
42     private String JavaDoc introID;
43     private static final String JavaDoc APPLICATION_CLASS = "Application"; //$NON-NLS-1$
44

45     public IntroTemplate() {
46         super();
47         setPageCount(1);
48         createOptions();
49     }
50
51     private void createOptions() {
52
53         addOption(KEY_PRODUCT_NAME, PDETemplateMessages.IntroTemplate_productName,
54                 VALUE_PRODUCT_NAME, 0);
55         
56         addOption( KEY_GENERATE_DYNAMIC_CONTENT,
57                 PDETemplateMessages.IntroTemplate_generate,
58                 new String JavaDoc[][] { {STATIC_SELECTED, PDETemplateMessages.IntroTemplate_generateStaticContent},
59                                  {DYNAMIC_SELECTED, PDETemplateMessages.IntroTemplate_generateDynamicContent}},
60                 STATIC_SELECTED, 0);
61     }
62     
63     public void addPages(Wizard wizard) {
64         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_INTRO);
65         page.setTitle(PDETemplateMessages.IntroTemplate_title);
66         page.setDescription(PDETemplateMessages.IntroTemplate_desc);
67         wizard.addPage(page);
68         markPagesAdded();
69     }
70
71     public boolean isDependentOnParentWizard() {
72         return true;
73     }
74
75     public String JavaDoc getSectionId() {
76         return "intro"; //$NON-NLS-1$
77
}
78     
79     protected void initializeFields(IFieldData data) {
80         // In a new project wizard, we don't know this yet - the
81
// model has not been created
82
String JavaDoc pluginId = data.getId();
83         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId) + ".intro"); //$NON-NLS-1$
84
packageName = getFormattedPackageName(pluginId) + ".intro"; //$NON-NLS-1$
85
introID = getFormattedPackageName(pluginId) + ".intro"; //$NON-NLS-1$
86
}
87     public void initializeFields(IPluginModelBase model) {
88         // In the new extension wizard, the model exists so
89
// we can initialize directly from it
90
String JavaDoc pluginId = model.getPluginBase().getId();
91         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId) + ".intro"); //$NON-NLS-1$
92
packageName = getFormattedPackageName(pluginId) + ".intro"; //$NON-NLS-1$
93
introID = getFormattedPackageName(pluginId) + ".intro"; //$NON-NLS-1$
94
}
95
96     protected void updateModel(IProgressMonitor monitor) throws CoreException {
97
98         IPluginBase plugin = model.getPluginBase();
99         IPluginModelFactory factory = model.getPluginFactory();
100                 
101         // org.eclipse.core.runtime.applications
102
IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
103
extension.setId(VALUE_APPLICATION_ID);
104         
105         IPluginElement element = model.getPluginFactory().createElement(extension);
106         element.setName("application"); //$NON-NLS-1$
107
extension.add(element);
108         
109         IPluginElement run = model.getPluginFactory().createElement(element);
110         run.setName("run"); //$NON-NLS-1$
111
run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + APPLICATION_CLASS); //$NON-NLS-1$ //$NON-NLS-2$
112
element.add(run);
113         
114         if (!extension.isInTheModel())
115             plugin.add(extension);
116         
117         
118         // org.eclipse.ui.perspectives
119
IPluginExtension perspectivesExtension = createExtension("org.eclipse.ui.perspectives", true); //$NON-NLS-1$
120
IPluginElement perspectiveElement = model.getPluginFactory().createElement(perspectivesExtension);
121         perspectiveElement.setName("perspective"); //$NON-NLS-1$
122
perspectiveElement.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
123
perspectiveElement.setAttribute("name", VALUE_PERSPECTIVE_NAME); //$NON-NLS-1$
124
perspectiveElement.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$
125
perspectivesExtension.add(perspectiveElement);
126         
127         if (!perspectivesExtension.isInTheModel())
128             plugin.add(perspectivesExtension);
129
130         createProductExtension();
131         
132         // org.eclipse.ui.intro
133
IPluginExtension extension2 = createExtension(
134                 "org.eclipse.ui.intro", true); //$NON-NLS-1$
135

136         IPluginElement introElement = factory.createElement(extension2);
137         introElement.setName("intro"); //$NON-NLS-1$
138
introElement.setAttribute("id", introID); //$NON-NLS-1$
139
introElement.setAttribute("class", //$NON-NLS-1$
140
"org.eclipse.ui.intro.config.CustomizableIntroPart"); //$NON-NLS-1$
141
extension2.add(introElement);
142
143         IPluginElement introProductBindingElement = factory
144                 .createElement(extension2);
145         introProductBindingElement.setName("introProductBinding"); //$NON-NLS-1$
146
introProductBindingElement.setAttribute("introId", introID);//$NON-NLS-1$
147

148         introProductBindingElement.setAttribute("productId", plugin.getId() //$NON-NLS-1$
149
+ '.' + VALUE_PRODUCT_ID);
150         extension2.add(introProductBindingElement);
151
152         if (!extension2.isInTheModel())
153             plugin.add(extension2);
154
155         // org.eclipse.ui.intro.config
156
IPluginExtension extension3 = createExtension(
157                 "org.eclipse.ui.intro.config", true); //$NON-NLS-1$
158

159         IPluginElement configurationElement = factory.createElement(extension3);
160         configurationElement.setName("config"); //$NON-NLS-1$
161
configurationElement.setAttribute("id", plugin.getId() + '.' //$NON-NLS-1$
162
+ "configId"); //$NON-NLS-1$
163
configurationElement.setAttribute("introId", introID);//$NON-NLS-1$
164
configurationElement.setAttribute("content", "introContent.xml"); //$NON-NLS-1$ //$NON-NLS-2$
165
IPluginElement presentationElement = factory
166                 .createElement(configurationElement);
167         presentationElement.setName("presentation"); //$NON-NLS-1$
168
presentationElement.setAttribute("home-page-id", "root"); //$NON-NLS-1$ //$NON-NLS-2$
169
IPluginElement implementationElement = factory
170                 .createElement(presentationElement);
171         implementationElement.setName("implementation"); //$NON-NLS-1$
172
implementationElement.setAttribute("os", "win32,linux,macosx"); //$NON-NLS-1$ //$NON-NLS-2$
173
if (getTargetVersion() == 3.0)
174             implementationElement.setAttribute("style", "content/shared.css"); //$NON-NLS-1$//$NON-NLS-2$
175

176         implementationElement.setAttribute("kind", "html"); //$NON-NLS-1$ //$NON-NLS-2$
177
presentationElement.add(implementationElement);
178         configurationElement.add(presentationElement);
179         extension3.add(configurationElement);
180
181         if (!extension3.isInTheModel())
182             plugin.add(extension3);
183         
184         // org.eclipse.ui.intro.configExtension
185
if (getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(DYNAMIC_SELECTED)) {
186             IPluginExtension extension4 = createExtension(
187                 "org.eclipse.ui.intro.configExtension", true); //$NON-NLS-1$
188

189             IPluginElement configExtensionElement = factory.createElement(extension4);
190             configExtensionElement.setName("configExtension"); //$NON-NLS-1$
191
configExtensionElement.setAttribute("configId", plugin.getId() + '.' + "configId"); //$NON-NLS-1$ //$NON-NLS-2$
192
configExtensionElement.setAttribute("content", "ext.xml"); //$NON-NLS-1$ //$NON-NLS-2$
193
extension4.add(configExtensionElement);
194
195             if (!extension4.isInTheModel())
196                 plugin.add(extension4);
197         }
198
199
200     }
201
202    private void createProductExtension() throws CoreException {
203         IPluginBase plugin = model.getPluginBase();
204         IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); //$NON-NLS-1$
205
extension.setId(VALUE_PRODUCT_ID);
206
207         IPluginElement element = model.getFactory().createElement(extension);
208         element.setName("product"); //$NON-NLS-1$
209
element.setAttribute("name", getStringOption(KEY_PRODUCT_NAME)); //$NON-NLS-1$
210
element.setAttribute("application", plugin.getId() + "." + VALUE_APPLICATION_ID); //$NON-NLS-1$ //$NON-NLS-2$
211

212         IPluginElement property = model.getFactory().createElement(element);
213
214         property = model.getFactory().createElement(element);
215         property.setName("property"); //$NON-NLS-1$
216
property.setAttribute("name", "windowImages"); //$NON-NLS-1$ //$NON-NLS-2$
217
property.setAttribute("value", "icons/alt_window_16.gif,icons/alt_window_32.gif"); //$NON-NLS-1$ //$NON-NLS-2$
218
element.add(property);
219
220         extension.add(element);
221
222         if (!extension.isInTheModel())
223             plugin.add(extension);
224     }
225    
226     protected boolean isOkToCreateFolder(File JavaDoc sourceFolder) {
227         return true;
228     }
229
230     /**
231      * @see AbstractTemplateSection#isOkToCreateFile(File)
232      */

233     protected boolean isOkToCreateFile(File JavaDoc sourceFile) {
234
235         if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(STATIC_SELECTED) &&
236                 (sourceFile.getName().equals("DynamicContentProvider.java") || //$NON-NLS-1$
237
sourceFile.getName().equals("concept3.xhtml") || //$NON-NLS-1$
238
sourceFile.getName().equals("extContent.xhtml") || //$NON-NLS-1$
239
sourceFile.getName().equals("ext.xml") ) ) { //$NON-NLS-1$
240
return false;
241         }
242         
243         return true;
244     }
245
246     public String JavaDoc getUsedExtensionPoint() {
247         return "org.eclipse.ui.intro"; // need more then one extension point //$NON-NLS-1$
248
}
249
250     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
251         ArrayList JavaDoc result = new ArrayList JavaDoc();
252
253         result.add(new PluginReference("org.eclipse.ui.intro", null, 0)); //$NON-NLS-1$
254
result.add(new PluginReference("org.eclipse.core.runtime", null, 0)); //$NON-NLS-1$
255
result.add(new PluginReference("org.eclipse.ui", null, 0)); //$NON-NLS-1$
256

257         if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(DYNAMIC_SELECTED)) {
258             result.add(new PluginReference("org.eclipse.ui.forms", null, 0)); //$NON-NLS-1$
259
result.add(new PluginReference("org.eclipse.swt", null, 0)); //$NON-NLS-1$
260
}
261
262         return (IPluginReference[]) result.toArray(new IPluginReference[result
263                 .size()]);
264     }
265
266     public int getNumberOfWorkUnits() {
267         return super.getNumberOfWorkUnits() + 1;
268     }
269     
270     public Object JavaDoc getValue(String JavaDoc valueName) {
271         
272         if (valueName.equals(KEY_PACKAGE_NAME)) {
273             return packageName;
274         }
275         
276         return super.getValue(valueName);
277     }
278     
279     public String JavaDoc getStringOption(String JavaDoc name) {
280         
281         if ( name.equals(KEY_PACKAGE_NAME)) {
282             return packageName;
283         }
284         
285         return super.getStringOption(name);
286     }
287
288     public String JavaDoc[] getNewFiles() {
289         if (getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(STATIC_SELECTED)) {
290             return new String JavaDoc[] {"icons/", "content/", "splash.bmp", "introContent.xml" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
291
}
292         return new String JavaDoc[] {"icons/", "content/", "splash.bmp", "introContent.xml", "ext.xml" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
293
}
294     
295     /* (non-Javadoc)
296      * @see org.eclipse.pde.internal.ui.templates.PDETemplateSection#copyBrandingDirectory()
297      */

298     protected boolean copyBrandingDirectory() {
299         return true;
300     }
301 }
302
Popular Tags