001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.core.runtime.IProgressMonitor;
016: import org.eclipse.jface.wizard.Wizard;
017: import org.eclipse.jface.wizard.WizardPage;
018: import org.eclipse.pde.core.plugin.IPluginBase;
019: import org.eclipse.pde.core.plugin.IPluginElement;
020: import org.eclipse.pde.core.plugin.IPluginExtension;
021: import org.eclipse.pde.core.plugin.IPluginModelFactory;
022: import org.eclipse.pde.core.plugin.IPluginReference;
023: import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
024: import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
025: import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
026: import org.eclipse.pde.ui.templates.BooleanOption;
027: import org.eclipse.pde.ui.templates.TemplateOption;
028:
029: public class HelpTemplate extends PDETemplateSection {
030:
031: public static final String KEY_TOC_LABEL = "tocLabel"; //$NON-NLS-1$
032: public static final String KEY_IS_PRIMARY = "isPrimary"; //$NON-NLS-1$
033: public static final String KEY_GEN_TEST = "generateTest"; //$NON-NLS-1$
034: public static final String KEY_GET_STARTED = "gettingStarted"; //$NON-NLS-1$
035: public static final String KEY_CONCEPTS = "concepts"; //$NON-NLS-1$
036: public static final String KEY_TASKS = "tasks"; //$NON-NLS-1$
037: public static final String KEY_REFERENCE = "reference"; //$NON-NLS-1$
038: public static final String KEY_SAMPLES = "samples"; //$NON-NLS-1$
039:
040: private TemplateOption tocLabelOption;
041: private BooleanOption primaryOption;
042: private BooleanOption genTestOption;
043: private BooleanOption gettingStartedOption;
044: private BooleanOption conceptsOption;
045: private BooleanOption tasksOption;
046: private BooleanOption referenceOption;
047: private BooleanOption samplesOption;
048:
049: public HelpTemplate() {
050: setPageCount(1);
051: createOptions();
052: alterOptionStates();
053: }
054:
055: public void addPages(Wizard wizard) {
056: WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_HELP);
057: page.setTitle(PDETemplateMessages.HelpTemplate_title);
058: page.setDescription(PDETemplateMessages.HelpTemplate_desc);
059: wizard.addPage(page);
060: markPagesAdded();
061: }
062:
063: private void alterOptionStates() {
064: genTestOption.setEnabled(!primaryOption.isSelected());
065: gettingStartedOption.setEnabled(primaryOption.isSelected());
066: conceptsOption.setEnabled(primaryOption.isSelected());
067: tasksOption.setEnabled(primaryOption.isSelected());
068: referenceOption.setEnabled(primaryOption.isSelected());
069: samplesOption.setEnabled(primaryOption.isSelected());
070: }
071:
072: private void createOptions() {
073: tocLabelOption = addOption(KEY_TOC_LABEL,
074: PDETemplateMessages.HelpTemplate_tocLabel,
075: PDETemplateMessages.HelpTemplate_sampleText, 0);
076:
077: primaryOption = (BooleanOption) addOption(KEY_IS_PRIMARY,
078: PDETemplateMessages.HelpTemplate_isPrimary, false, 0);
079:
080: genTestOption = (BooleanOption) addOption(KEY_GEN_TEST,
081: PDETemplateMessages.HelpTemplate_generateTest, true, 0);
082:
083: gettingStartedOption = (BooleanOption) addOption(
084: KEY_GET_STARTED,
085: PDETemplateMessages.HelpTemplate_gettingStarted, true,
086: 0);
087:
088: conceptsOption = (BooleanOption) addOption(KEY_CONCEPTS,
089: PDETemplateMessages.HelpTemplate_concepts, true, 0);
090:
091: tasksOption = (BooleanOption) addOption(KEY_TASKS,
092: PDETemplateMessages.HelpTemplate_tasks, true, 0);
093:
094: referenceOption = (BooleanOption) addOption(KEY_REFERENCE,
095: PDETemplateMessages.HelpTemplate_reference, true, 0);
096:
097: samplesOption = (BooleanOption) addOption(KEY_SAMPLES,
098: PDETemplateMessages.HelpTemplate_samples, true, 0);
099:
100: }
101:
102: /**
103: * @see OptionTemplateSection#getSectionId()
104: */
105: public String getSectionId() {
106: return "help"; //$NON-NLS-1$
107: }
108:
109: protected boolean isOkToCreateFolder(File sourceFolder) {
110: boolean isOk = true;
111: String folderName = sourceFolder.getName();
112: if (folderName.equals("concepts")) { //$NON-NLS-1$
113: isOk = conceptsOption.isEnabled()
114: && conceptsOption.isSelected();
115: } else if (folderName.equals("gettingstarted")) { //$NON-NLS-1$
116: isOk = gettingStartedOption.isEnabled()
117: && gettingStartedOption.isSelected();
118: } else if (folderName.equals("reference")) { //$NON-NLS-1$
119: isOk = referenceOption.isEnabled()
120: && referenceOption.isSelected();
121: } else if (folderName.equals("samples")) { //$NON-NLS-1$
122: isOk = samplesOption.isEnabled()
123: && samplesOption.isSelected();
124: } else if (folderName.equals("tasks")) { //$NON-NLS-1$
125: isOk = tasksOption.isEnabled() && tasksOption.isSelected();
126: }
127: return isOk;
128: }
129:
130: /**
131: * @see AbstractTemplateSection#isOkToCreateFile(File)
132: */
133: protected boolean isOkToCreateFile(File sourceFile) {
134: boolean isOk = true;
135: String fileName = sourceFile.getName();
136: if (fileName.equals("testToc.xml")) { //$NON-NLS-1$
137: isOk = genTestOption.isEnabled()
138: && genTestOption.isSelected();
139: } else if (fileName.equals("tocconcepts.xml")) { //$NON-NLS-1$
140: isOk = conceptsOption.isEnabled()
141: && conceptsOption.isSelected();
142: } else if (fileName.equals("tocgettingstarted.xml")) { //$NON-NLS-1$
143: isOk = gettingStartedOption.isEnabled()
144: && gettingStartedOption.isSelected();
145: } else if (fileName.equals("tocreference.xml")) { //$NON-NLS-1$
146: isOk = referenceOption.isEnabled()
147: && referenceOption.isSelected();
148: } else if (fileName.equals("tocsamples.xml")) { //$NON-NLS-1$
149: isOk = samplesOption.isEnabled()
150: && samplesOption.isSelected();
151: } else if (fileName.equals("toctasks.xml")) { //$NON-NLS-1$
152: isOk = tasksOption.isEnabled() && tasksOption.isSelected();
153: } else if ((fileName.equals("maintopic.html") || fileName.equals("subtopic.html")) //$NON-NLS-1$ //$NON-NLS-2$
154: && sourceFile.getParentFile().getName().equals("html")) { //$NON-NLS-1$
155: isOk = !primaryOption.isSelected()
156: || (primaryOption.isSelected()
157: && !gettingStartedOption.isSelected()
158: && !conceptsOption.isSelected()
159: && !tasksOption.isSelected()
160: && !referenceOption.isSelected() && !samplesOption
161: .isSelected());
162: }
163: return isOk;
164: }
165:
166: /**
167: * @see BaseOptionTemplateSection#validateOptions(TemplateOption)
168: */
169: public void validateOptions(TemplateOption changed) {
170: if (changed == tocLabelOption) {
171: if (changed.isEmpty()) {
172: flagMissingRequiredOption(changed);
173: } else {
174: resetPageState();
175: }
176: } else if (changed == primaryOption) {
177: alterOptionStates();
178: }
179: }
180:
181: /**
182: * @see AbstractTemplateSection#updateModel(IProgressMonitor)
183: */
184: protected void updateModel(IProgressMonitor monitor)
185: throws CoreException {
186: IPluginBase plugin = model.getPluginBase();
187: IPluginExtension extension = createExtension(
188: getUsedExtensionPoint(), true);
189: IPluginModelFactory factory = model.getPluginFactory();
190:
191: IPluginElement tocElement = factory.createElement(extension);
192: tocElement.setName("toc"); //$NON-NLS-1$
193: tocElement.setAttribute("file", "toc.xml"); //$NON-NLS-1$ //$NON-NLS-2$
194: if (primaryOption.isSelected())
195: tocElement.setAttribute("primary", "true"); //$NON-NLS-1$ //$NON-NLS-2$
196: extension.add(tocElement);
197:
198: if (genTestOption.isSelected() && genTestOption.isEnabled()) {
199: IPluginElement testTocElement = factory
200: .createElement(extension);
201: testTocElement.setName("toc"); //$NON-NLS-1$
202: testTocElement.setAttribute("file", "testToc.xml"); //$NON-NLS-1$ //$NON-NLS-2$
203: testTocElement.setAttribute("primary", "true"); //$NON-NLS-1$ //$NON-NLS-2$
204: extension.add(testTocElement);
205: }
206: addNonPrimaryTopic(conceptsOption, "tocconcepts.xml", extension); //$NON-NLS-1$
207: addNonPrimaryTopic(gettingStartedOption,
208: "tocgettingstarted.xml", extension); //$NON-NLS-1$
209: addNonPrimaryTopic(referenceOption,
210: "tocreference.xml", extension); //$NON-NLS-1$
211: addNonPrimaryTopic(samplesOption, "tocsamples.xml", extension); //$NON-NLS-1$
212: addNonPrimaryTopic(tasksOption, "toctasks.xml", extension); //$NON-NLS-1$
213:
214: if (!extension.isInTheModel())
215: plugin.add(extension);
216: }
217:
218: private void addNonPrimaryTopic(BooleanOption option, String file,
219: IPluginExtension extension) throws CoreException {
220: if (option.isEnabled() && option.isSelected()) {
221: IPluginElement tocElement = extension.getPluginModel()
222: .getPluginFactory().createElement(extension);
223: tocElement.setName("toc"); //$NON-NLS-1$
224: tocElement.setAttribute("file", file); //$NON-NLS-1$
225: extension.add(tocElement);
226: }
227: }
228:
229: /**
230: * @see ITemplateSection#getUsedExtensionPoint()
231: */
232: public String getUsedExtensionPoint() {
233: return "org.eclipse.help.toc"; //$NON-NLS-1$
234: }
235:
236: /* (non-Javadoc)
237: * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
238: */
239: public IPluginReference[] getDependencies(String schemaVersion) {
240: return new IPluginReference[0];
241: }
242:
243: /* (non-Javadoc)
244: * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getFoldersToInclude()
245: */
246: public String[] getNewFiles() {
247: return new String[] { "html/", "*.xml" }; //$NON-NLS-1$ //$NON-NLS-2$
248: }
249:
250: }
|