KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.eclipse.pde.internal.ui.templates.rcp;
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.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.internal.ui.templates.PluginReference;
26 import org.eclipse.pde.ui.IFieldData;
27
28
29 public class MailTemplate extends PDETemplateSection {
30     
31     public static final String JavaDoc KEY_WORKBENCH_ADVISOR = "advisor"; //$NON-NLS-1$
32
public static final String JavaDoc KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$
33

34     public MailTemplate() {
35         setPageCount(1);
36         createOptions();
37     }
38     
39     public void addPages(Wizard wizard) {
40         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL);
41         page.setTitle(PDETemplateMessages.MailTemplate_title);
42         page.setDescription(PDETemplateMessages.MailTemplate_desc);
43         wizard.addPage(page);
44         markPagesAdded();
45     }
46
47     
48     private void createOptions() {
49         addOption(KEY_PRODUCT_NAME, PDETemplateMessages.MailTemplate_productName, VALUE_PRODUCT_NAME, 0);
50         
51         addOption(KEY_PACKAGE_NAME, PDETemplateMessages.MailTemplate_packageName, (String JavaDoc) null, 0); //
52

53         addOption(KEY_APPLICATION_CLASS, PDETemplateMessages.MailTemplate_appClass, "Application", 0); //$NON-NLS-1$
54
}
55     
56     protected void initializeFields(IFieldData data) {
57         // In a new project wizard, we don't know this yet - the
58
// model has not been created
59
String JavaDoc packageName = getFormattedPackageName(data.getId());
60         initializeOption(KEY_PACKAGE_NAME, packageName);
61     }
62     
63     public void initializeFields(IPluginModelBase model) {
64         String JavaDoc packageName = getFormattedPackageName(model.getPluginBase().getId());
65         initializeOption(KEY_PACKAGE_NAME, packageName);
66     }
67     
68     /*
69      * (non-Javadoc)
70      *
71      * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
72      */

73     public String JavaDoc getSectionId() {
74         return "mail"; //$NON-NLS-1$
75
}
76
77     /* (non-Javadoc)
78      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
79      */

80     protected void updateModel(IProgressMonitor monitor) throws CoreException {
81         createApplicationExtension();
82         createPerspectiveExtension();
83         createViewExtension();
84         if (getTargetVersion() >= 3.1) {
85             createCommandExtension(false);
86             createBindingsExtension();
87         } else {
88             createCommandExtension(true);
89         }
90         createProductExtension();
91     }
92     
93     private void createApplicationExtension() throws CoreException {
94         IPluginBase plugin = model.getPluginBase();
95         
96         IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
97
extension.setId(VALUE_APPLICATION_ID);
98         
99         IPluginElement element = model.getPluginFactory().createElement(extension);
100         element.setName("application"); //$NON-NLS-1$
101
extension.add(element);
102         
103         IPluginElement run = model.getPluginFactory().createElement(element);
104         run.setName("run"); //$NON-NLS-1$
105
run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
106
element.add(run);
107         
108         if (!extension.isInTheModel())
109             plugin.add(extension);
110     }
111
112     
113     private void createPerspectiveExtension() throws CoreException {
114         IPluginBase plugin = model.getPluginBase();
115         
116         IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); //$NON-NLS-1$
117
IPluginElement element = model.getPluginFactory().createElement(extension);
118         element.setName("perspective"); //$NON-NLS-1$
119
element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
120
element.setAttribute("name", VALUE_PERSPECTIVE_NAME); //$NON-NLS-1$
121
element.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$
122
extension.add(element);
123         
124         if (!extension.isInTheModel())
125             plugin.add(extension);
126     }
127     
128     private void createViewExtension() throws CoreException {
129         IPluginBase plugin = model.getPluginBase();
130         String JavaDoc id = plugin.getId();
131         IPluginExtension extension = createExtension("org.eclipse.ui.views", true); //$NON-NLS-1$
132

133         IPluginElement view = model.getPluginFactory().createElement(extension);
134         view.setName("view"); //$NON-NLS-1$
135
view.setAttribute("allowMultiple", "true"); //$NON-NLS-1$ //$NON-NLS-2$
136
view.setAttribute("icon", "icons/sample2.gif"); //$NON-NLS-1$ //$NON-NLS-2$
137
view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".View" ); //$NON-NLS-1$ //$NON-NLS-2$
138
view.setAttribute("name", "Message"); //$NON-NLS-1$ //$NON-NLS-2$
139
view.setAttribute("id", id + ".view"); //$NON-NLS-1$ //$NON-NLS-2$
140
extension.add(view);
141         
142         view = model.getPluginFactory().createElement(extension);
143         view.setName("view"); //$NON-NLS-1$
144
view.setAttribute("allowMultiple", "true"); //$NON-NLS-1$ //$NON-NLS-2$
145
view.setAttribute("icon", "icons/sample3.gif"); //$NON-NLS-1$ //$NON-NLS-2$
146
view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".NavigationView" ); //$NON-NLS-1$ //$NON-NLS-2$
147
view.setAttribute("name", "Mailboxes"); //$NON-NLS-1$ //$NON-NLS-2$
148
view.setAttribute("id", id + ".navigationView"); //$NON-NLS-1$ //$NON-NLS-2$
149
extension.add(view);
150         
151         if (!extension.isInTheModel())
152             plugin.add(extension);
153     }
154     
155     private void createCommandExtension(boolean generateKeyBindings) throws CoreException {
156         IPluginBase plugin = model.getPluginBase();
157         String JavaDoc id = plugin.getId();
158         IPluginExtension extension = createExtension("org.eclipse.ui.commands", true); //$NON-NLS-1$
159

160         IPluginElement element = model.getPluginFactory().createElement(extension);
161         element.setName("category"); //$NON-NLS-1$
162
element.setAttribute("id", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
163
element.setAttribute("name", "Mail"); //$NON-NLS-1$ //$NON-NLS-2$
164
extension.add(element);
165
166         element = model.getPluginFactory().createElement(extension);
167         element.setName("command"); //$NON-NLS-1$
168
element.setAttribute("description", "Opens a mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
169
element.setAttribute("name", "Open Mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
170
element.setAttribute("id", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
171
element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
172
extension.add(element);
173         
174         element = model.getPluginFactory().createElement(extension);
175         element.setName("command"); //$NON-NLS-1$
176
element.setAttribute("description", "Open a message dialog"); //$NON-NLS-1$ //$NON-NLS-2$
177
element.setAttribute("name", "Open Message Dialog"); //$NON-NLS-1$ //$NON-NLS-2$
178
element.setAttribute("id", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
179
element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
180
extension.add(element);
181         
182         if(generateKeyBindings){
183             element = model.getPluginFactory().createElement(extension);
184             element.setName("keyConfiguration"); //$NON-NLS-1$
185
element.setAttribute("description", "The key configuration for this sample"); //$NON-NLS-1$ //$NON-NLS-2$
186
element.setAttribute("name", id + ".keyConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
187
element.setAttribute("id", id + ".keyConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
188
extension.add(element);
189             
190             element = model.getPluginFactory().createElement(extension);
191             element.setName("keyBinding"); //$NON-NLS-1$
192
element.setAttribute("commandId", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
193
element.setAttribute("keySequence", "CTRL+2"); //$NON-NLS-1$ //$NON-NLS-2$
194
element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
195
extension.add(element);
196             
197             element = model.getPluginFactory().createElement(extension);
198             element.setName("keyBinding"); //$NON-NLS-1$
199
element.setAttribute("commandId", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
200
element.setAttribute("keySequence", "CTRL+3"); //$NON-NLS-1$ //$NON-NLS-2$
201
element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
202
extension.add(element);
203             
204             element = model.getPluginFactory().createElement(extension);
205             element.setName("keyBinding"); //$NON-NLS-1$
206
element.setAttribute("commandId", "org.eclipse.ui.file.exit"); //$NON-NLS-1$ //$NON-NLS-2$
207
element.setAttribute("keySequence", "CTRL+Q"); //$NON-NLS-1$ //$NON-NLS-2$
208
element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
209
extension.add(element);
210         }
211         
212         if (!extension.isInTheModel())
213             plugin.add(extension);
214     }
215     
216     private void createBindingsExtension() throws CoreException {
217         IPluginBase plugin = model.getPluginBase();
218         String JavaDoc id = plugin.getId();
219         IPluginExtension extension = createExtension("org.eclipse.ui.bindings", true); //$NON-NLS-1$
220

221         IPluginElement element = model.getPluginFactory().createElement(extension);
222         element.setName("key"); //$NON-NLS-1$
223
element.setAttribute("commandId", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
224
element.setAttribute("sequence", "CTRL+2"); //$NON-NLS-1$ //$NON-NLS-2$
225
element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
226
extension.add(element);
227         
228         element = model.getPluginFactory().createElement(extension);
229         element.setName("key"); //$NON-NLS-1$
230
element.setAttribute("commandId", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
231
element.setAttribute("sequence", "CTRL+3"); //$NON-NLS-1$ //$NON-NLS-2$
232
element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
233
extension.add(element);
234         
235         element = model.getPluginFactory().createElement(extension);
236         element.setName("key"); //$NON-NLS-1$
237
element.setAttribute("commandId", "org.eclipse.ui.file.exit"); //$NON-NLS-1$ //$NON-NLS-2$
238
element.setAttribute("sequence", "CTRL+X"); //$NON-NLS-1$ //$NON-NLS-2$
239
element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
240
extension.add(element);
241         
242         if (!extension.isInTheModel())
243             plugin.add(extension);
244     }
245     
246     private void createProductExtension() throws CoreException {
247         IPluginBase plugin = model.getPluginBase();
248         IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); //$NON-NLS-1$
249
extension.setId(VALUE_PRODUCT_ID);
250         
251         IPluginElement element = model.getFactory().createElement(extension);
252         element.setName("product"); //$NON-NLS-1$
253
element.setAttribute("name", getStringOption(KEY_PRODUCT_NAME)); //$NON-NLS-1$
254
element.setAttribute("application", plugin.getId() + "." + VALUE_APPLICATION_ID); //$NON-NLS-1$ //$NON-NLS-2$
255

256         IPluginElement property = model.getFactory().createElement(element);
257         property.setName("property"); //$NON-NLS-1$
258
property.setAttribute("name", "aboutText"); //$NON-NLS-1$ //$NON-NLS-2$
259
property.setAttribute("value", "RCP Mail template created by PDE"); //$NON-NLS-1$ //$NON-NLS-2$
260
element.add(property);
261         
262         property = model.getFactory().createElement(element);
263         property.setName("property"); //$NON-NLS-1$
264
property.setAttribute("name", "windowImages"); //$NON-NLS-1$ //$NON-NLS-2$
265
property.setAttribute("value", "icons/sample2.gif"); //$NON-NLS-1$ //$NON-NLS-2$
266
element.add(property);
267
268         property = model.getFactory().createElement(element);
269         property.setName("property"); //$NON-NLS-1$
270
property.setAttribute("name", "aboutImage"); //$NON-NLS-1$ //$NON-NLS-2$
271
property.setAttribute("value", "product_lg.gif"); //$NON-NLS-1$ //$NON-NLS-2$
272
element.add(property);
273         
274         extension.add(element);
275         
276         if (!extension.isInTheModel()) {
277             plugin.add(extension);
278         }
279
280     }
281
282     /* (non-Javadoc)
283      * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
284      */

285     public String JavaDoc getUsedExtensionPoint() {
286         return null;
287     }
288     
289     /* (non-Javadoc)
290      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
291      */

292     public boolean isDependentOnParentWizard() {
293         return true;
294     }
295     
296     /* (non-Javadoc)
297      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
298      */

299     public int getNumberOfWorkUnits() {
300         return super.getNumberOfWorkUnits() + 1;
301     }
302     
303     /* (non-Javadoc)
304      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
305      */

306     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
307         IPluginReference[] dep = new IPluginReference[2];
308         dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
309
dep[1] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
310
return dep;
311     }
312     
313     /* (non-Javadoc)
314      * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getNewFiles()
315      */

316     public String JavaDoc[] getNewFiles() {
317         return new String JavaDoc[] {"icons/", "product_lg.gif", "splash.bmp"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
318
}
319     
320     /* (non-Javadoc)
321      * @see org.eclipse.pde.internal.ui.templates.PDETemplateSection#copyBrandingDirectory()
322      */

323     protected boolean copyBrandingDirectory() {
324         return true;
325     }
326
327 }
328
Popular Tags