KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.pde.internal.ui.templates.ide;
12
13 import java.io.File JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.jface.wizard.Wizard;
18 import org.eclipse.jface.wizard.WizardPage;
19 import org.eclipse.pde.core.plugin.IPluginBase;
20 import org.eclipse.pde.core.plugin.IPluginElement;
21 import org.eclipse.pde.core.plugin.IPluginExtension;
22 import org.eclipse.pde.core.plugin.IPluginModelFactory;
23 import org.eclipse.pde.core.plugin.IPluginReference;
24 import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
25 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
26 import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
27 import org.eclipse.pde.ui.templates.BooleanOption;
28 import org.eclipse.pde.ui.templates.TemplateOption;
29
30 public class HelpTemplate extends PDETemplateSection {
31     
32     public static final String JavaDoc KEY_TOC_LABEL = "tocLabel"; //$NON-NLS-1$
33
public static final String JavaDoc KEY_IS_PRIMARY = "isPrimary"; //$NON-NLS-1$
34
public static final String JavaDoc KEY_GEN_TEST = "generateTest"; //$NON-NLS-1$
35
public static final String JavaDoc KEY_GET_STARTED = "gettingStarted"; //$NON-NLS-1$
36
public static final String JavaDoc KEY_CONCEPTS = "concepts"; //$NON-NLS-1$
37
public static final String JavaDoc KEY_TASKS = "tasks"; //$NON-NLS-1$
38
public static final String JavaDoc KEY_REFERENCE = "reference"; //$NON-NLS-1$
39
public static final String JavaDoc KEY_SAMPLES = "samples"; //$NON-NLS-1$
40

41     private TemplateOption tocLabelOption;
42     private BooleanOption primaryOption;
43     private BooleanOption genTestOption;
44     private BooleanOption gettingStartedOption;
45     private BooleanOption conceptsOption;
46     private BooleanOption tasksOption;
47     private BooleanOption referenceOption;
48     private BooleanOption samplesOption;
49     
50     public HelpTemplate() {
51         setPageCount(1);
52         createOptions();
53         alterOptionStates();
54     }
55
56     public void addPages(Wizard wizard) {
57         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_HELP);
58         page.setTitle(PDETemplateMessages.HelpTemplate_title);
59         page.setDescription(PDETemplateMessages.HelpTemplate_desc);
60         wizard.addPage(page);
61         markPagesAdded();
62     }
63     
64     private void alterOptionStates() {
65         genTestOption.setEnabled(!primaryOption.isSelected());
66         gettingStartedOption.setEnabled(primaryOption.isSelected());
67         conceptsOption.setEnabled(primaryOption.isSelected());
68         tasksOption.setEnabled(primaryOption.isSelected());
69         referenceOption.setEnabled(primaryOption.isSelected());
70         samplesOption.setEnabled(primaryOption.isSelected());
71     }
72
73     private void createOptions() {
74         tocLabelOption = addOption(
75             KEY_TOC_LABEL,
76             PDETemplateMessages.HelpTemplate_tocLabel,
77             PDETemplateMessages.HelpTemplate_sampleText,
78             0);
79             
80         primaryOption = (BooleanOption)addOption(
81             KEY_IS_PRIMARY,
82             PDETemplateMessages.HelpTemplate_isPrimary,
83             false,
84             0);
85             
86         genTestOption = (BooleanOption)addOption(
87             KEY_GEN_TEST,
88             PDETemplateMessages.HelpTemplate_generateTest,
89             true,
90             0);
91
92         gettingStartedOption = (BooleanOption)addOption(
93             KEY_GET_STARTED,
94             PDETemplateMessages.HelpTemplate_gettingStarted,
95             true,
96             0);
97             
98         conceptsOption = (BooleanOption)addOption(
99             KEY_CONCEPTS,
100             PDETemplateMessages.HelpTemplate_concepts,
101             true,
102             0);
103             
104         tasksOption = (BooleanOption)addOption(
105             KEY_TASKS,
106             PDETemplateMessages.HelpTemplate_tasks,
107             true,
108             0);
109             
110         referenceOption = (BooleanOption)addOption(
111             KEY_REFERENCE,
112             PDETemplateMessages.HelpTemplate_reference,
113             true,
114             0);
115             
116         samplesOption = (BooleanOption)addOption(
117             KEY_SAMPLES,
118             PDETemplateMessages.HelpTemplate_samples,
119             true,
120             0);
121
122     }
123     /**
124      * @see OptionTemplateSection#getSectionId()
125      */

126     public String JavaDoc getSectionId() {
127         return "help"; //$NON-NLS-1$
128
}
129
130     protected boolean isOkToCreateFolder(File JavaDoc sourceFolder) {
131         boolean isOk = true;
132         String JavaDoc folderName = sourceFolder.getName();
133         if (folderName.equals("concepts")) { //$NON-NLS-1$
134
isOk = conceptsOption.isEnabled() && conceptsOption.isSelected();
135         } else if (folderName.equals("gettingstarted")) { //$NON-NLS-1$
136
isOk = gettingStartedOption.isEnabled() && gettingStartedOption.isSelected();
137         } else if (folderName.equals("reference")) { //$NON-NLS-1$
138
isOk = referenceOption.isEnabled() && referenceOption.isSelected();
139         } else if (folderName.equals("samples")) { //$NON-NLS-1$
140
isOk = samplesOption.isEnabled() && samplesOption.isSelected();
141         } else if (folderName.equals("tasks")) { //$NON-NLS-1$
142
isOk = tasksOption.isEnabled() && tasksOption.isSelected();
143         }
144         return isOk;
145     }
146     /**
147      * @see AbstractTemplateSection#isOkToCreateFile(File)
148      */

149     protected boolean isOkToCreateFile(File JavaDoc sourceFile) {
150         boolean isOk = true;
151         String JavaDoc fileName = sourceFile.getName();
152         if (fileName.equals("testToc.xml")) { //$NON-NLS-1$
153
isOk = genTestOption.isEnabled() && genTestOption.isSelected();
154         } else if (fileName.equals("tocconcepts.xml")) { //$NON-NLS-1$
155
isOk = conceptsOption.isEnabled() && conceptsOption.isSelected();
156         } else if (fileName.equals("tocgettingstarted.xml")) { //$NON-NLS-1$
157
isOk = gettingStartedOption.isEnabled() && gettingStartedOption.isSelected();
158         } else if (fileName.equals("tocreference.xml")) { //$NON-NLS-1$
159
isOk = referenceOption.isEnabled() && referenceOption.isSelected();
160         } else if (fileName.equals("tocsamples.xml")) { //$NON-NLS-1$
161
isOk = samplesOption.isEnabled() && samplesOption.isSelected();
162         } else if (fileName.equals("toctasks.xml")) { //$NON-NLS-1$
163
isOk = tasksOption.isEnabled() && tasksOption.isSelected();
164         } else if (
165             (fileName.equals("maintopic.html") || fileName.equals("subtopic.html")) //$NON-NLS-1$ //$NON-NLS-2$
166
&& sourceFile.getParentFile().getName().equals("html")) { //$NON-NLS-1$
167
isOk =
168                 !primaryOption.isSelected()
169                     || (primaryOption.isSelected()
170                         && !gettingStartedOption.isSelected()
171                         && !conceptsOption.isSelected()
172                         && !tasksOption.isSelected()
173                         && !referenceOption.isSelected()
174                         && !samplesOption.isSelected());
175         }
176         return isOk;
177     }
178     /**
179      * @see BaseOptionTemplateSection#validateOptions(TemplateOption)
180      */

181     public void validateOptions(TemplateOption changed) {
182         if (changed == tocLabelOption) {
183             if (changed.isEmpty()) {
184                 flagMissingRequiredOption(changed);
185             } else {
186                 resetPageState();
187             }
188         } else if (changed == primaryOption) {
189             alterOptionStates();
190         }
191     }
192
193     /**
194      * @see AbstractTemplateSection#updateModel(IProgressMonitor)
195      */

196     protected void updateModel(IProgressMonitor monitor) throws CoreException {
197         IPluginBase plugin = model.getPluginBase();
198         IPluginExtension extension = createExtension(getUsedExtensionPoint(), true);
199         IPluginModelFactory factory = model.getPluginFactory();
200
201         IPluginElement tocElement = factory.createElement(extension);
202         tocElement.setName("toc"); //$NON-NLS-1$
203
tocElement.setAttribute("file","toc.xml"); //$NON-NLS-1$ //$NON-NLS-2$
204
if (primaryOption.isSelected()) tocElement.setAttribute("primary","true"); //$NON-NLS-1$ //$NON-NLS-2$
205
extension.add(tocElement);
206         
207         if (genTestOption.isSelected() && genTestOption.isEnabled()) {
208             IPluginElement testTocElement = factory.createElement(extension);
209             testTocElement.setName("toc"); //$NON-NLS-1$
210
testTocElement.setAttribute("file","testToc.xml"); //$NON-NLS-1$ //$NON-NLS-2$
211
testTocElement.setAttribute("primary","true"); //$NON-NLS-1$ //$NON-NLS-2$
212
extension.add(testTocElement);
213         }
214         addNonPrimaryTopic(conceptsOption, "tocconcepts.xml", extension); //$NON-NLS-1$
215
addNonPrimaryTopic(gettingStartedOption, "tocgettingstarted.xml", extension); //$NON-NLS-1$
216
addNonPrimaryTopic(referenceOption, "tocreference.xml", extension); //$NON-NLS-1$
217
addNonPrimaryTopic(samplesOption, "tocsamples.xml", extension); //$NON-NLS-1$
218
addNonPrimaryTopic(tasksOption, "toctasks.xml", extension); //$NON-NLS-1$
219

220         if (!extension.isInTheModel())
221             plugin.add(extension);
222     }
223     
224     private void addNonPrimaryTopic(BooleanOption option, String JavaDoc file, IPluginExtension extension) throws CoreException {
225         if (option.isEnabled() && option.isSelected()) {
226             IPluginElement tocElement = extension.getPluginModel().getPluginFactory().createElement(extension);
227             tocElement.setName("toc"); //$NON-NLS-1$
228
tocElement.setAttribute("file", file); //$NON-NLS-1$
229
extension.add(tocElement);
230         }
231     }
232
233     /**
234      * @see ITemplateSection#getUsedExtensionPoint()
235      */

236     public String JavaDoc getUsedExtensionPoint() {
237         return "org.eclipse.help.toc"; //$NON-NLS-1$
238
}
239     
240     /* (non-Javadoc)
241      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
242      */

243     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
244         return new IPluginReference[0];
245     }
246     
247     /* (non-Javadoc)
248      * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getFoldersToInclude()
249      */

250     public String JavaDoc[] getNewFiles() {
251         return new String JavaDoc[] {"html/", "*.xml"}; //$NON-NLS-1$ //$NON-NLS-2$
252
}
253
254 }
255
Popular Tags