KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > templates > ide > UniversalWelcomeTemplate


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.templates.ide;
13
14 import java.io.File JavaDoc;
15 import java.util.ArrayList JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.wizard.Wizard;
20 import org.eclipse.jface.wizard.WizardPage;
21 import org.eclipse.pde.core.plugin.IPluginBase;
22 import org.eclipse.pde.core.plugin.IPluginElement;
23 import org.eclipse.pde.core.plugin.IPluginExtension;
24 import org.eclipse.pde.core.plugin.IPluginModelBase;
25 import org.eclipse.pde.core.plugin.IPluginReference;
26 import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
27 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
28 import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
29 import org.eclipse.pde.internal.ui.templates.PluginReference;
30 import org.eclipse.pde.ui.IFieldData;
31
32 /**
33  * Creates a template for contributing to the Universal Welcome
34  * intro. Requires Eclipse version 3.2.
35  *
36  * @since 3.2
37  */

38
39 public class UniversalWelcomeTemplate extends PDETemplateSection {
40     private static final String JavaDoc KEY_LINK_ID = "linkId"; //$NON-NLS-1$
41

42     private static final String JavaDoc KEY_EXTENSION_ID = "extensionId"; //$NON-NLS-1$
43

44     private static final String JavaDoc KEY_INTRO_DIR = "introDir"; //$NON-NLS-1$
45

46     private static final String JavaDoc KEY_PATH = "path"; //$NON-NLS-1$
47

48     private static final String JavaDoc KEY_LINK_URL = "linkUrl"; //$NON-NLS-1$
49

50     private String JavaDoc pluginId;
51
52     public UniversalWelcomeTemplate() {
53         setPageCount(1);
54         createOptions();
55     }
56
57     private void createOptions() {
58         // options
59
addOption(KEY_INTRO_DIR, PDETemplateMessages.UniversalWelcomeTemplate_key_directoryName, "intro", 0); //$NON-NLS-1$
60
addOption(KEY_PATH, PDETemplateMessages.UniversalWelcomeTemplate_key_targetPage, new String JavaDoc[][] {
61                 { "overview/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Overview }, { "tutorials/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Tutorials }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
62
{ "firststeps/@", PDETemplateMessages.UniversalWelcomeTemplate_page_FirstSteps }, { "samples/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Samples }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
63
{ "whatsnew/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Whatsnew }, { "migrate/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Migrate }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
64
{ "webresources/@", PDETemplateMessages.UniversalWelcomeTemplate_page_WebResources } }, "overview/@", 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
65
addOption(KEY_LINK_URL, PDETemplateMessages.UniversalWelcomeTemplate_linkUrl, "http://www.eclipse.org", 0); //$NON-NLS-1$
66
}
67
68     public void addPages(Wizard wizard) {
69         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_UNIVERSAL_WELCOME);
70         page.setTitle(PDETemplateMessages.IntroTemplate_title);
71         page.setDescription(PDETemplateMessages.IntroTemplate_desc);
72         wizard.addPage(page);
73         markPagesAdded();
74     }
75
76     public boolean isDependentOnParentWizard() {
77         return true;
78     }
79
80     public String JavaDoc getSectionId() {
81         return "universalWelcome"; //$NON-NLS-1$
82
}
83
84     protected void initializeFields(IFieldData data) {
85         // In a new project wizard, we don't know this yet - the
86
// model has not been created
87
pluginId = data.getId();
88     }
89
90     public void initializeFields(IPluginModelBase model) {
91         pluginId = model.getPluginBase().getId();
92     }
93
94     protected void updateModel(IProgressMonitor monitor) throws CoreException {
95         IPluginBase plugin = model.getPluginBase();
96
97         IPluginExtension extension = createExtension(
98                 "org.eclipse.ui.intro.configExtension", false); //$NON-NLS-1$
99

100         IPluginElement element = model.getPluginFactory().createElement(
101                 extension);
102         element.setName("configExtension"); //$NON-NLS-1$
103
element
104                 .setAttribute("configId", //$NON-NLS-1$
105
"org.eclipse.ui.intro.universalConfig"); //$NON-NLS-1$
106
element.setAttribute("content", getStringOption(KEY_INTRO_DIR) //$NON-NLS-1$
107
+ "/sample.xml"); //$NON-NLS-1$
108
extension.add(element);
109
110         if (!extension.isInTheModel())
111             plugin.add(extension);
112     }
113
114     protected boolean isOkToCreateFolder(File JavaDoc sourceFolder) {
115         return true;
116     }
117
118     /**
119      * @see AbstractTemplateSection#isOkToCreateFile(File)
120      */

121     protected boolean isOkToCreateFile(File JavaDoc sourceFile) {
122         return true;
123     }
124
125     public String JavaDoc getUsedExtensionPoint() {
126         return "org.eclipse.ui.intro.configExtension"; //$NON-NLS-1$
127
}
128
129     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
130         ArrayList JavaDoc result = new ArrayList JavaDoc();
131
132         // We really need Eclipse 3.2 or higher but since Universal
133
// appears in 3.2 for the first time, just depending on
134
// its presence has the same effect.
135
result.add(new PluginReference("org.eclipse.ui.intro", null, 0)); //$NON-NLS-1$
136
result.add(new PluginReference(
137                 "org.eclipse.ui.intro.universal", null, 0)); //$NON-NLS-1$
138
result.add(new PluginReference("org.eclipse.ui", null, 0)); //$NON-NLS-1$
139

140         return (IPluginReference[]) result.toArray(new IPluginReference[result
141                 .size()]);
142     }
143
144     public int getNumberOfWorkUnits() {
145         return super.getNumberOfWorkUnits() + 1;
146     }
147
148     /*
149      * We are going to compute some values even though we are
150      * not exposing them as options.
151      */

152     public String JavaDoc getStringOption(String JavaDoc name) {
153         if (name.equals(KEY_EXTENSION_ID)) {
154             return stripNonAlphanumeric(pluginId) + "-introExtension"; //$NON-NLS-1$
155
}
156         if (name.equals(KEY_LINK_ID)) {
157             return stripNonAlphanumeric(pluginId) + "-introLink"; //$NON-NLS-1$
158
}
159         return super.getStringOption(name);
160     }
161
162     /*
163      * Strips any non alphanumeric characters from the string so as not to break the css
164      */

165     private String JavaDoc stripNonAlphanumeric(String JavaDoc id) {
166         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
167         for (int i = 0; i < id.length(); i++) {
168             char next = id.charAt(i);
169             if (Character.isLetterOrDigit(next)) {
170                 result.append(next);
171             }
172         }
173         return result.toString();
174     }
175
176     public String JavaDoc[] getNewFiles() {
177         return new String JavaDoc[] { getStringOption(KEY_INTRO_DIR) + "/" }; //$NON-NLS-1$
178
}
179 }
Popular Tags