KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2006 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.wizards.templates;
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.IHelpContextIds;
27 import org.eclipse.pde.internal.ui.PDEUIMessages;
28 import org.eclipse.pde.ui.IFieldData;
29 import org.eclipse.pde.ui.templates.TemplateOption;
30
31 /**
32  * Creates a template for contributing to the Universal Welcome
33  * intro. Requires Eclipse version 3.2.
34  *
35  * @since 3.2
36  */

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

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

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

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

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

49     private String JavaDoc pluginId;
50
51     public UniversalWelcomeTemplate() {
52         setPageCount(1);
53         createOptions();
54     }
55
56     private void createOptions() {
57         // options
58
addOption(KEY_INTRO_DIR, PDEUIMessages.UniversalWelcomeTemplate_key_directoryName, "intro", 0); //$NON-NLS-1$
59
addOption(KEY_PATH, PDEUIMessages.UniversalWelcomeTemplate_key_targetPage, new String JavaDoc[][] {
60                 { "overview/@", PDEUIMessages.UniversalWelcomeTemplate_page_Overview }, { "tutorials/@", PDEUIMessages.UniversalWelcomeTemplate_page_Tutorials }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
61
{ "firststeps/@", PDEUIMessages.UniversalWelcomeTemplate_page_FirstSteps }, { "samples/@", PDEUIMessages.UniversalWelcomeTemplate_page_Samples }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
62
{ "whatsnew/@", PDEUIMessages.UniversalWelcomeTemplate_page_Whatsnew }, { "migrate/@", PDEUIMessages.UniversalWelcomeTemplate_page_Migrate }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
63
{ "webresources/@", PDEUIMessages.UniversalWelcomeTemplate_page_WebResources } }, "overview/@", 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
64
addOption(KEY_LINK_URL, PDEUIMessages.UniversalWelcomeTemplate_linkUrl, "http://www.eclipse.org", 0); //$NON-NLS-1$
65
}
66
67     public void addPages(Wizard wizard) {
68         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_UNIVERSAL_WELCOME);
69         page.setTitle(PDEUIMessages.IntroTemplate_title);
70         page.setDescription(PDEUIMessages.IntroTemplate_desc);
71         wizard.addPage(page);
72         markPagesAdded();
73     }
74
75     public boolean isDependentOnParentWizard() {
76         return true;
77     }
78
79     public String JavaDoc getSectionId() {
80         return "universalWelcome"; //$NON-NLS-1$
81
}
82
83     protected void initializeFields(IFieldData data) {
84         // In a new project wizard, we don't know this yet - the
85
// model has not been created
86
pluginId = data.getId();
87     }
88
89     public void initializeFields(IPluginModelBase model) {
90         pluginId = model.getPluginBase().getId();
91     }
92
93     public void validateOptions(TemplateOption source) {
94
95         if (source.isRequired() && source.isEmpty()) {
96             flagMissingRequiredOption(source);
97         } else {
98             validateContainerPage(source);
99         }
100     }
101
102     private void validateContainerPage(TemplateOption source) {
103         TemplateOption[] allPageOptions = getOptions(0);
104         for (int i = 0; i < allPageOptions.length; i++) {
105             TemplateOption nextOption = allPageOptions[i];
106             if (nextOption.isRequired() && nextOption.isEmpty()) {
107                 flagMissingRequiredOption(nextOption);
108                 return;
109             }
110         }
111         resetPageState();
112     }
113
114     protected void updateModel(IProgressMonitor monitor) throws CoreException {
115         IPluginBase plugin = model.getPluginBase();
116
117         IPluginExtension extension = createExtension(
118                 "org.eclipse.ui.intro.configExtension", false); //$NON-NLS-1$
119

120         IPluginElement element = model.getPluginFactory().createElement(
121                 extension);
122         element.setName("configExtension"); //$NON-NLS-1$
123
element
124                 .setAttribute("configId", //$NON-NLS-1$
125
"org.eclipse.ui.intro.universalConfig"); //$NON-NLS-1$
126
element.setAttribute("content", getStringOption(KEY_INTRO_DIR) //$NON-NLS-1$
127
+ "/sample.xml"); //$NON-NLS-1$
128
extension.add(element);
129
130         if (!extension.isInTheModel())
131             plugin.add(extension);
132     }
133
134     protected boolean isOkToCreateFolder(File JavaDoc sourceFolder) {
135         return true;
136     }
137
138     /**
139      * @see AbstractTemplateSection#isOkToCreateFile(File)
140      */

141     protected boolean isOkToCreateFile(File JavaDoc sourceFile) {
142         return true;
143     }
144
145     public String JavaDoc getUsedExtensionPoint() {
146         return "org.eclipse.ui.intro.configExtension"; //$NON-NLS-1$
147
}
148
149     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
150         ArrayList JavaDoc result = new ArrayList JavaDoc();
151
152         // We really need Eclipse 3.2 or higher but since Universal
153
// appears in 3.2 for the first time, just depending on
154
// its presence has the same effect.
155
result.add(new PluginReference("org.eclipse.ui.intro", null, 0)); //$NON-NLS-1$
156
result.add(new PluginReference(
157                 "org.eclipse.ui.intro.universal", null, 0)); //$NON-NLS-1$
158
result.add(new PluginReference("org.eclipse.ui", null, 0)); //$NON-NLS-1$
159

160         return (IPluginReference[]) result.toArray(new IPluginReference[result
161                 .size()]);
162     }
163
164     public int getNumberOfWorkUnits() {
165         return super.getNumberOfWorkUnits() + 1;
166     }
167
168     /*
169      * We are going to compute some values even though we are
170      * not exposing them as options.
171      */

172     public String JavaDoc getStringOption(String JavaDoc name) {
173         if (name.equals(KEY_EXTENSION_ID)) {
174             return pluginId + ".introExtension"; //$NON-NLS-1$
175
}
176         if (name.equals(KEY_LINK_ID)) {
177             return pluginId + "-introLink"; //$NON-NLS-1$
178
}
179         return super.getStringOption(name);
180     }
181
182     public String JavaDoc[] getNewFiles() {
183         return new String JavaDoc[] { getStringOption(KEY_INTRO_DIR) + "/" }; //$NON-NLS-1$
184
}
185 }
Popular Tags