001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.templates.rcp;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IProgressMonitor;
014: import org.eclipse.jface.wizard.Wizard;
015: import org.eclipse.jface.wizard.WizardPage;
016: import org.eclipse.pde.core.plugin.IPluginBase;
017: import org.eclipse.pde.core.plugin.IPluginElement;
018: import org.eclipse.pde.core.plugin.IPluginExtension;
019: import org.eclipse.pde.core.plugin.IPluginModelBase;
020: import org.eclipse.pde.core.plugin.IPluginReference;
021: import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
022: import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
023: import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
024: import org.eclipse.pde.internal.ui.templates.PluginReference;
025: import org.eclipse.pde.ui.IFieldData;
026:
027: public class MailTemplate extends PDETemplateSection {
028:
029: public static final String KEY_WORKBENCH_ADVISOR = "advisor"; //$NON-NLS-1$
030: public static final String KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$
031:
032: public MailTemplate() {
033: setPageCount(1);
034: createOptions();
035: }
036:
037: public void addPages(Wizard wizard) {
038: WizardPage page = createPage(0,
039: IHelpContextIds.TEMPLATE_RCP_MAIL);
040: page.setTitle(PDETemplateMessages.MailTemplate_title);
041: page.setDescription(PDETemplateMessages.MailTemplate_desc);
042: wizard.addPage(page);
043: markPagesAdded();
044: }
045:
046: private void createOptions() {
047: addOption(KEY_PRODUCT_NAME,
048: PDETemplateMessages.MailTemplate_productName,
049: VALUE_PRODUCT_NAME, 0);
050:
051: addOption(KEY_PACKAGE_NAME,
052: PDETemplateMessages.MailTemplate_packageName,
053: (String) null, 0); //
054:
055: addOption(KEY_APPLICATION_CLASS,
056: PDETemplateMessages.MailTemplate_appClass,
057: "Application", 0); //$NON-NLS-1$
058: }
059:
060: protected void initializeFields(IFieldData data) {
061: // In a new project wizard, we don't know this yet - the
062: // model has not been created
063: String packageName = getFormattedPackageName(data.getId());
064: initializeOption(KEY_PACKAGE_NAME, packageName);
065: }
066:
067: public void initializeFields(IPluginModelBase model) {
068: String packageName = getFormattedPackageName(model
069: .getPluginBase().getId());
070: initializeOption(KEY_PACKAGE_NAME, packageName);
071: }
072:
073: /*
074: * (non-Javadoc)
075: *
076: * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
077: */
078: public String getSectionId() {
079: return "mail"; //$NON-NLS-1$
080: }
081:
082: /* (non-Javadoc)
083: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
084: */
085: protected void updateModel(IProgressMonitor monitor)
086: throws CoreException {
087: createApplicationExtension();
088: createPerspectiveExtension();
089: createViewExtension();
090: if (getTargetVersion() >= 3.1) {
091: createCommandExtension(false);
092: createBindingsExtension();
093: } else {
094: createCommandExtension(true);
095: }
096: createProductExtension();
097: }
098:
099: private void createApplicationExtension() throws CoreException {
100: IPluginBase plugin = model.getPluginBase();
101:
102: IPluginExtension extension = createExtension(
103: "org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
104: extension.setId(VALUE_APPLICATION_ID);
105:
106: IPluginElement element = model.getPluginFactory()
107: .createElement(extension);
108: element.setName("application"); //$NON-NLS-1$
109: extension.add(element);
110:
111: IPluginElement run = model.getPluginFactory().createElement(
112: element);
113: run.setName("run"); //$NON-NLS-1$
114: run
115: .setAttribute(
116: "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
117: element.add(run);
118:
119: if (!extension.isInTheModel())
120: plugin.add(extension);
121: }
122:
123: private void createPerspectiveExtension() throws CoreException {
124: IPluginBase plugin = model.getPluginBase();
125:
126: IPluginExtension extension = createExtension(
127: "org.eclipse.ui.perspectives", true); //$NON-NLS-1$
128: IPluginElement element = model.getPluginFactory()
129: .createElement(extension);
130: element.setName("perspective"); //$NON-NLS-1$
131: element
132: .setAttribute(
133: "class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
134: element.setAttribute("name", VALUE_PERSPECTIVE_NAME); //$NON-NLS-1$
135: element.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$
136: extension.add(element);
137:
138: if (!extension.isInTheModel())
139: plugin.add(extension);
140: }
141:
142: private void createViewExtension() throws CoreException {
143: IPluginBase plugin = model.getPluginBase();
144: String id = plugin.getId();
145: IPluginExtension extension = createExtension(
146: "org.eclipse.ui.views", true); //$NON-NLS-1$
147:
148: IPluginElement view = model.getPluginFactory().createElement(
149: extension);
150: view.setName("view"); //$NON-NLS-1$
151: view.setAttribute("allowMultiple", "true"); //$NON-NLS-1$ //$NON-NLS-2$
152: view.setAttribute("icon", "icons/sample2.gif"); //$NON-NLS-1$ //$NON-NLS-2$
153: view.setAttribute(
154: "class", getStringOption(KEY_PACKAGE_NAME) + ".View"); //$NON-NLS-1$ //$NON-NLS-2$
155: view.setAttribute("name", "Message"); //$NON-NLS-1$ //$NON-NLS-2$
156: view.setAttribute("id", id + ".view"); //$NON-NLS-1$ //$NON-NLS-2$
157: extension.add(view);
158:
159: view = model.getPluginFactory().createElement(extension);
160: view.setName("view"); //$NON-NLS-1$
161: view.setAttribute("allowMultiple", "true"); //$NON-NLS-1$ //$NON-NLS-2$
162: view.setAttribute("icon", "icons/sample3.gif"); //$NON-NLS-1$ //$NON-NLS-2$
163: view
164: .setAttribute(
165: "class", getStringOption(KEY_PACKAGE_NAME) + ".NavigationView"); //$NON-NLS-1$ //$NON-NLS-2$
166: view.setAttribute("name", "Mailboxes"); //$NON-NLS-1$ //$NON-NLS-2$
167: view.setAttribute("id", id + ".navigationView"); //$NON-NLS-1$ //$NON-NLS-2$
168: extension.add(view);
169:
170: if (!extension.isInTheModel())
171: plugin.add(extension);
172: }
173:
174: private void createCommandExtension(boolean generateKeyBindings)
175: throws CoreException {
176: IPluginBase plugin = model.getPluginBase();
177: String id = plugin.getId();
178: IPluginExtension extension = createExtension(
179: "org.eclipse.ui.commands", true); //$NON-NLS-1$
180:
181: IPluginElement element = model.getPluginFactory()
182: .createElement(extension);
183: element.setName("category"); //$NON-NLS-1$
184: element.setAttribute("id", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
185: element.setAttribute("name", "Mail"); //$NON-NLS-1$ //$NON-NLS-2$
186: extension.add(element);
187:
188: element = model.getPluginFactory().createElement(extension);
189: element.setName("command"); //$NON-NLS-1$
190: element.setAttribute("description", "Opens a mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
191: element.setAttribute("name", "Open Mailbox"); //$NON-NLS-1$ //$NON-NLS-2$
192: element.setAttribute("id", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
193: element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
194: extension.add(element);
195:
196: element = model.getPluginFactory().createElement(extension);
197: element.setName("command"); //$NON-NLS-1$
198: element.setAttribute("description", "Open a message dialog"); //$NON-NLS-1$ //$NON-NLS-2$
199: element.setAttribute("name", "Open Message Dialog"); //$NON-NLS-1$ //$NON-NLS-2$
200: element.setAttribute("id", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
201: element.setAttribute("categoryId", id + ".category"); //$NON-NLS-1$ //$NON-NLS-2$
202: extension.add(element);
203:
204: if (generateKeyBindings) {
205: element = model.getPluginFactory().createElement(extension);
206: element.setName("keyConfiguration"); //$NON-NLS-1$
207: element
208: .setAttribute(
209: "description", "The key configuration for this sample"); //$NON-NLS-1$ //$NON-NLS-2$
210: element.setAttribute("name", id + ".keyConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
211: element.setAttribute("id", id + ".keyConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
212: extension.add(element);
213:
214: element = model.getPluginFactory().createElement(extension);
215: element.setName("keyBinding"); //$NON-NLS-1$
216: element.setAttribute("commandId", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
217: element.setAttribute("keySequence", "CTRL+2"); //$NON-NLS-1$ //$NON-NLS-2$
218: element
219: .setAttribute(
220: "keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
221: extension.add(element);
222:
223: element = model.getPluginFactory().createElement(extension);
224: element.setName("keyBinding"); //$NON-NLS-1$
225: element.setAttribute("commandId", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
226: element.setAttribute("keySequence", "CTRL+3"); //$NON-NLS-1$ //$NON-NLS-2$
227: element
228: .setAttribute(
229: "keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
230: extension.add(element);
231:
232: element = model.getPluginFactory().createElement(extension);
233: element.setName("keyBinding"); //$NON-NLS-1$
234: element.setAttribute(
235: "commandId", "org.eclipse.ui.file.exit"); //$NON-NLS-1$ //$NON-NLS-2$
236: element.setAttribute("keySequence", "CTRL+Q"); //$NON-NLS-1$ //$NON-NLS-2$
237: element
238: .setAttribute(
239: "keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
240: extension.add(element);
241: }
242:
243: if (!extension.isInTheModel())
244: plugin.add(extension);
245: }
246:
247: private void createBindingsExtension() throws CoreException {
248: IPluginBase plugin = model.getPluginBase();
249: String id = plugin.getId();
250: IPluginExtension extension = createExtension(
251: "org.eclipse.ui.bindings", true); //$NON-NLS-1$
252:
253: IPluginElement element = model.getPluginFactory()
254: .createElement(extension);
255: element.setName("key"); //$NON-NLS-1$
256: element.setAttribute("commandId", id + ".open"); //$NON-NLS-1$ //$NON-NLS-2$
257: element.setAttribute("sequence", "CTRL+2"); //$NON-NLS-1$ //$NON-NLS-2$
258: element
259: .setAttribute(
260: "schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
261: extension.add(element);
262:
263: element = model.getPluginFactory().createElement(extension);
264: element.setName("key"); //$NON-NLS-1$
265: element.setAttribute("commandId", id + ".openMessage"); //$NON-NLS-1$ //$NON-NLS-2$
266: element.setAttribute("sequence", "CTRL+3"); //$NON-NLS-1$ //$NON-NLS-2$
267: element
268: .setAttribute(
269: "schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
270: extension.add(element);
271:
272: element = model.getPluginFactory().createElement(extension);
273: element.setName("key"); //$NON-NLS-1$
274: element.setAttribute("commandId", "org.eclipse.ui.file.exit"); //$NON-NLS-1$ //$NON-NLS-2$
275: element.setAttribute("sequence", "CTRL+X"); //$NON-NLS-1$ //$NON-NLS-2$
276: element
277: .setAttribute(
278: "schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$
279: extension.add(element);
280:
281: if (!extension.isInTheModel())
282: plugin.add(extension);
283: }
284:
285: private void createProductExtension() throws CoreException {
286: IPluginBase plugin = model.getPluginBase();
287: IPluginExtension extension = createExtension(
288: "org.eclipse.core.runtime.products", true); //$NON-NLS-1$
289: extension.setId(VALUE_PRODUCT_ID);
290:
291: IPluginElement element = model.getFactory().createElement(
292: extension);
293: element.setName("product"); //$NON-NLS-1$
294: element.setAttribute("name", getStringOption(KEY_PRODUCT_NAME)); //$NON-NLS-1$
295: element
296: .setAttribute(
297: "application", plugin.getId() + "." + VALUE_APPLICATION_ID); //$NON-NLS-1$ //$NON-NLS-2$
298:
299: IPluginElement property = model.getFactory().createElement(
300: element);
301: property.setName("property"); //$NON-NLS-1$
302: property.setAttribute("name", "aboutText"); //$NON-NLS-1$ //$NON-NLS-2$
303: property.setAttribute(
304: "value", "RCP Mail template created by PDE"); //$NON-NLS-1$ //$NON-NLS-2$
305: element.add(property);
306:
307: property = model.getFactory().createElement(element);
308: property.setName("property"); //$NON-NLS-1$
309: property.setAttribute("name", "windowImages"); //$NON-NLS-1$ //$NON-NLS-2$
310: property.setAttribute("value", "icons/sample2.gif"); //$NON-NLS-1$ //$NON-NLS-2$
311: element.add(property);
312:
313: property = model.getFactory().createElement(element);
314: property.setName("property"); //$NON-NLS-1$
315: property.setAttribute("name", "aboutImage"); //$NON-NLS-1$ //$NON-NLS-2$
316: property.setAttribute("value", "product_lg.gif"); //$NON-NLS-1$ //$NON-NLS-2$
317: element.add(property);
318:
319: extension.add(element);
320:
321: if (!extension.isInTheModel()) {
322: plugin.add(extension);
323: }
324:
325: }
326:
327: /* (non-Javadoc)
328: * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
329: */
330: public String getUsedExtensionPoint() {
331: return null;
332: }
333:
334: /* (non-Javadoc)
335: * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
336: */
337: public boolean isDependentOnParentWizard() {
338: return true;
339: }
340:
341: /* (non-Javadoc)
342: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
343: */
344: public int getNumberOfWorkUnits() {
345: return super .getNumberOfWorkUnits() + 1;
346: }
347:
348: /* (non-Javadoc)
349: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
350: */
351: public IPluginReference[] getDependencies(String schemaVersion) {
352: IPluginReference[] dep = new IPluginReference[2];
353: dep[0] = new PluginReference(
354: "org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
355: dep[1] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
356: return dep;
357: }
358:
359: /* (non-Javadoc)
360: * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getNewFiles()
361: */
362: public String[] getNewFiles() {
363: return new String[] { "icons/", "product_lg.gif", "splash.bmp" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
364: }
365:
366: /* (non-Javadoc)
367: * @see org.eclipse.pde.internal.ui.templates.PDETemplateSection#copyBrandingDirectory()
368: */
369: protected boolean copyBrandingDirectory() {
370: return true;
371: }
372:
373: }
|