001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 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 HelloNonUIRCPTemplate extends PDETemplateSection {
028:
029: public static final String KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$
030: public static final String KEY_APPLICATION_MESSAGE = "message"; //$NON-NLS-1$
031:
032: public HelloNonUIRCPTemplate() {
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.HelloNonUIRCPTemplate_title);
041: page
042: .setDescription(PDETemplateMessages.HelloNonUIRCPTemplate_desc);
043: wizard.addPage(page);
044: markPagesAdded();
045: }
046:
047: private void createOptions() {
048: addOption(KEY_PACKAGE_NAME,
049: PDETemplateMessages.MailTemplate_packageName,
050: (String) null, 0);
051:
052: addOption(KEY_APPLICATION_CLASS,
053: PDETemplateMessages.HelloNonUIRCPTemplate_appClass,
054: "Application", 0); //$NON-NLS-1$
055:
056: addOption(
057: KEY_APPLICATION_MESSAGE,
058: PDETemplateMessages.HelloNonUIRCPTemplate_messageText,
059: PDETemplateMessages.HelloNonUIRCPTemplate_defaultMessage,
060: 0);
061: }
062:
063: protected void initializeFields(IFieldData data) {
064: // In a new project wizard, we don't know this yet - the
065: // model has not been created
066: String packageName = getFormattedPackageName(data.getId());
067: initializeOption(KEY_PACKAGE_NAME, packageName);
068: }
069:
070: public void initializeFields(IPluginModelBase model) {
071: String packageName = getFormattedPackageName(model
072: .getPluginBase().getId());
073: initializeOption(KEY_PACKAGE_NAME, packageName);
074: }
075:
076: /*
077: * (non-Javadoc)
078: *
079: * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
080: */
081: public String getSectionId() {
082: return "helloNonUIRCP"; //$NON-NLS-1$
083: }
084:
085: /* (non-Javadoc)
086: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
087: */
088: protected void updateModel(IProgressMonitor monitor)
089: throws CoreException {
090: createApplicationExtension();
091: }
092:
093: private void createApplicationExtension() throws CoreException {
094: IPluginBase plugin = model.getPluginBase();
095:
096: IPluginExtension extension = createExtension(
097: "org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
098: extension.setId("application"); //$NON-NLS-1$
099:
100: IPluginElement element = model.getPluginFactory()
101: .createElement(extension);
102: element.setName("application"); //$NON-NLS-1$
103: extension.add(element);
104:
105: IPluginElement run = model.getPluginFactory().createElement(
106: element);
107: run.setName("run"); //$NON-NLS-1$
108: run
109: .setAttribute(
110: "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
111: element.add(run);
112:
113: if (!extension.isInTheModel())
114: plugin.add(extension);
115: }
116:
117: /* (non-Javadoc)
118: * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
119: */
120: public String getUsedExtensionPoint() {
121: return null;
122: }
123:
124: /* (non-Javadoc)
125: * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
126: */
127: public boolean isDependentOnParentWizard() {
128: return true;
129: }
130:
131: /* (non-Javadoc)
132: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
133: */
134: public int getNumberOfWorkUnits() {
135: return super .getNumberOfWorkUnits() + 1;
136: }
137:
138: /* (non-Javadoc)
139: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
140: */
141: public IPluginReference[] getDependencies(String schemaVersion) {
142: IPluginReference[] dep = new IPluginReference[1];
143: dep[0] = new PluginReference(
144: "org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
145: return dep;
146: }
147:
148: }
|