001: /*******************************************************************************
002: * Copyright (c) 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.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.PDETemplateSection;
025: import org.eclipse.pde.internal.ui.templates.PluginReference;
026: import org.eclipse.pde.ui.IFieldData;
027:
028: public class PerspectiveTemplate extends PDETemplateSection {
029: public static final String PERSPECTIVE_CLASS_NAME = "perspectiveClassName"; //$NON-NLS-1$
030: public static final String PERSPECTIVE_NAME = "perspectiveCategoryName"; //$NON-NLS-1$
031:
032: public static final String BLN_PERSPECTIVE_SHORTS = "perspectiveShortcuts"; //$NON-NLS-1$
033: public static final String BLN_NEW_WIZARD_SHORTS = "newWizardShortcuts"; //$NON-NLS-1$
034: public static final String BLN_SHOW_VIEW_SHORTS = "showViewShortcuts"; //$NON-NLS-1$
035: public static final String BLN_ACTION_SETS = "actionSets"; //$NON-NLS-1$
036:
037: private WizardPage page;
038:
039: /**
040: * Constructor for PerspectiveTemplate.
041: */
042: public PerspectiveTemplate() {
043: setPageCount(1);
044: createOptions();
045: }
046:
047: /* (non-Javadoc)
048: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
049: */
050: public IPluginReference[] getDependencies(String schemaVersion) {
051: // Additional dependencies required
052: if (schemaVersion != null) {
053: IPluginReference[] dep = new IPluginReference[2];
054: dep[0] = new PluginReference(
055: "org.eclipse.ui.console", null, 0); //$NON-NLS-1$
056: dep[1] = new PluginReference("org.eclipse.jdt.ui", null, 0); //$NON-NLS-1$
057: return dep;
058: }
059: return super .getDependencies(schemaVersion);
060: }
061:
062: /* (non-Javadoc)
063: * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
064: * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getDirectoryCandidates()
065: */
066: public String getSectionId() {
067: return "perspective"; //$NON-NLS-1$
068: }
069:
070: /* (non-Javadoc)
071: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
072: */
073: public int getNumberOfWorkUnits() {
074: return super .getNumberOfWorkUnits() + 1;
075: }
076:
077: /**
078: * Creates the options to be displayed on the template wizard.
079: * Various string options, blank fields and a multiple choice
080: * option are used.
081: */
082: private void createOptions() {
083: addOption(KEY_PACKAGE_NAME,
084: PDETemplateMessages.PerspectiveTemplate_packageName,
085: (String) null, 0);
086: addOption(
087: PERSPECTIVE_CLASS_NAME,
088: PDETemplateMessages.PerspectiveTemplate_perspectiveClass,
089: PDETemplateMessages.PerspectiveTemplate_perspectiveClassName,
090: 0);
091: addOption(
092: PERSPECTIVE_NAME,
093: PDETemplateMessages.PerspectiveTemplate_perspective,
094: PDETemplateMessages.PerspectiveTemplate_perspectiveName,
095: 0);
096:
097: addBlankField(0);
098:
099: addOption(
100: BLN_PERSPECTIVE_SHORTS,
101: PDETemplateMessages.PerspectiveTemplate_perspectiveShortcuts,
102: true, 0);
103: addOption(
104: BLN_SHOW_VIEW_SHORTS,
105: PDETemplateMessages.PerspectiveTemplate_showViewShortcuts,
106: true, 0);
107: addOption(
108: BLN_NEW_WIZARD_SHORTS,
109: PDETemplateMessages.PerspectiveTemplate_newWizardShortcuts,
110: true, 0);
111: addOption(BLN_ACTION_SETS,
112: PDETemplateMessages.PerspectiveTemplate_actionSets,
113: true, 0);
114: }
115:
116: /* (non-Javadoc)
117: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#addPages(org.eclipse.jface.wizard.Wizard)
118: */
119: public void addPages(Wizard wizard) {
120: int pageIndex = 0;
121:
122: page = createPage(pageIndex, IHelpContextIds.TEMPLATE_EDITOR);
123: page.setTitle(PDETemplateMessages.PerspectiveTemplate_title);
124: page
125: .setDescription(PDETemplateMessages.PerspectiveTemplate_desc);
126:
127: wizard.addPage(page);
128: markPagesAdded();
129: }
130:
131: /* (non-Javadoc)
132: * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
133: */
134: public boolean isDependentOnParentWizard() {
135: return true;
136: }
137:
138: /* (non-Javadoc)
139: * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#initializeFields(org.eclipse.pde.ui.IFieldData)
140: */
141: protected void initializeFields(IFieldData data) {
142: // In a new project wizard, we don't know this yet - the
143: // model has not been created
144: String id = data.getId();
145: initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
146: }
147:
148: /* (non-Javadoc)
149: * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#initializeFields(org.eclipse.pde.core.plugin.IPluginModelBase)
150: */
151: public void initializeFields(IPluginModelBase model) {
152: // In the new extension wizard, the model exists so
153: // we can initialize directly from it
154: String pluginId = model.getPluginBase().getId();
155: initializeOption(KEY_PACKAGE_NAME,
156: getFormattedPackageName(pluginId));
157: }
158:
159: /* (non-Javadoc)
160: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
161: */
162: protected void updateModel(IProgressMonitor monitor)
163: throws CoreException {
164: // This method creates the extension point structure through the use
165: // of IPluginElement objects. The element attributes are set based on
166: // user input from the wizard page as well as values required for the
167: // operation of the extension point.
168: IPluginBase plugin = model.getPluginBase();
169: IPluginExtension extension = createExtension(
170: getUsedExtensionPoint(), true);
171: IPluginModelFactory factory = model.getPluginFactory();
172:
173: IPluginElement perspectiveElement = factory
174: .createElement(extension);
175: perspectiveElement.setName("perspective"); //$NON-NLS-1$
176: perspectiveElement
177: .setAttribute(
178: "id", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(PERSPECTIVE_CLASS_NAME)); //$NON-NLS-1$ //$NON-NLS-2$
179: perspectiveElement.setAttribute(
180: "name", getStringOption(PERSPECTIVE_NAME)); //$NON-NLS-1$
181: perspectiveElement
182: .setAttribute(
183: "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(PERSPECTIVE_CLASS_NAME)); //$NON-NLS-1$ //$NON-NLS-2$
184: perspectiveElement.setAttribute(
185: "icon", "icons/releng_gears.gif"); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
186:
187: extension.add(perspectiveElement);
188: if (!extension.isInTheModel())
189: plugin.add(extension);
190: }
191:
192: /* (non-Javadoc)
193: * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getNewFiles()
194: */
195: public String[] getNewFiles() {
196: return new String[] { "icons/" }; //$NON-NLS-1$
197: }
198:
199: /* (non-Javadoc)
200: * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getFormattedPackageName(java.lang.String)
201: */
202: protected String getFormattedPackageName(String id) {
203: // Package name addition to create a location for containing
204: // any classes required by the decorator.
205: String packageName = super .getFormattedPackageName(id);
206: if (packageName.length() != 0)
207: return packageName + ".perspectives"; //$NON-NLS-1$
208: return "perspectives"; //$NON-NLS-1$
209: }
210:
211: /* (non-Javadoc)
212: * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
213: */
214: public String getUsedExtensionPoint() {
215: return "org.eclipse.ui.perspectives"; //$NON-NLS-1$
216: }
217: }
|