1 11 package org.eclipse.pde.internal.ui.wizards.templates; 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.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 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"; 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 125 public String getSectionId() { 126 return "help"; } 128 129 protected boolean isOkToCreateFolder(File sourceFolder) { 130 boolean isOk = true; 131 String folderName = sourceFolder.getName(); 132 if (folderName.equals("concepts")) { isOk = conceptsOption.isEnabled() && conceptsOption.isSelected(); 134 } else if (folderName.equals("gettingstarted")) { isOk = gettingStartedOption.isEnabled() && gettingStartedOption.isSelected(); 136 } else if (folderName.equals("reference")) { isOk = referenceOption.isEnabled() && referenceOption.isSelected(); 138 } else if (folderName.equals("samples")) { isOk = samplesOption.isEnabled() && samplesOption.isSelected(); 140 } else if (folderName.equals("tasks")) { isOk = tasksOption.isEnabled() && tasksOption.isSelected(); 142 } 143 return isOk; 144 } 145 148 protected boolean isOkToCreateFile(File sourceFile) { 149 boolean isOk = true; 150 String fileName = sourceFile.getName(); 151 if (fileName.equals("testToc.xml")) { isOk = genTestOption.isEnabled() && genTestOption.isSelected(); 153 } else if (fileName.equals("tocconcepts.xml")) { isOk = conceptsOption.isEnabled() && conceptsOption.isSelected(); 155 } else if (fileName.equals("tocgettingstarted.xml")) { isOk = gettingStartedOption.isEnabled() && gettingStartedOption.isSelected(); 157 } else if (fileName.equals("tocreference.xml")) { isOk = referenceOption.isEnabled() && referenceOption.isSelected(); 159 } else if (fileName.equals("tocsamples.xml")) { isOk = samplesOption.isEnabled() && samplesOption.isSelected(); 161 } else if (fileName.equals("toctasks.xml")) { isOk = tasksOption.isEnabled() && tasksOption.isSelected(); 163 } else if ( 164 (fileName.equals("maintopic.html") || fileName.equals("subtopic.html")) && sourceFile.getParentFile().getName().equals("html")) { 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 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 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"); tocElement.setAttribute("file","toc.xml"); if (primaryOption.isSelected()) tocElement.setAttribute("primary","true"); extension.add(tocElement); 205 206 if (genTestOption.isSelected() && genTestOption.isEnabled()) { 207 IPluginElement testTocElement = factory.createElement(extension); 208 testTocElement.setName("toc"); testTocElement.setAttribute("file","testToc.xml"); testTocElement.setAttribute("primary","true"); extension.add(testTocElement); 212 } 213 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); 219 if (!extension.isInTheModel()) 220 plugin.add(extension); 221 } 222 223 private void addNonPrimaryTopic(BooleanOption option, String file, IPluginExtension extension) throws CoreException { 224 if (option.isEnabled() && option.isSelected()) { 225 IPluginElement tocElement = extension.getPluginModel().getPluginFactory().createElement(extension); 226 tocElement.setName("toc"); tocElement.setAttribute("file", file); extension.add(tocElement); 229 } 230 } 231 232 235 public String getUsedExtensionPoint() { 236 return "org.eclipse.help.toc"; } 238 239 242 public IPluginReference[] getDependencies(String schemaVersion) { 243 return new IPluginReference[0]; 244 } 245 246 249 public String [] getNewFiles() { 250 return new String [] {"html/", "*.xml"}; } 252 253 } 254 | Popular Tags |