001: /*******************************************************************************
002: * Copyright (c) 2000, 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.ide;
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.IPluginModelFactory;
021: import org.eclipse.pde.core.plugin.IPluginReference;
022: import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
023: import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
024: import org.eclipse.pde.internal.ui.templates.PluginReference;
025: import org.eclipse.pde.ui.IFieldData;
026: import org.eclipse.pde.ui.templates.TemplateOption;
027:
028: public class MultiPageEditorTemplate extends BaseEditorTemplate {
029: /**
030: * Constructor for MultiPageEditorTemplate.
031: */
032: public MultiPageEditorTemplate() {
033: setPageCount(1);
034: createOptions();
035: }
036:
037: public String getSectionId() {
038: return "multiPageEditor"; //$NON-NLS-1$
039: }
040:
041: public IPluginReference[] getDependencies(String schemaVersion) {
042: if (schemaVersion != null) {
043: IPluginReference[] dep = new IPluginReference[6];
044: dep[0] = new PluginReference(
045: "org.eclipse.jface.text", null, 0); //$NON-NLS-1$
046: dep[1] = new PluginReference(
047: "org.eclipse.core.resources", null, 0); //$NON-NLS-1$
048: dep[2] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
049: dep[3] = new PluginReference(
050: "org.eclipse.ui.editors", null, 0); //$NON-NLS-1$
051: dep[4] = new PluginReference("org.eclipse.ui.ide", null, 0); //$NON-NLS-1$
052: dep[5] = new PluginReference(
053: "org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
054: return dep;
055: }
056: return super .getDependencies(schemaVersion);
057: }
058:
059: /*
060: * @see ITemplateSection#getNumberOfWorkUnits()
061: */
062: public int getNumberOfWorkUnits() {
063: return super .getNumberOfWorkUnits() + 1;
064: }
065:
066: private void createOptions() {
067: // first page
068: addOption(
069: KEY_PACKAGE_NAME,
070: PDETemplateMessages.MultiPageEditorTemplate_packageName,
071: (String) null, 0);
072: addOption(
073: "editorClassName", //$NON-NLS-1$
074: PDETemplateMessages.MultiPageEditorTemplate_className,
075: "MultiPageEditor", //$NON-NLS-1$
076: 0);
077: addOption(
078: "contributorClassName", //$NON-NLS-1$
079: PDETemplateMessages.MultiPageEditorTemplate_contributor,
080: "MultiPageEditorContributor", //$NON-NLS-1$
081: 0);
082: addOption(
083: "editorName", //$NON-NLS-1$
084: PDETemplateMessages.MultiPageEditorTemplate_editorName,
085: PDETemplateMessages.MultiPageEditorTemplate_defaultEditorName,
086: 0);
087: addOption(
088: "extensions", //$NON-NLS-1$
089: PDETemplateMessages.MultiPageEditorTemplate_extensions,
090: "mpe", //$NON-NLS-1$
091: 0);
092: }
093:
094: protected void initializeFields(IFieldData data) {
095: // In a new project wizard, we don't know this yet - the
096: // model has not been created
097: String id = data.getId();
098: initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
099: }
100:
101: public void initializeFields(IPluginModelBase model) {
102: // In the new extension wizard, the model exists so
103: // we can initialize directly from it
104: String pluginId = model.getPluginBase().getId();
105: initializeOption(KEY_PACKAGE_NAME,
106: getFormattedPackageName(pluginId));
107: }
108:
109: public boolean isDependentOnParentWizard() {
110: return true;
111: }
112:
113: public void addPages(Wizard wizard) {
114: WizardPage page = createPage(0,
115: IHelpContextIds.TEMPLATE_MULTIPAGE_EDITOR);
116: page
117: .setTitle(PDETemplateMessages.MultiPageEditorTemplate_title);
118: page
119: .setDescription(PDETemplateMessages.MultiPageEditorTemplate_desc);
120: wizard.addPage(page);
121: markPagesAdded();
122: }
123:
124: public void validateOptions(TemplateOption source) {
125: if (source.isRequired() && source.isEmpty()) {
126: flagMissingRequiredOption(source);
127: } else {
128: validateContainerPage(source);
129: }
130: }
131:
132: private void validateContainerPage(TemplateOption source) {
133: TemplateOption[] allPageOptions = getOptions(0);
134: for (int i = 0; i < allPageOptions.length; i++) {
135: TemplateOption nextOption = allPageOptions[i];
136: if (nextOption.isRequired() && nextOption.isEmpty()) {
137: flagMissingRequiredOption(nextOption);
138: return;
139: }
140: }
141: resetPageState();
142: }
143:
144: protected void updateModel(IProgressMonitor monitor)
145: throws CoreException {
146: IPluginBase plugin = model.getPluginBase();
147: IPluginExtension extension = createExtension(
148: "org.eclipse.ui.editors", true); //$NON-NLS-1$
149: IPluginModelFactory factory = model.getPluginFactory();
150:
151: String editorClassName = getStringOption(KEY_PACKAGE_NAME)
152: + "." + getStringOption("editorClassName"); //$NON-NLS-1$ //$NON-NLS-2$
153: String contributorClassName = getStringOption(KEY_PACKAGE_NAME)
154: + "." //$NON-NLS-1$
155: + getStringOption("contributorClassName"); //$NON-NLS-1$
156:
157: IPluginElement editorElement = factory.createElement(extension);
158: editorElement.setName("editor"); //$NON-NLS-1$
159: editorElement.setAttribute("id", editorClassName); //$NON-NLS-1$
160: editorElement.setAttribute(
161: "name", getStringOption("editorName")); //$NON-NLS-1$ //$NON-NLS-2$
162: editorElement.setAttribute("icon", "icons/sample.gif"); //$NON-NLS-1$ //$NON-NLS-2$
163: editorElement.setAttribute(
164: "extensions", getStringOption("extensions")); //$NON-NLS-1$ //$NON-NLS-2$
165:
166: editorElement.setAttribute("class", editorClassName); //$NON-NLS-1$
167: editorElement.setAttribute(
168: "contributorClass", contributorClassName); //$NON-NLS-1$
169: extension.add(editorElement);
170: if (!extension.isInTheModel())
171: plugin.add(extension);
172: }
173:
174: /* (non-Javadoc)
175: * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#formatPackageName(java.lang.String)
176: */
177: protected String getFormattedPackageName(String id) {
178: String packageName = super .getFormattedPackageName(id);
179: if (packageName.length() != 0)
180: return packageName + ".editors"; //$NON-NLS-1$
181: return "editors"; //$NON-NLS-1$
182: }
183:
184: }
|