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.IPluginReference; 26 import org.eclipse.pde.internal.ui.IHelpContextIds; 27 import org.eclipse.pde.internal.ui.PDEUIMessages; 28 import org.eclipse.pde.ui.IFieldData; 29 import org.eclipse.pde.ui.templates.TemplateOption; 30 31 37 38 public class UniversalWelcomeTemplate extends PDETemplateSection { 39 private static final String KEY_LINK_ID = "linkId"; 41 private static final String KEY_EXTENSION_ID = "extensionId"; 43 private static final String KEY_INTRO_DIR = "introDir"; 45 private static final String KEY_PATH = "path"; 47 private static final String KEY_LINK_URL = "linkUrl"; 49 private String pluginId; 50 51 public UniversalWelcomeTemplate() { 52 setPageCount(1); 53 createOptions(); 54 } 55 56 private void createOptions() { 57 addOption(KEY_INTRO_DIR, PDEUIMessages.UniversalWelcomeTemplate_key_directoryName, "intro", 0); addOption(KEY_PATH, PDEUIMessages.UniversalWelcomeTemplate_key_targetPage, new String [][] { 60 { "overview/@", PDEUIMessages.UniversalWelcomeTemplate_page_Overview }, { "tutorials/@", PDEUIMessages.UniversalWelcomeTemplate_page_Tutorials }, { "firststeps/@", PDEUIMessages.UniversalWelcomeTemplate_page_FirstSteps }, { "samples/@", PDEUIMessages.UniversalWelcomeTemplate_page_Samples }, { "whatsnew/@", PDEUIMessages.UniversalWelcomeTemplate_page_Whatsnew }, { "migrate/@", PDEUIMessages.UniversalWelcomeTemplate_page_Migrate }, { "webresources/@", PDEUIMessages.UniversalWelcomeTemplate_page_WebResources } }, "overview/@", 0); addOption(KEY_LINK_URL, PDEUIMessages.UniversalWelcomeTemplate_linkUrl, "http://www.eclipse.org", 0); } 66 67 public void addPages(Wizard wizard) { 68 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_UNIVERSAL_WELCOME); 69 page.setTitle(PDEUIMessages.IntroTemplate_title); 70 page.setDescription(PDEUIMessages.IntroTemplate_desc); 71 wizard.addPage(page); 72 markPagesAdded(); 73 } 74 75 public boolean isDependentOnParentWizard() { 76 return true; 77 } 78 79 public String getSectionId() { 80 return "universalWelcome"; } 82 83 protected void initializeFields(IFieldData data) { 84 pluginId = data.getId(); 87 } 88 89 public void initializeFields(IPluginModelBase model) { 90 pluginId = model.getPluginBase().getId(); 91 } 92 93 public void validateOptions(TemplateOption source) { 94 95 if (source.isRequired() && source.isEmpty()) { 96 flagMissingRequiredOption(source); 97 } else { 98 validateContainerPage(source); 99 } 100 } 101 102 private void validateContainerPage(TemplateOption source) { 103 TemplateOption[] allPageOptions = getOptions(0); 104 for (int i = 0; i < allPageOptions.length; i++) { 105 TemplateOption nextOption = allPageOptions[i]; 106 if (nextOption.isRequired() && nextOption.isEmpty()) { 107 flagMissingRequiredOption(nextOption); 108 return; 109 } 110 } 111 resetPageState(); 112 } 113 114 protected void updateModel(IProgressMonitor monitor) throws CoreException { 115 IPluginBase plugin = model.getPluginBase(); 116 117 IPluginExtension extension = createExtension( 118 "org.eclipse.ui.intro.configExtension", false); 120 IPluginElement element = model.getPluginFactory().createElement( 121 extension); 122 element.setName("configExtension"); element 124 .setAttribute("configId", "org.eclipse.ui.intro.universalConfig"); element.setAttribute("content", getStringOption(KEY_INTRO_DIR) + "/sample.xml"); extension.add(element); 129 130 if (!extension.isInTheModel()) 131 plugin.add(extension); 132 } 133 134 protected boolean isOkToCreateFolder(File sourceFolder) { 135 return true; 136 } 137 138 141 protected boolean isOkToCreateFile(File sourceFile) { 142 return true; 143 } 144 145 public String getUsedExtensionPoint() { 146 return "org.eclipse.ui.intro.configExtension"; } 148 149 public IPluginReference[] getDependencies(String schemaVersion) { 150 ArrayList result = new ArrayList (); 151 152 result.add(new PluginReference("org.eclipse.ui.intro", null, 0)); result.add(new PluginReference( 157 "org.eclipse.ui.intro.universal", null, 0)); result.add(new PluginReference("org.eclipse.ui", null, 0)); 160 return (IPluginReference[]) result.toArray(new IPluginReference[result 161 .size()]); 162 } 163 164 public int getNumberOfWorkUnits() { 165 return super.getNumberOfWorkUnits() + 1; 166 } 167 168 172 public String getStringOption(String name) { 173 if (name.equals(KEY_EXTENSION_ID)) { 174 return pluginId + ".introExtension"; } 176 if (name.equals(KEY_LINK_ID)) { 177 return pluginId + "-introLink"; } 179 return super.getStringOption(name); 180 } 181 182 public String [] getNewFiles() { 183 return new String [] { getStringOption(KEY_INTRO_DIR) + "/" }; } 185 } | Popular Tags |