1 11 12 package org.eclipse.pde.internal.ui.templates.rcp; 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.ui.templates.IHelpContextIds; 28 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 29 import org.eclipse.pde.internal.ui.templates.PDETemplateSection; 30 import org.eclipse.pde.internal.ui.templates.PluginReference; 31 import org.eclipse.pde.ui.IFieldData; 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_GENERATE_DYNAMIC_CONTENT = "IntroTemplate.generateDynamicContent"; 41 private String packageName; 42 private String introID; 43 private static final String APPLICATION_CLASS = "Application"; 45 public IntroTemplate() { 46 super(); 47 setPageCount(1); 48 createOptions(); 49 } 50 51 private void createOptions() { 52 53 addOption(KEY_PRODUCT_NAME, PDETemplateMessages.IntroTemplate_productName, 54 VALUE_PRODUCT_NAME, 0); 55 56 addOption( KEY_GENERATE_DYNAMIC_CONTENT, 57 PDETemplateMessages.IntroTemplate_generate, 58 new String [][] { {STATIC_SELECTED, PDETemplateMessages.IntroTemplate_generateStaticContent}, 59 {DYNAMIC_SELECTED, PDETemplateMessages.IntroTemplate_generateDynamicContent}}, 60 STATIC_SELECTED, 0); 61 } 62 63 public void addPages(Wizard wizard) { 64 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_INTRO); 65 page.setTitle(PDETemplateMessages.IntroTemplate_title); 66 page.setDescription(PDETemplateMessages.IntroTemplate_desc); 67 wizard.addPage(page); 68 markPagesAdded(); 69 } 70 71 public boolean isDependentOnParentWizard() { 72 return true; 73 } 74 75 public String getSectionId() { 76 return "intro"; } 78 79 protected void initializeFields(IFieldData data) { 80 String pluginId = data.getId(); 83 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId) + ".intro"); packageName = getFormattedPackageName(pluginId) + ".intro"; introID = getFormattedPackageName(pluginId) + ".intro"; } 87 public void initializeFields(IPluginModelBase model) { 88 String pluginId = model.getPluginBase().getId(); 91 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId) + ".intro"); packageName = getFormattedPackageName(pluginId) + ".intro"; introID = getFormattedPackageName(pluginId) + ".intro"; } 95 96 protected void updateModel(IProgressMonitor monitor) throws CoreException { 97 98 IPluginBase plugin = model.getPluginBase(); 99 IPluginModelFactory factory = model.getPluginFactory(); 100 101 IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); extension.setId(VALUE_APPLICATION_ID); 104 105 IPluginElement element = model.getPluginFactory().createElement(extension); 106 element.setName("application"); extension.add(element); 108 109 IPluginElement run = model.getPluginFactory().createElement(element); 110 run.setName("run"); run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + APPLICATION_CLASS); element.add(run); 113 114 if (!extension.isInTheModel()) 115 plugin.add(extension); 116 117 118 IPluginExtension perspectivesExtension = createExtension("org.eclipse.ui.perspectives", true); IPluginElement perspectiveElement = model.getPluginFactory().createElement(perspectivesExtension); 121 perspectiveElement.setName("perspective"); perspectiveElement.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); perspectiveElement.setAttribute("name", VALUE_PERSPECTIVE_NAME); perspectiveElement.setAttribute("id", plugin.getId() + ".perspective"); perspectivesExtension.add(perspectiveElement); 126 127 if (!perspectivesExtension.isInTheModel()) 128 plugin.add(perspectivesExtension); 129 130 createProductExtension(); 131 132 IPluginExtension extension2 = createExtension( 134 "org.eclipse.ui.intro", true); 136 IPluginElement introElement = factory.createElement(extension2); 137 introElement.setName("intro"); introElement.setAttribute("id", introID); introElement.setAttribute("class", "org.eclipse.ui.intro.config.CustomizableIntroPart"); extension2.add(introElement); 142 143 IPluginElement introProductBindingElement = factory 144 .createElement(extension2); 145 introProductBindingElement.setName("introProductBinding"); introProductBindingElement.setAttribute("introId", introID); 148 introProductBindingElement.setAttribute("productId", plugin.getId() + '.' + VALUE_PRODUCT_ID); 150 extension2.add(introProductBindingElement); 151 152 if (!extension2.isInTheModel()) 153 plugin.add(extension2); 154 155 IPluginExtension extension3 = createExtension( 157 "org.eclipse.ui.intro.config", true); 159 IPluginElement configurationElement = factory.createElement(extension3); 160 configurationElement.setName("config"); configurationElement.setAttribute("id", plugin.getId() + '.' + "configId"); configurationElement.setAttribute("introId", introID); configurationElement.setAttribute("content", "introContent.xml"); IPluginElement presentationElement = factory 166 .createElement(configurationElement); 167 presentationElement.setName("presentation"); presentationElement.setAttribute("home-page-id", "root"); IPluginElement implementationElement = factory 170 .createElement(presentationElement); 171 implementationElement.setName("implementation"); implementationElement.setAttribute("os", "win32,linux,macosx"); if (getTargetVersion() == 3.0) 174 implementationElement.setAttribute("style", "content/shared.css"); 176 implementationElement.setAttribute("kind", "html"); presentationElement.add(implementationElement); 178 configurationElement.add(presentationElement); 179 extension3.add(configurationElement); 180 181 if (!extension3.isInTheModel()) 182 plugin.add(extension3); 183 184 if (getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(DYNAMIC_SELECTED)) { 186 IPluginExtension extension4 = createExtension( 187 "org.eclipse.ui.intro.configExtension", true); 189 IPluginElement configExtensionElement = factory.createElement(extension4); 190 configExtensionElement.setName("configExtension"); configExtensionElement.setAttribute("configId", plugin.getId() + '.' + "configId"); configExtensionElement.setAttribute("content", "ext.xml"); extension4.add(configExtensionElement); 194 195 if (!extension4.isInTheModel()) 196 plugin.add(extension4); 197 } 198 199 200 } 201 202 private void createProductExtension() throws CoreException { 203 IPluginBase plugin = model.getPluginBase(); 204 IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); extension.setId(VALUE_PRODUCT_ID); 206 207 IPluginElement element = model.getFactory().createElement(extension); 208 element.setName("product"); element.setAttribute("name", getStringOption(KEY_PRODUCT_NAME)); element.setAttribute("application", plugin.getId() + "." + VALUE_APPLICATION_ID); 212 IPluginElement property = model.getFactory().createElement(element); 213 214 property = model.getFactory().createElement(element); 215 property.setName("property"); property.setAttribute("name", "windowImages"); property.setAttribute("value", "icons/alt_window_16.gif,icons/alt_window_32.gif"); element.add(property); 219 220 extension.add(element); 221 222 if (!extension.isInTheModel()) 223 plugin.add(extension); 224 } 225 226 protected boolean isOkToCreateFolder(File sourceFolder) { 227 return true; 228 } 229 230 233 protected boolean isOkToCreateFile(File sourceFile) { 234 235 if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(STATIC_SELECTED) && 236 (sourceFile.getName().equals("DynamicContentProvider.java") || sourceFile.getName().equals("concept3.xhtml") || sourceFile.getName().equals("extContent.xhtml") || sourceFile.getName().equals("ext.xml") ) ) { return false; 241 } 242 243 return true; 244 } 245 246 public String getUsedExtensionPoint() { 247 return "org.eclipse.ui.intro"; } 249 250 public IPluginReference[] getDependencies(String schemaVersion) { 251 ArrayList result = new ArrayList (); 252 253 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)); 257 if ( getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(DYNAMIC_SELECTED)) { 258 result.add(new PluginReference("org.eclipse.ui.forms", null, 0)); result.add(new PluginReference("org.eclipse.swt", null, 0)); } 261 262 return (IPluginReference[]) result.toArray(new IPluginReference[result 263 .size()]); 264 } 265 266 public int getNumberOfWorkUnits() { 267 return super.getNumberOfWorkUnits() + 1; 268 } 269 270 public Object getValue(String valueName) { 271 272 if (valueName.equals(KEY_PACKAGE_NAME)) { 273 return packageName; 274 } 275 276 return super.getValue(valueName); 277 } 278 279 public String getStringOption(String name) { 280 281 if ( name.equals(KEY_PACKAGE_NAME)) { 282 return packageName; 283 } 284 285 return super.getStringOption(name); 286 } 287 288 public String [] getNewFiles() { 289 if (getValue(KEY_GENERATE_DYNAMIC_CONTENT).toString().equals(STATIC_SELECTED)) { 290 return new String [] {"icons/", "content/", "splash.bmp", "introContent.xml" }; } 292 return new String [] {"icons/", "content/", "splash.bmp", "introContent.xml", "ext.xml" }; } 294 295 298 protected boolean copyBrandingDirectory() { 299 return true; 300 } 301 } 302 | Popular Tags |