001: /*******************************************************************************
002: * Copyright (c) 2006, 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 java.io.File;
013: import java.util.ArrayList;
014:
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.core.runtime.IProgressMonitor;
017: import org.eclipse.jface.wizard.Wizard;
018: import org.eclipse.jface.wizard.WizardPage;
019: import org.eclipse.pde.core.plugin.IPluginBase;
020: import org.eclipse.pde.core.plugin.IPluginElement;
021: import org.eclipse.pde.core.plugin.IPluginExtension;
022: import org.eclipse.pde.core.plugin.IPluginModelBase;
023: import org.eclipse.pde.core.plugin.IPluginReference;
024: import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
025: import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
026: import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
027: import org.eclipse.pde.internal.ui.templates.PluginReference;
028: import org.eclipse.pde.ui.IFieldData;
029:
030: /**
031: * Creates a template for contributing to the Universal Welcome
032: * intro. Requires Eclipse version 3.2.
033: *
034: * @since 3.2
035: */
036:
037: public class UniversalWelcomeTemplate extends PDETemplateSection {
038: private static final String KEY_LINK_ID = "linkId"; //$NON-NLS-1$
039:
040: private static final String KEY_EXTENSION_ID = "extensionId"; //$NON-NLS-1$
041:
042: private static final String KEY_INTRO_DIR = "introDir"; //$NON-NLS-1$
043:
044: private static final String KEY_PATH = "path"; //$NON-NLS-1$
045:
046: private static final String KEY_LINK_URL = "linkUrl"; //$NON-NLS-1$
047:
048: private String pluginId;
049:
050: public UniversalWelcomeTemplate() {
051: setPageCount(1);
052: createOptions();
053: }
054:
055: private void createOptions() {
056: // options
057: addOption(
058: KEY_INTRO_DIR,
059: PDETemplateMessages.UniversalWelcomeTemplate_key_directoryName,
060: "intro", 0); //$NON-NLS-1$
061: addOption(
062: KEY_PATH,
063: PDETemplateMessages.UniversalWelcomeTemplate_key_targetPage,
064: new String[][] {
065: {
066: "overview/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Overview }, { "tutorials/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Tutorials }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
067: {
068: "firststeps/@", PDETemplateMessages.UniversalWelcomeTemplate_page_FirstSteps }, { "samples/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Samples }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
069: {
070: "whatsnew/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Whatsnew }, { "migrate/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Migrate }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
071: {
072: "webresources/@", PDETemplateMessages.UniversalWelcomeTemplate_page_WebResources } }, "overview/@", 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
073: addOption(KEY_LINK_URL,
074: PDETemplateMessages.UniversalWelcomeTemplate_linkUrl,
075: "http://www.eclipse.org", 0); //$NON-NLS-1$
076: }
077:
078: public void addPages(Wizard wizard) {
079: WizardPage page = createPage(0,
080: IHelpContextIds.TEMPLATE_UNIVERSAL_WELCOME);
081: page.setTitle(PDETemplateMessages.IntroTemplate_title);
082: page.setDescription(PDETemplateMessages.IntroTemplate_desc);
083: wizard.addPage(page);
084: markPagesAdded();
085: }
086:
087: public boolean isDependentOnParentWizard() {
088: return true;
089: }
090:
091: public String getSectionId() {
092: return "universalWelcome"; //$NON-NLS-1$
093: }
094:
095: protected void initializeFields(IFieldData data) {
096: // In a new project wizard, we don't know this yet - the
097: // model has not been created
098: pluginId = data.getId();
099: }
100:
101: public void initializeFields(IPluginModelBase model) {
102: pluginId = model.getPluginBase().getId();
103: }
104:
105: protected void updateModel(IProgressMonitor monitor)
106: throws CoreException {
107: IPluginBase plugin = model.getPluginBase();
108:
109: IPluginExtension extension = createExtension(
110: "org.eclipse.ui.intro.configExtension", false); //$NON-NLS-1$
111:
112: IPluginElement element = model.getPluginFactory()
113: .createElement(extension);
114: element.setName("configExtension"); //$NON-NLS-1$
115: element.setAttribute("configId", //$NON-NLS-1$
116: "org.eclipse.ui.intro.universalConfig"); //$NON-NLS-1$
117: element.setAttribute("content", getStringOption(KEY_INTRO_DIR) //$NON-NLS-1$
118: + "/sample.xml"); //$NON-NLS-1$
119: extension.add(element);
120:
121: if (!extension.isInTheModel())
122: plugin.add(extension);
123: }
124:
125: protected boolean isOkToCreateFolder(File sourceFolder) {
126: return true;
127: }
128:
129: /**
130: * @see AbstractTemplateSection#isOkToCreateFile(File)
131: */
132: protected boolean isOkToCreateFile(File sourceFile) {
133: return true;
134: }
135:
136: public String getUsedExtensionPoint() {
137: return "org.eclipse.ui.intro.configExtension"; //$NON-NLS-1$
138: }
139:
140: public IPluginReference[] getDependencies(String schemaVersion) {
141: ArrayList result = new ArrayList();
142:
143: // We really need Eclipse 3.2 or higher but since Universal
144: // appears in 3.2 for the first time, just depending on
145: // its presence has the same effect.
146: result
147: .add(new PluginReference(
148: "org.eclipse.ui.intro", null, 0)); //$NON-NLS-1$
149: result.add(new PluginReference(
150: "org.eclipse.ui.intro.universal", null, 0)); //$NON-NLS-1$
151: result.add(new PluginReference("org.eclipse.ui", null, 0)); //$NON-NLS-1$
152:
153: return (IPluginReference[]) result
154: .toArray(new IPluginReference[result.size()]);
155: }
156:
157: public int getNumberOfWorkUnits() {
158: return super .getNumberOfWorkUnits() + 1;
159: }
160:
161: /*
162: * We are going to compute some values even though we are
163: * not exposing them as options.
164: */
165: public String getStringOption(String name) {
166: if (name.equals(KEY_EXTENSION_ID)) {
167: return stripNonAlphanumeric(pluginId) + "-introExtension"; //$NON-NLS-1$
168: }
169: if (name.equals(KEY_LINK_ID)) {
170: return stripNonAlphanumeric(pluginId) + "-introLink"; //$NON-NLS-1$
171: }
172: return super .getStringOption(name);
173: }
174:
175: /*
176: * Strips any non alphanumeric characters from the string so as not to break the css
177: */
178: private String stripNonAlphanumeric(String id) {
179: StringBuffer result = new StringBuffer();
180: for (int i = 0; i < id.length(); i++) {
181: char next = id.charAt(i);
182: if (Character.isLetterOrDigit(next)) {
183: result.append(next);
184: }
185: }
186: return result.toString();
187: }
188:
189: public String[] getNewFiles() {
190: return new String[] { getStringOption(KEY_INTRO_DIR) + "/" }; //$NON-NLS-1$
191: }
192: }
|