001: /*******************************************************************************
002: * Copyright (c) 2000, 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.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.ui.IFieldData;
025:
026: public class HelloWorldTemplate extends PDETemplateSection {
027: public static final String KEY_CLASS_NAME = "className"; //$NON-NLS-1$
028: public static final String KEY_MESSAGE = "message"; //$NON-NLS-1$
029: public static final String CLASS_NAME = "SampleAction"; //$NON-NLS-1$
030:
031: /**
032: * Constructor for HelloWorldTemplate.
033: */
034: public HelloWorldTemplate() {
035: setPageCount(1);
036: createOptions();
037: }
038:
039: public String getSectionId() {
040: return "helloWorld"; //$NON-NLS-1$
041: }
042:
043: /*
044: * @see ITemplateSection#getNumberOfWorkUnits()
045: */
046: public int getNumberOfWorkUnits() {
047: return super .getNumberOfWorkUnits() + 1;
048: }
049:
050: private void createOptions() {
051: addOption(KEY_PACKAGE_NAME,
052: PDETemplateMessages.HelloWorldTemplate_packageName,
053: (String) null, 0);
054: addOption(KEY_CLASS_NAME,
055: PDETemplateMessages.HelloWorldTemplate_className,
056: CLASS_NAME, 0);
057: addOption(KEY_MESSAGE,
058: PDETemplateMessages.HelloWorldTemplate_messageText,
059: PDETemplateMessages.HelloWorldTemplate_defaultMessage,
060: 0);
061: }
062:
063: public void addPages(Wizard wizard) {
064: WizardPage page = createPage(0,
065: IHelpContextIds.TEMPLATE_HELLO_WORLD);
066: page.setTitle(PDETemplateMessages.HelloWorldTemplate_title);
067: page
068: .setDescription(PDETemplateMessages.HelloWorldTemplate_desc);
069: wizard.addPage(page);
070: markPagesAdded();
071: }
072:
073: public boolean isDependentOnParentWizard() {
074: return true;
075: }
076:
077: protected void initializeFields(IFieldData data) {
078: // In a new project wizard, we don't know this yet - the
079: // model has not been created
080: String id = data.getId();
081: initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
082: }
083:
084: public void initializeFields(IPluginModelBase model) {
085: // In the new extension wizard, the model exists so
086: // we can initialize directly from it
087: String pluginId = model.getPluginBase().getId();
088: initializeOption(KEY_PACKAGE_NAME,
089: getFormattedPackageName(pluginId));
090: }
091:
092: public String getUsedExtensionPoint() {
093: return "org.eclipse.ui.actionSets"; //$NON-NLS-1$
094: }
095:
096: protected void updateModel(IProgressMonitor monitor)
097: throws CoreException {
098: IPluginBase plugin = model.getPluginBase();
099: IPluginExtension extension = createExtension(
100: "org.eclipse.ui.actionSets", true); //$NON-NLS-1$
101: IPluginModelFactory factory = model.getPluginFactory();
102:
103: IPluginElement setElement = factory.createElement(extension);
104: setElement.setName("actionSet"); //$NON-NLS-1$
105: setElement.setAttribute("id", plugin.getId() + ".actionSet"); //$NON-NLS-1$ //$NON-NLS-2$
106: setElement
107: .setAttribute(
108: "label", PDETemplateMessages.HelloWorldTemplate_sampleActionSet); //$NON-NLS-1$
109: setElement.setAttribute("visible", "true"); //$NON-NLS-1$ //$NON-NLS-2$
110:
111: IPluginElement menuElement = factory.createElement(setElement);
112: menuElement.setName("menu"); //$NON-NLS-1$
113: menuElement
114: .setAttribute(
115: "label", PDETemplateMessages.HelloWorldTemplate_sampleMenu); //$NON-NLS-1$
116: menuElement.setAttribute("id", "sampleMenu"); //$NON-NLS-1$ //$NON-NLS-2$
117:
118: IPluginElement groupElement = factory
119: .createElement(menuElement);
120: groupElement.setName("separator"); //$NON-NLS-1$
121: groupElement.setAttribute("name", "sampleGroup"); //$NON-NLS-1$ //$NON-NLS-2$
122: menuElement.add(groupElement);
123: setElement.add(menuElement);
124:
125: String fullClassName = getStringOption(KEY_PACKAGE_NAME)
126: + "." + getStringOption(KEY_CLASS_NAME); //$NON-NLS-1$
127:
128: IPluginElement actionElement = factory
129: .createElement(setElement);
130: actionElement.setName("action"); //$NON-NLS-1$
131: actionElement.setAttribute("id", fullClassName); //$NON-NLS-1$
132: actionElement
133: .setAttribute(
134: "label", PDETemplateMessages.HelloWorldTemplate_sampleAction); //$NON-NLS-1$
135: actionElement.setAttribute(
136: "menubarPath", "sampleMenu/sampleGroup"); //$NON-NLS-1$ //$NON-NLS-2$
137: actionElement.setAttribute("toolbarPath", "sampleGroup"); //$NON-NLS-1$ //$NON-NLS-2$
138: actionElement.setAttribute("icon", "icons/sample.gif"); //$NON-NLS-1$ //$NON-NLS-2$
139: actionElement
140: .setAttribute(
141: "tooltip", PDETemplateMessages.HelloWorldTemplate_defaultMessage); //$NON-NLS-1$
142: actionElement.setAttribute("class", fullClassName); //$NON-NLS-1$
143: setElement.add(actionElement);
144: extension.add(setElement);
145: if (!extension.isInTheModel())
146: plugin.add(extension);
147: }
148:
149: /* (non-Javadoc)
150: * @see org.eclipse.pde.ui.templates.ITemplateSection#getFoldersToInclude()
151: */
152: public String[] getNewFiles() {
153: return new String[] { "icons/" }; //$NON-NLS-1$
154: }
155:
156: /* (non-Javadoc)
157: * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#formatPackageName(java.lang.String)
158: */
159: protected String getFormattedPackageName(String id) {
160: String packageName = super .getFormattedPackageName(id);
161: if (packageName.length() != 0)
162: return packageName + ".actions"; //$NON-NLS-1$
163: return "actions"; //$NON-NLS-1$
164: }
165: }
|