1 11 12 package org.eclipse.pde.internal.ui.wizards.templates; 13 14 import java.io.File ; 15 import java.util.ArrayList ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.jface.wizard.Wizard; 20 import org.eclipse.jface.wizard.WizardPage; 21 import org.eclipse.pde.core.plugin.IPluginBase; 22 import org.eclipse.pde.core.plugin.IPluginElement; 23 import org.eclipse.pde.core.plugin.IPluginExtension; 24 import org.eclipse.pde.core.plugin.IPluginModelBase; 25 import org.eclipse.pde.core.plugin.IPluginModelFactory; 26 import org.eclipse.pde.core.plugin.IPluginReference; 27 import org.eclipse.pde.internal.core.plugin.PluginBase; 28 import org.eclipse.pde.internal.ui.IHelpContextIds; 29 import org.eclipse.pde.internal.ui.PDEUIMessages; 30 import org.eclipse.pde.ui.IFieldData; 31 import org.eclipse.pde.ui.templates.TemplateOption; 32 33 public class IntroTemplate extends PDETemplateSection { 34 35 private static final String DYNAMIC_SELECTED = "dynamic"; 37 private static final String STATIC_SELECTED = "static"; 39 private static final String KEY_PRODUCT_ID = "IntroTemplate.productID"; 41 private static final String KEY_PRODUCT_NAME = "productName"; 43 private static final String KEY_APPLICATION_ID = "IntroTemplate.application"; 45 private static final String KEY_GENERATE_DYNAMIC_CONTENT = "IntroTemplate.generateDynamicContent"; 47 public static final String CLASS_NAME = "SampleXHTMLContentProvider"; 49 public static final String KEY_PERSPECTIVE_NAME = "perspectiveName"; 51 private String packageName; 52 private String introID; 53 private String perspectiveName; 54 private static final String APPLICATION_CLASS = "Application"; 56 public IntroTemplate() { 57 super(); 58 setPageCount(1); 59 createOptions(); 60 } 61 62 private void createOptions() { 63 64 addOption(KEY_PRODUCT_ID, PDEUIMessages.IntroTemplate_productID, 66 "product", 0); addOption(KEY_PRODUCT_NAME, PDEUIMessages.IntroTemplate_productName, 68 "My New Product", 0); addOption(KEY_APPLICATION_ID, PDEUIMessages.IntroTemplate_application, 70 "application", 0); 72 addOption( KEY_GENERATE_DYNAMIC_CONTENT, 73 PDEUIMessages.IntroTemplate_generate, 74 new String [][] { {STATIC_SELECTED, PDEUIMessages.IntroTemplate_generateStaticContent}, 75 {DYNAMIC_SELECTED, PDEUIMessages.IntroTemplate_generateDynamicContent}}, 76 STATIC_SELECTED, 0); 77 } 78 79 public void addPages(Wizard wizard) { 80 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_INTRO); 81 page.setTitle(PDEUIMessages.IntroTemplate_title); 82 page.setDescription(PDEUIMessages.IntroTemplate_desc); 83 wizard.addPage(page); 84 markPagesAdded(); 85 } 86 87 public boolean isDependentOnParentWizard() { 88 return true; 89 } 90 91 public String getSectionId() { 92 return "intro"; } 94 95 protected void initializeFields(IFieldData data) { 96 String pluginId = data.getId(); 99 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId) + ".intro"); initializeOption(KEY_APPLICATION_ID, getFormattedPackageName(pluginId) + ".application"); initializeOption(KEY_PERSPECTIVE_NAME, getFormattedPackageName(pluginId) + " Perspective"); perspectiveName = getFormattedPackageName(pluginId) + ".perspective"; packageName = getFormattedPackageName(pluginId) + ".intro"; introID = getFormattedPackageName(pluginId) + ".intro"; } 106 public void initializeFields(IPluginModelBase model) { 107 String pluginId = model.getPluginBase().getId(); 110 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId) + ".intro"); initializeOption(KEY_APPLICATION_ID, getFormattedPackageName(pluginId) + ".application"); initializeOption(KEY_PERSPECTIVE_NAME, getFormattedPackageName(pluginId) + " Perspective"); perspectiveName = getFormattedPackageName(pluginId) + ".perspective"; packageName = getFormattedPackageName(pluginId) + ".intro"; introID = getFormattedPackageName(pluginId) + ".intro"; } 117 118 public void validateOptions(TemplateOption source) { 119 120 if (source.isRequired() && source.isEmpty()) { 121 flagMissingRequiredOption(source); 122 } else { 123 validateContainerPage(source); 124 } 125 } 126 127 private void validateContainerPage(TemplateOption source) { 128 TemplateOption[] allPageOptions = getOptions(0); 129 for (int i = 0; i < allPageOptions.length; i++) { 130 TemplateOption nextOption = allPageOptions[i]; 131 if (nextOption.isRequired() && nextOption.isEmpty()) { 132 flagMissingRequiredOption(nextOption); 133 return; 134 } 135 } 136 resetPageState(); 137 } 138 139 protected void updateModel(IProgressMonitor monitor) throws CoreException { 140 141 IPluginBase plugin = model.getPluginBase(); 142 IPluginModelFactory factory = model.getPluginFactory(); 143 144 IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); extension.setId(getStringOption(KEY_APPLICATION_ID)); 147 148 IPluginElement element = model.getPluginFactory().createElement(extension); 149 element.setName("application"); extension.add(element); 151 152 IPluginElement run = model.getPluginFactory().createElement(element); 153 run.setName("run"); run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + APPLICATION_CLASS); element.add(run); 156 157 if (!extension.isInTheModel()) 158 plugin.add(extension); 159 160 161 IPluginExtension perspectivesExtension = createExtension("org.eclipse.ui.perspectives", true); IPluginElement perspectiveElement = model.getPluginFactory().createElement(perspectivesExtension); 164 perspectiveElement.setName("perspective"); perspectiveElement.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); perspectiveElement.setAttribute("name", getStringOption(KEY_PERSPECTIVE_NAME)); perspectiveElement.setAttribute("id", plugin.getId() + ".perspective"); perspectivesExtension.add(perspectiveElement); 169 170 if (!perspectivesExtension.isInTheModel()) 171 plugin.add(perspectivesExtension); 172 173 174 IPluginExtension extension1 = createExtension( 176 "org.eclipse.core.runtime.products", true); extension1.setId(getStringOption(KEY_PRODUCT_ID)); 178 180 IPluginElement productElement = factory.createElement(extension1); 181 productElement.setName("product"); productElement.setAttribute("name", getStringOption(KEY_PRODUCT_NAME)); productElement.setAttribute( 184 "application", plugin.getId() + "." + getStringOption(KEY_APPLICATION_ID)); extension1.add(productElement); 186 187 if (!extension1.isInTheModel()) 188 plugin.add(extension1); 189 190 IPluginExtension extension2 = createExtension( 192 "org.eclipse.ui.intro", true); 194 IPluginElement introElement = factory.createElement(extension2); 195 introElement.setName("intro"); introElement.setAttribute("id", introID); introElement.setAttribute("class", "org.eclipse.ui.intro.config.CustomizableIntroPart"); extension2.add(introElement); 200 201 IPluginElement introProductBindingElement = factory 202 .createElement(extension2); 203 introProductBindingElement.setName("introProductBinding"); introProductBindingElement.setAttribute("introId", introID); 206 introProductBindingElement.setAttribute("productId", plugin.getId() + '.' + getStringOption(KEY_PRODUCT_ID)); 208 extension2.add(introProductBindingElement); 209 210 if (!extension2.isInTheModel()) 211 plugin.add(extension2); 212 213 IPluginExtension extension3 = createExtension( 215 "org.eclipse.ui.intro.config", true); 217 IPluginElement configurationElement = factory.createElement(extension3); 218 configurationElement.setName("config"); configurationElement.setAttribute("id", plugin.getId() + '.' + "configId"); configurationElement.setAttribute("introId", introID); configurationElement.setAttribute("content", "introContent.xml"); IPluginElement presentationElement = factory 224 .createElement(configurationElement); 225 presentationElement.setName("presentation"); presentationElement.setAttribute("home-page-id", "root"); IPluginElement implementationElement = factory 228 .createElement(presentationElement); 229 implementationElement.setName("implementation"); implementationElement.setAttribute("os", "win32,linux,macosx"); if ( ((PluginBase)plugin).getTargetVersion().equals("3.0")) { implementationElement.setAttribute("style", "content/shared.css"); } 234 implementationElement.setAttribute("kind", "html"); presentationElement.add(implementationElement); 236 configurationElement.add(presentationElement); 237 extension3.add(configurationElement); 238 239 if (!extension3.isInTheModel()) 240 plugin.add(extension3); 241 242 if (getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(DYNAMIC_SELECTED)) { 244 IPluginExtension extension4 = createExtension( 245 "org.eclipse.ui.intro.configExtension", true); 247 IPluginElement configExtensionElement = factory.createElement(extension4); 248 configExtensionElement.setName("configExtension"); configExtensionElement.setAttribute("configId", plugin.getId() + '.' + "configId"); configExtensionElement.setAttribute("content", "ext.xml"); extension4.add(configExtensionElement); 252 253 if (!extension4.isInTheModel()) 254 plugin.add(extension4); 255 } 256 257 258 } 259 260 protected boolean isOkToCreateFolder(File sourceFolder) { 261 return true; 262 } 263 264 267 protected boolean isOkToCreateFile(File sourceFile) { 268 269 if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(STATIC_SELECTED) && 270 (sourceFile.getName().equals("DynamicContentProvider.java") || sourceFile.getName().equals("concept3.xhtml") || sourceFile.getName().equals("extContent.xhtml") || sourceFile.getName().equals("ext.xml") ) ) { return false; 275 } 276 277 return true; 278 } 279 280 public String getUsedExtensionPoint() { 281 return "org.eclipse.ui.intro"; } 283 284 public IPluginReference[] getDependencies(String schemaVersion) { 285 ArrayList result = new ArrayList (); 286 287 result.add(new PluginReference("org.eclipse.ui.intro", null, 0)); result.add(new PluginReference("org.eclipse.core.runtime", null, 0)); result.add(new PluginReference("org.eclipse.ui", null, 0)); 291 if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(DYNAMIC_SELECTED)) { 292 result.add(new PluginReference("org.eclipse.ui.forms", null, 0)); result.add(new PluginReference("org.eclipse.swt", null, 0)); } 295 296 return (IPluginReference[]) result.toArray(new IPluginReference[result 297 .size()]); 298 } 299 300 public int getNumberOfWorkUnits() { 301 return super.getNumberOfWorkUnits() + 1; 302 } 303 304 public Object getValue(String valueName) { 305 306 if (valueName.equals(KEY_PACKAGE_NAME)) { 307 return packageName; 308 } 309 310 return super.getValue(valueName); 311 } 312 313 public String getStringOption(String name) { 314 315 if (name.equals(KEY_PERSPECTIVE_NAME)) { 316 return perspectiveName; 317 } else if ( name.equals(KEY_PACKAGE_NAME)) { 318 return packageName; 319 } 320 321 return super.getStringOption(name); 322 } 323 324 public String [] getNewFiles() { 325 326 if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(STATIC_SELECTED)) { 327 return new String [] {"content/", "splash.bmp", "introContent.xml"}; } 329 330 return new String [] {"content/", "splash.bmp", "introContent.xml", "ext.xml"}; 332 } 333 } 334 | Popular Tags |