KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > templates > 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.wizards.templates;
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.IHelpContextIds;
25 import org.eclipse.pde.internal.ui.PDEUIMessages;
26 import org.eclipse.pde.ui.templates.BooleanOption;
27 import org.eclipse.pde.ui.templates.TemplateOption;
28
29 public class HelpTemplate extends PDETemplateSection {
30     
31     public static final String JavaDoc KEY_TOC_LABEL = "tocLabel"; //$NON-NLS-1$
32
public static final String JavaDoc KEY_IS_PRIMARY = "isPrimary"; //$NON-NLS-1$
33
public static final String JavaDoc KEY_GEN_TEST = "generateTest"; //$NON-NLS-1$
34
public static final String JavaDoc KEY_GET_STARTED = "gettingStarted"; //$NON-NLS-1$
35
public static final String JavaDoc KEY_CONCEPTS = "concepts"; //$NON-NLS-1$
36
public static final String JavaDoc KEY_TASKS = "tasks"; //$NON-NLS-1$
37
public static final String JavaDoc KEY_REFERENCE = "reference"; //$NON-NLS-1$
38
public static final String JavaDoc KEY_SAMPLES = "samples"; //$NON-NLS-1$
39

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

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

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

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

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

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

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

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

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