1 11 package org.eclipse.pde.internal.ui.templates.ide; 12 13 import java.io.File ; 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 KEY_TOC_LABEL = "tocLabel"; public static final String KEY_IS_PRIMARY = "isPrimary"; public static final String KEY_GEN_TEST = "generateTest"; public static final String KEY_GET_STARTED = "gettingStarted"; public static final String KEY_CONCEPTS = "concepts"; public static final String KEY_TASKS = "tasks"; public static final String KEY_REFERENCE = "reference"; public static final String KEY_SAMPLES = "samples"; 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 126 public String getSectionId() { 127 return "help"; } 129 130 protected boolean isOkToCreateFolder(File sourceFolder) { 131 boolean isOk = true; 132 String folderName = sourceFolder.getName(); 133 if (folderName.equals("concepts")) { isOk = conceptsOption.isEnabled() && conceptsOption.isSelected(); 135 } else if (folderName.equals("gettingstarted")) { isOk = gettingStartedOption.isEnabled() && gettingStartedOption.isSelected(); 137 } else if (folderName.equals("reference")) { isOk = referenceOption.isEnabled() && referenceOption.isSelected(); 139 } else if (folderName.equals("samples")) { isOk = samplesOption.isEnabled() && samplesOption.isSelected(); 141 } else if (folderName.equals("tasks")) { isOk = tasksOption.isEnabled() && tasksOption.isSelected(); 143 } 144 return isOk; 145 } 146 149 protected boolean isOkToCreateFile(File sourceFile) { 150 boolean isOk = true; 151 String fileName = sourceFile.getName(); 152 if (fileName.equals("testToc.xml")) { isOk = genTestOption.isEnabled() && genTestOption.isSelected(); 154 } else if (fileName.equals("tocconcepts.xml")) { isOk = conceptsOption.isEnabled() && conceptsOption.isSelected(); 156 } else if (fileName.equals("tocgettingstarted.xml")) { isOk = gettingStartedOption.isEnabled() && gettingStartedOption.isSelected(); 158 } else if (fileName.equals("tocreference.xml")) { isOk = referenceOption.isEnabled() && referenceOption.isSelected(); 160 } else if (fileName.equals("tocsamples.xml")) { isOk = samplesOption.isEnabled() && samplesOption.isSelected(); 162 } else if (fileName.equals("toctasks.xml")) { isOk = tasksOption.isEnabled() && tasksOption.isSelected(); 164 } else if ( 165 (fileName.equals("maintopic.html") || fileName.equals("subtopic.html")) && sourceFile.getParentFile().getName().equals("html")) { 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 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 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"); tocElement.setAttribute("file","toc.xml"); if (primaryOption.isSelected()) tocElement.setAttribute("primary","true"); extension.add(tocElement); 206 207 if (genTestOption.isSelected() && genTestOption.isEnabled()) { 208 IPluginElement testTocElement = factory.createElement(extension); 209 testTocElement.setName("toc"); testTocElement.setAttribute("file","testToc.xml"); testTocElement.setAttribute("primary","true"); extension.add(testTocElement); 213 } 214 addNonPrimaryTopic(conceptsOption, "tocconcepts.xml", extension); addNonPrimaryTopic(gettingStartedOption, "tocgettingstarted.xml", extension); addNonPrimaryTopic(referenceOption, "tocreference.xml", extension); addNonPrimaryTopic(samplesOption, "tocsamples.xml", extension); addNonPrimaryTopic(tasksOption, "toctasks.xml", extension); 220 if (!extension.isInTheModel()) 221 plugin.add(extension); 222 } 223 224 private void addNonPrimaryTopic(BooleanOption option, String file, IPluginExtension extension) throws CoreException { 225 if (option.isEnabled() && option.isSelected()) { 226 IPluginElement tocElement = extension.getPluginModel().getPluginFactory().createElement(extension); 227 tocElement.setName("toc"); tocElement.setAttribute("file", file); extension.add(tocElement); 230 } 231 } 232 233 236 public String getUsedExtensionPoint() { 237 return "org.eclipse.help.toc"; } 239 240 243 public IPluginReference[] getDependencies(String schemaVersion) { 244 return new IPluginReference[0]; 245 } 246 247 250 public String [] getNewFiles() { 251 return new String [] {"html/", "*.xml"}; } 253 254 } 255 | Popular Tags |