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 ViewRCPTemplate extends PDETemplateSection {
028:
029: public static final String KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$
030: public static final String KEY_WINDOW_TITLE = "windowTitle"; //$NON-NLS-1$
031:
032: public ViewRCPTemplate() {
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.ViewRCPTemplate_title);
041: page.setDescription(PDETemplateMessages.ViewRCPTemplate_desc);
042: wizard.addPage(page);
043: markPagesAdded();
044: }
045:
046: private void createOptions() {
047: addOption(KEY_WINDOW_TITLE,
048: PDETemplateMessages.ViewRCPTemplate_windowTitle,
049: "RCP Application", 0); //$NON-NLS-1$
050:
051: addOption(KEY_PACKAGE_NAME,
052: PDETemplateMessages.ViewRCPTemplate_packageName,
053: (String) null, 0);
054:
055: addOption(KEY_APPLICATION_CLASS,
056: PDETemplateMessages.ViewRCPTemplate_appClass,
057: "Application", 0); //$NON-NLS-1$
058:
059: createBrandingOptions();
060: }
061:
062: protected void initializeFields(IFieldData data) {
063: // In a new project wizard, we don't know this yet - the
064: // model has not been created
065: String id = data.getId();
066: initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
067: }
068:
069: public void initializeFields(IPluginModelBase model) {
070: // In the new extension wizard, the model exists so
071: // we can initialize directly from it
072: String pluginId = model.getPluginBase().getId();
073: initializeOption(KEY_PACKAGE_NAME,
074: getFormattedPackageName(pluginId));
075: }
076:
077: /*
078: * (non-Javadoc)
079: *
080: * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
081: */
082: public String getSectionId() {
083: return "viewRCP"; //$NON-NLS-1$
084: }
085:
086: /* (non-Javadoc)
087: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
088: */
089: protected void updateModel(IProgressMonitor monitor)
090: throws CoreException {
091: createApplicationExtension();
092: createPerspectiveExtension();
093: createViewExtension();
094: if (getBooleanOption(KEY_PRODUCT_BRANDING))
095: createProductExtension();
096: }
097:
098: private void createApplicationExtension() throws CoreException {
099: IPluginBase plugin = model.getPluginBase();
100:
101: IPluginExtension extension = createExtension(
102: "org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
103: extension.setId(VALUE_APPLICATION_ID);
104:
105: IPluginElement element = model.getPluginFactory()
106: .createElement(extension);
107: element.setName("application"); //$NON-NLS-1$
108: extension.add(element);
109:
110: IPluginElement run = model.getPluginFactory().createElement(
111: element);
112: run.setName("run"); //$NON-NLS-1$
113: run
114: .setAttribute(
115: "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
116: element.add(run);
117:
118: if (!extension.isInTheModel())
119: plugin.add(extension);
120: }
121:
122: private void createPerspectiveExtension() throws CoreException {
123: IPluginBase plugin = model.getPluginBase();
124:
125: IPluginExtension extension = createExtension(
126: "org.eclipse.ui.perspectives", true); //$NON-NLS-1$
127: IPluginElement element = model.getPluginFactory()
128: .createElement(extension);
129: element.setName("perspective"); //$NON-NLS-1$
130: element
131: .setAttribute(
132: "class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
133: element.setAttribute("name", "Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
134: element.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$
135: extension.add(element);
136:
137: if (!extension.isInTheModel())
138: plugin.add(extension);
139: }
140:
141: private void createViewExtension() throws CoreException {
142: IPluginBase plugin = model.getPluginBase();
143: String id = plugin.getId();
144: IPluginExtension extension = createExtension(
145: "org.eclipse.ui.views", true); //$NON-NLS-1$
146:
147: IPluginElement view = model.getPluginFactory().createElement(
148: extension);
149: view.setName("view"); //$NON-NLS-1$
150: view.setAttribute(
151: "class", getStringOption(KEY_PACKAGE_NAME) + ".View"); //$NON-NLS-1$ //$NON-NLS-2$
152: view.setAttribute("name", "View"); //$NON-NLS-1$ //$NON-NLS-2$
153: view.setAttribute("id", id + ".view"); //$NON-NLS-1$ //$NON-NLS-2$
154: extension.add(view);
155:
156: if (!extension.isInTheModel())
157: plugin.add(extension);
158: }
159:
160: private void createProductExtension() throws CoreException {
161: IPluginBase plugin = model.getPluginBase();
162: IPluginExtension extension = createExtension(
163: "org.eclipse.core.runtime.products", true); //$NON-NLS-1$
164: extension.setId(VALUE_PRODUCT_ID);
165:
166: IPluginElement element = model.getFactory().createElement(
167: extension);
168: element.setName("product"); //$NON-NLS-1$
169: element.setAttribute("name", getStringOption(KEY_WINDOW_TITLE)); //$NON-NLS-1$
170: element
171: .setAttribute(
172: "application", plugin.getId() + "." + VALUE_APPLICATION_ID); //$NON-NLS-1$ //$NON-NLS-2$
173:
174: IPluginElement property = model.getFactory().createElement(
175: element);
176:
177: property = model.getFactory().createElement(element);
178: property.setName("property"); //$NON-NLS-1$
179: property.setAttribute("name", "windowImages"); //$NON-NLS-1$ //$NON-NLS-2$
180: property
181: .setAttribute(
182: "value", "icons/alt_window_16.gif,icons/alt_window_32.gif"); //$NON-NLS-1$ //$NON-NLS-2$
183: element.add(property);
184:
185: extension.add(element);
186:
187: if (!extension.isInTheModel())
188: plugin.add(extension);
189: }
190:
191: /*
192: * (non-Javadoc)
193: *
194: * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
195: */
196: public String getUsedExtensionPoint() {
197: return null;
198: }
199:
200: /* (non-Javadoc)
201: * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
202: */
203: public boolean isDependentOnParentWizard() {
204: return true;
205: }
206:
207: /* (non-Javadoc)
208: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
209: */
210: public int getNumberOfWorkUnits() {
211: return super .getNumberOfWorkUnits() + 1;
212: }
213:
214: /* (non-Javadoc)
215: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
216: */
217: public IPluginReference[] getDependencies(String schemaVersion) {
218: IPluginReference[] dep = new IPluginReference[2];
219: dep[0] = new PluginReference(
220: "org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
221: dep[1] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
222: return dep;
223: }
224:
225: /* (non-Javadoc)
226: * @see org.eclipse.pde.internal.ui.templates.PDETemplateSection#getNewFiles()
227: */
228: public String[] getNewFiles() {
229: if (copyBrandingDirectory())
230: return new String[] { "icons/", "splash.bmp" }; //$NON-NLS-1$ //$NON-NLS-2$
231: return super.getNewFiles();
232: }
233: }
|