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 HelloRCPTemplate 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 HelloRCPTemplate() {
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.HelloRCPTemplate_title);
041: page.setDescription(PDETemplateMessages.HelloRCPTemplate_desc);
042: wizard.addPage(page);
043: markPagesAdded();
044: }
045:
046: private void createOptions() {
047: addOption(KEY_WINDOW_TITLE,
048: PDETemplateMessages.HelloRCPTemplate_windowTitle,
049: "Hello RCP", 0); //$NON-NLS-1$
050:
051: addOption(KEY_PACKAGE_NAME,
052: PDETemplateMessages.MailTemplate_packageName,
053: (String) null, 0);
054:
055: addOption(KEY_APPLICATION_CLASS,
056: PDETemplateMessages.HelloRCPTemplate_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 packageName = getFormattedPackageName(data.getId());
066: initializeOption(KEY_PACKAGE_NAME, packageName);
067: }
068:
069: public void initializeFields(IPluginModelBase model) {
070: String packageName = getFormattedPackageName(model
071: .getPluginBase().getId());
072: initializeOption(KEY_PACKAGE_NAME, packageName);
073: }
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
079: */
080: public String getSectionId() {
081: return "helloRCP"; //$NON-NLS-1$
082: }
083:
084: /* (non-Javadoc)
085: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
086: */
087: protected void updateModel(IProgressMonitor monitor)
088: throws CoreException {
089: createApplicationExtension();
090: createPerspectiveExtension();
091: if (getBooleanOption(KEY_PRODUCT_BRANDING))
092: createProductExtension();
093: }
094:
095: private void createApplicationExtension() throws CoreException {
096: IPluginBase plugin = model.getPluginBase();
097:
098: IPluginExtension extension = createExtension(
099: "org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
100: extension.setId(VALUE_APPLICATION_ID);
101:
102: IPluginElement element = model.getPluginFactory()
103: .createElement(extension);
104: element.setName("application"); //$NON-NLS-1$
105: extension.add(element);
106:
107: IPluginElement run = model.getPluginFactory().createElement(
108: element);
109: run.setName("run"); //$NON-NLS-1$
110: run
111: .setAttribute(
112: "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
113: element.add(run);
114:
115: if (!extension.isInTheModel())
116: plugin.add(extension);
117: }
118:
119: private void createPerspectiveExtension() throws CoreException {
120: IPluginBase plugin = model.getPluginBase();
121:
122: IPluginExtension extension = createExtension(
123: "org.eclipse.ui.perspectives", true); //$NON-NLS-1$
124: IPluginElement element = model.getPluginFactory()
125: .createElement(extension);
126: element.setName("perspective"); //$NON-NLS-1$
127: element
128: .setAttribute(
129: "class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
130: element.setAttribute("name", VALUE_PERSPECTIVE_NAME); //$NON-NLS-1$
131: element.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$
132: extension.add(element);
133:
134: if (!extension.isInTheModel())
135: plugin.add(extension);
136: }
137:
138: private void createProductExtension() throws CoreException {
139: IPluginBase plugin = model.getPluginBase();
140: IPluginExtension extension = createExtension(
141: "org.eclipse.core.runtime.products", true); //$NON-NLS-1$
142: extension.setId(VALUE_PRODUCT_ID);
143:
144: IPluginElement element = model.getFactory().createElement(
145: extension);
146: element.setName("product"); //$NON-NLS-1$
147: element.setAttribute("name", getStringOption(KEY_WINDOW_TITLE)); //$NON-NLS-1$
148: element
149: .setAttribute(
150: "application", plugin.getId() + "." + VALUE_APPLICATION_ID); //$NON-NLS-1$ //$NON-NLS-2$
151:
152: IPluginElement property = model.getFactory().createElement(
153: element);
154:
155: property = model.getFactory().createElement(element);
156: property.setName("property"); //$NON-NLS-1$
157: property.setAttribute("name", "windowImages"); //$NON-NLS-1$ //$NON-NLS-2$
158: property
159: .setAttribute(
160: "value", "icons/alt_window_16.gif,icons/alt_window_32.gif"); //$NON-NLS-1$ //$NON-NLS-2$
161: element.add(property);
162:
163: extension.add(element);
164:
165: if (!extension.isInTheModel())
166: plugin.add(extension);
167: }
168:
169: /* (non-Javadoc)
170: * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
171: */
172: public String getUsedExtensionPoint() {
173: return null;
174: }
175:
176: /* (non-Javadoc)
177: * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
178: */
179: public boolean isDependentOnParentWizard() {
180: return true;
181: }
182:
183: /* (non-Javadoc)
184: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
185: */
186: public int getNumberOfWorkUnits() {
187: return super .getNumberOfWorkUnits() + 1;
188: }
189:
190: /* (non-Javadoc)
191: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
192: */
193: public IPluginReference[] getDependencies(String schemaVersion) {
194: IPluginReference[] dep = new IPluginReference[2];
195: dep[0] = new PluginReference(
196: "org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
197: dep[1] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
198: return dep;
199: }
200:
201: /* (non-Javadoc)
202: * @see org.eclipse.pde.internal.ui.templates.PDETemplateSection#getNewFiles()
203: */
204: public String[] getNewFiles() {
205: if (copyBrandingDirectory())
206: return new String[] { "icons/", "splash.bmp" }; //$NON-NLS-1$ //$NON-NLS-2$
207: return super.getNewFiles();
208: }
209: }
|