KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.wizards.templates;
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.IPluginReference;
22 import org.eclipse.pde.internal.core.plugin.PluginBase;
23 import org.eclipse.pde.internal.ui.IHelpContextIds;
24 import org.eclipse.pde.internal.ui.PDEUIMessages;
25 import org.eclipse.pde.ui.IFieldData;
26 import org.eclipse.pde.ui.templates.TemplateOption;
27
28
29 public class MailTemplate extends PDETemplateSection {
30     
31     public static final String JavaDoc KEY_PRODUCT_NAME = "productName"; //$NON-NLS-1$
32
public static final String JavaDoc KEY_PRODUCT_ID = "productID"; //$NON-NLS-1$
33
public static final String JavaDoc KEY_PERSPECTIVE_NAME = "perspectiveName"; //$NON-NLS-1$
34
public static final String JavaDoc KEY_WORKBENCH_ADVISOR = "advisor"; //$NON-NLS-1$
35
public static final String JavaDoc KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$
36
public static final String JavaDoc KEY_APPLICATION_ID = "applicationID"; //$NON-NLS-1$
37

38     public MailTemplate() {
39         setPageCount(1);
40         createOptions();
41     }
42     
43     public void addPages(Wizard wizard) {
44         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL);
45         page.setTitle(PDEUIMessages.MailTemplate_title);
46         page.setDescription(PDEUIMessages.MailTemplate_desc);
47         wizard.addPage(page);
48         markPagesAdded();
49     }
50
51     
52     private void createOptions() {
53         addOption(KEY_PRODUCT_NAME, PDEUIMessages.MailTemplate_productName, "RCP Product", 0); //$NON-NLS-1$
54

55         addOption(KEY_PRODUCT_ID, PDEUIMessages.MailTemplate_productID, "product", 0); //$NON-NLS-1$
56

57         addOption(KEY_APPLICATION_ID, PDEUIMessages.MailTemplate_appId, "application", 0); //$NON-NLS-1$
58

59         addOption(KEY_PERSPECTIVE_NAME, PDEUIMessages.MailTemplate_perspectiveName, (String JavaDoc)null, 0); //
60

61         addOption(KEY_PACKAGE_NAME, PDEUIMessages.MailTemplate_packageName, (String JavaDoc) null, 0); //
62

63         addOption(KEY_APPLICATION_CLASS, PDEUIMessages.MailTemplate_appClass, "Application", 0); //$NON-NLS-1$
64
}
65     
66     protected void initializeFields(IFieldData data) {
67         // In a new project wizard, we don't know this yet - the
68
// model has not been created
69
String JavaDoc packageName = getFormattedPackageName(data.getId());
70         initializeOption(KEY_PACKAGE_NAME, packageName);
71
72         int index = packageName.lastIndexOf('.');
73         String JavaDoc name = packageName.substring(index + 1) + " Perspective"; //$NON-NLS-1$
74
initializeOption(KEY_PERSPECTIVE_NAME, Character.toUpperCase(name.charAt(0)) + name.substring(1));
75     }
76     
77     public void initializeFields(IPluginModelBase model) {
78         String JavaDoc packageName = getFormattedPackageName(model.getPluginBase().getId());
79         initializeOption(KEY_PACKAGE_NAME, packageName);
80
81         int index = packageName.lastIndexOf('.');
82         String JavaDoc name = packageName.substring(index + 1) + " Perspective"; //$NON-NLS-1$
83
initializeOption(KEY_PERSPECTIVE_NAME, Character.toUpperCase(name.charAt(0)) + name.substring(1));
84     }
85     
86     /*
87      * (non-Javadoc)
88      *
89      * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
90      */

91     public String JavaDoc getSectionId() {
92         return "mail"; //$NON-NLS-1$
93
}
94
95     /* (non-Javadoc)
96      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#validateOptions(org.eclipse.pde.ui.templates.TemplateOption)
97      */

98     public void validateOptions(TemplateOption source) {
99         if (source.isRequired() && source.isEmpty()) {
100             flagMissingRequiredOption(source);
101         } else {
102             validateContainerPage(source);
103         }
104     }
105     
106     private void validateContainerPage(TemplateOption source) {
107         TemplateOption[] allPageOptions = getOptions(0);
108         for (int i = 0; i < allPageOptions.length; i++) {
109             TemplateOption nextOption = allPageOptions[i];
110             if (nextOption.isRequired() && nextOption.isEmpty()) {
111                 flagMissingRequiredOption(nextOption);
112                 return;
113             }
114         }
115         resetPageState();
116     }
117
118     /* (non-Javadoc)
119      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
120      */

121     protected void updateModel(IProgressMonitor monitor) throws CoreException {
122         createApplicationExtension();
123         createPerspectiveExtension();
124         createViewExtension();
125         if ("3.1".compareTo(((PluginBase) model.getPluginBase()).getTargetVersion()) <= 0) { //$NON-NLS-1$
126
createCommandExtension(false);
127             createBindingsExtension();
128         } else {
129             createCommandExtension(true);
130         }
131         createProductExtension();
132     }
133     
134     private void createApplicationExtension() throws CoreException {
135         IPluginBase plugin = model.getPluginBase();
136         
137         IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
138
extension.setId(getStringOption(KEY_APPLICATION_ID));
139         
140         IPluginElement element = model.getPluginFactory().createElement(extension);
141         element.setName("application"); //$NON-NLS-1$
142
extension.add(element);
143         
144         IPluginElement run = model.getPluginFactory().createElement(element);
145         run.setName("run"); //$NON-NLS-1$
146
run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
147
element.add(run);
148         
149         if (!extension.isInTheModel())
150             plugin.add(extension);
151     }
152
153     
154     private void createPerspectiveExtension() throws CoreException {
155         IPluginBase plugin = model.getPluginBase();
156         
157         IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); //$NON-NLS-1$
158
IPluginElement element = model.getPluginFactory().createElement(extension);
159         element.setName("perspective"); //$NON-NLS-1$
160
element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
161
element.setAttribute("name", getStringOption(KEY_PERSPECTIVE_NAME)); //$NON-NLS-1$
162
element.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$
163
extension.add(element);
164         
165         if (!extension.isInTheModel())
166             plugin.add(extension);
167     }
168     
169     private void createViewExtension() throws CoreException {
170         IPluginBase plugin = model.getPluginBase();
171         String JavaDoc id = plugin.getId();
172         IPluginExtension extension = createExtension("org.eclipse.ui.views", true); //$NON-NLS-1$
173

174         IPluginElement view = model.getPluginFactory().createElement(extension);
175         view.setName("view"); //$NON-NLS-1$
176
view.setAttribute("allowMultiple", "true"); //$NON-NLS-1$ //$NON-NLS-2$
177
view.setAttribute("icon", "icons/sample2.gif"); //$NON-NLS-1$ //$NON-NLS-2$
178
view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".View" ); //$NON-NLS-1$ //$NON-NLS-2$
179
view.setAttribute("name", "Message"); //$NON-NLS-1$ //$NON-NLS-2$
180
view.setAttribute("id", id + ".view"); //$NON-NLS-1$ //$NON-NLS-2$
181
extension.add(view);
182         
183         view = model.getPluginFactory().createElement(extension);
184         view.setName("view"); //$NON-NLS-1$
185
view.setAttribute("allowMultiple", "true"); //$NON-NLS-1$ //$NON-NLS-2$
186
view.setAttribute("icon", "icons/sample3.gif"); //$NON-NLS-1$ //$NON-NLS-2$
187
view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".NavigationView" ); //$NON-NLS-1$ //$NON-NLS-2$
188
view.setAttribute("name", "Mailboxes"); //$NON-NLS-1$ //$NON-NLS-2$
189
view.setAttribute("id", id + ".navigationView"); //$NON-NLS-1$ //$NON-NLS-2$
190
extension.add(view);
191         
192         if (!extension.isInTheModel())
193             plugin.add(extension);
194     }
195     
196     private void createCommandExtension(boolean generateKeyBindings) throws CoreException {
197         IPluginBase plugin = model.getPluginBase();
198         String JavaDoc id = plugin.getId();
199         IPluginExtension extension = createExtension("org.eclipse.ui.commands", true); //$NON-NLS-1$
200

201         IPluginElement element = model.getPluginFactory().createElement(extension);
202         element.setName("category"); //$NON-NLS-1$
203
element.setAttribute("id", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
204
element.setAttribute("name", "Mail"); //$NON-NLS-1$ //$NON-NLS-2$
205
extension.add(element);
206
207         element = model.getPluginFactory().createElement(extension);
208         element.setName("command"); //$NON-NLS-1$
209
element.setAttribute("description", "Opens a mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
210
element.setAttribute("name", "Open Mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
211
element.setAttribute("id", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
212
element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
213
extension.add(element);
214         
215         element = model.getPluginFactory().createElement(extension);
216         element.setName("command"); //$NON-NLS-1$
217
element.setAttribute("description", "Open a message dialog"); //$NON-NLS-1$ //$NON-NLS-2$
218
element.setAttribute("name", "Open Message Dialog"); //$NON-NLS-1$ //$NON-NLS-2$
219
element.setAttribute("id", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
220
element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
221
extension.add(element);
222         
223         if(generateKeyBindings){
224             element = model.getPluginFactory().createElement(extension);
225             element.setName("keyConfiguration"); //$NON-NLS-1$
226
element.setAttribute("description", "The key configuration for this sample"); //$NON-NLS-1$ //$NON-NLS-2$
227
element.setAttribute("name", id + ".keyConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
228
element.setAttribute("id", id + ".keyConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
229
extension.add(element);
230             
231             element = model.getPluginFactory().createElement(extension);
232             element.setName("keyBinding"); //$NON-NLS-1$
233
element.setAttribute("commandId", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
234
element.setAttribute("keySequence", "CTRL+2"); //$NON-NLS-1$ //$NON-NLS-2$
235
element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
236
extension.add(element);
237             
238             element = model.getPluginFactory().createElement(extension);
239             element.setName("keyBinding"); //$NON-NLS-1$
240
element.setAttribute("commandId", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
241
element.setAttribute("keySequence", "CTRL+3"); //$NON-NLS-1$ //$NON-NLS-2$
242
element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
243
extension.add(element);
244             
245             element = model.getPluginFactory().createElement(extension);
246             element.setName("keyBinding"); //$NON-NLS-1$
247
element.setAttribute("commandId", "org.eclipse.ui.file.exit"); //$NON-NLS-1$ //$NON-NLS-2$
248
element.setAttribute("keySequence", "CTRL+X"); //$NON-NLS-1$ //$NON-NLS-2$
249
element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
250
extension.add(element);
251         }
252         
253         if (!extension.isInTheModel())
254             plugin.add(extension);
255     }
256     
257     private void createBindingsExtension() throws CoreException {
258         IPluginBase plugin = model.getPluginBase();
259         String JavaDoc id = plugin.getId();
260         IPluginExtension extension = createExtension("org.eclipse.ui.bindings", true); //$NON-NLS-1$
261

262         IPluginElement element = model.getPluginFactory().createElement(extension);
263         element.setName("key"); //$NON-NLS-1$
264
element.setAttribute("commandId", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
265
element.setAttribute("sequence", "CTRL+2"); //$NON-NLS-1$ //$NON-NLS-2$
266
element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
267
extension.add(element);
268         
269         element = model.getPluginFactory().createElement(extension);
270         element.setName("key"); //$NON-NLS-1$
271
element.setAttribute("commandId", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
272
element.setAttribute("sequence", "CTRL+3"); //$NON-NLS-1$ //$NON-NLS-2$
273
element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
274
extension.add(element);
275         
276         element = model.getPluginFactory().createElement(extension);
277         element.setName("key"); //$NON-NLS-1$
278
element.setAttribute("commandId", "org.eclipse.ui.file.exit"); //$NON-NLS-1$ //$NON-NLS-2$
279
element.setAttribute("sequence", "CTRL+X"); //$NON-NLS-1$ //$NON-NLS-2$
280
element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
281
extension.add(element);
282         
283         if (!extension.isInTheModel())
284             plugin.add(extension);
285     }
286     
287     private void createProductExtension() throws CoreException {
288         IPluginBase plugin = model.getPluginBase();
289         IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); //$NON-NLS-1$
290
extension.setId(getStringOption(KEY_PRODUCT_ID));
291         
292         IPluginElement element = model.getFactory().createElement(extension);
293         element.setName("product"); //$NON-NLS-1$
294
element.setAttribute("name", getStringOption(KEY_PRODUCT_NAME)); //$NON-NLS-1$
295
element.setAttribute("application", plugin.getId() + "." + getStringOption(KEY_APPLICATION_ID)); //$NON-NLS-1$ //$NON-NLS-2$
296

297         IPluginElement property = model.getFactory().createElement(element);
298         property.setName("property"); //$NON-NLS-1$
299
property.setAttribute("name", "aboutText"); //$NON-NLS-1$ //$NON-NLS-2$
300
property.setAttribute("value", "%aboutText"); //$NON-NLS-1$ //$NON-NLS-2$
301
element.add(property);
302         
303         property = model.getFactory().createElement(element);
304         property.setName("property"); //$NON-NLS-1$
305
property.setAttribute("name", "windowImages"); //$NON-NLS-1$ //$NON-NLS-2$
306
property.setAttribute("value", "icons/sample2.gif"); //$NON-NLS-1$ //$NON-NLS-2$
307
element.add(property);
308
309         property = model.getFactory().createElement(element);
310         property.setName("property"); //$NON-NLS-1$
311
property.setAttribute("name", "aboutImage"); //$NON-NLS-1$ //$NON-NLS-2$
312
property.setAttribute("value", "product_lg.gif"); //$NON-NLS-1$ //$NON-NLS-2$
313
element.add(property);
314         
315         extension.add(element);
316         
317         if (!extension.isInTheModel()) {
318             plugin.add(extension);
319         }
320
321     }
322
323     /* (non-Javadoc)
324      * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
325      */

326     public String JavaDoc getUsedExtensionPoint() {
327         return null;
328     }
329     
330     /* (non-Javadoc)
331      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
332      */

333     public boolean isDependentOnParentWizard() {
334         return true;
335     }
336     
337     /* (non-Javadoc)
338      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
339      */

340     public int getNumberOfWorkUnits() {
341         return super.getNumberOfWorkUnits() + 1;
342     }
343     
344     /* (non-Javadoc)
345      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
346      */

347     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
348         IPluginReference[] dep = new IPluginReference[2];
349         dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
350
dep[1] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
351
return dep;
352     }
353     
354     /* (non-Javadoc)
355      * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getNewFiles()
356      */

357     public String JavaDoc[] getNewFiles() {
358         return new String JavaDoc[] {"icons/", "plugin.properties", "product_lg.gif", "splash.bmp"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
359
}
360
361 }
362
Popular Tags