1 11 12 package org.eclipse.pde.internal.ui.templates.ide; 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.templates.IHelpContextIds; 27 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 28 import org.eclipse.pde.internal.ui.templates.PDETemplateSection; 29 import org.eclipse.pde.internal.ui.templates.PluginReference; 30 import org.eclipse.pde.ui.IFieldData; 31 32 38 39 public class UniversalWelcomeTemplate extends PDETemplateSection { 40 private static final String KEY_LINK_ID = "linkId"; 42 private static final String KEY_EXTENSION_ID = "extensionId"; 44 private static final String KEY_INTRO_DIR = "introDir"; 46 private static final String KEY_PATH = "path"; 48 private static final String KEY_LINK_URL = "linkUrl"; 50 private String pluginId; 51 52 public UniversalWelcomeTemplate() { 53 setPageCount(1); 54 createOptions(); 55 } 56 57 private void createOptions() { 58 addOption(KEY_INTRO_DIR, PDETemplateMessages.UniversalWelcomeTemplate_key_directoryName, "intro", 0); addOption(KEY_PATH, PDETemplateMessages.UniversalWelcomeTemplate_key_targetPage, new String [][] { 61 { "overview/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Overview }, { "tutorials/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Tutorials }, { "firststeps/@", PDETemplateMessages.UniversalWelcomeTemplate_page_FirstSteps }, { "samples/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Samples }, { "whatsnew/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Whatsnew }, { "migrate/@", PDETemplateMessages.UniversalWelcomeTemplate_page_Migrate }, { "webresources/@", PDETemplateMessages.UniversalWelcomeTemplate_page_WebResources } }, "overview/@", 0); addOption(KEY_LINK_URL, PDETemplateMessages.UniversalWelcomeTemplate_linkUrl, "http://www.eclipse.org", 0); } 67 68 public void addPages(Wizard wizard) { 69 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_UNIVERSAL_WELCOME); 70 page.setTitle(PDETemplateMessages.IntroTemplate_title); 71 page.setDescription(PDETemplateMessages.IntroTemplate_desc); 72 wizard.addPage(page); 73 markPagesAdded(); 74 } 75 76 public boolean isDependentOnParentWizard() { 77 return true; 78 } 79 80 public String getSectionId() { 81 return "universalWelcome"; } 83 84 protected void initializeFields(IFieldData data) { 85 pluginId = data.getId(); 88 } 89 90 public void initializeFields(IPluginModelBase model) { 91 pluginId = model.getPluginBase().getId(); 92 } 93 94 protected void updateModel(IProgressMonitor monitor) throws CoreException { 95 IPluginBase plugin = model.getPluginBase(); 96 97 IPluginExtension extension = createExtension( 98 "org.eclipse.ui.intro.configExtension", false); 100 IPluginElement element = model.getPluginFactory().createElement( 101 extension); 102 element.setName("configExtension"); element 104 .setAttribute("configId", "org.eclipse.ui.intro.universalConfig"); element.setAttribute("content", getStringOption(KEY_INTRO_DIR) + "/sample.xml"); extension.add(element); 109 110 if (!extension.isInTheModel()) 111 plugin.add(extension); 112 } 113 114 protected boolean isOkToCreateFolder(File sourceFolder) { 115 return true; 116 } 117 118 121 protected boolean isOkToCreateFile(File sourceFile) { 122 return true; 123 } 124 125 public String getUsedExtensionPoint() { 126 return "org.eclipse.ui.intro.configExtension"; } 128 129 public IPluginReference[] getDependencies(String schemaVersion) { 130 ArrayList result = new ArrayList (); 131 132 result.add(new PluginReference("org.eclipse.ui.intro", null, 0)); result.add(new PluginReference( 137 "org.eclipse.ui.intro.universal", null, 0)); result.add(new PluginReference("org.eclipse.ui", null, 0)); 140 return (IPluginReference[]) result.toArray(new IPluginReference[result 141 .size()]); 142 } 143 144 public int getNumberOfWorkUnits() { 145 return super.getNumberOfWorkUnits() + 1; 146 } 147 148 152 public String getStringOption(String name) { 153 if (name.equals(KEY_EXTENSION_ID)) { 154 return stripNonAlphanumeric(pluginId) + "-introExtension"; } 156 if (name.equals(KEY_LINK_ID)) { 157 return stripNonAlphanumeric(pluginId) + "-introLink"; } 159 return super.getStringOption(name); 160 } 161 162 165 private String stripNonAlphanumeric(String id) { 166 StringBuffer result = new StringBuffer (); 167 for (int i = 0; i < id.length(); i++) { 168 char next = id.charAt(i); 169 if (Character.isLetterOrDigit(next)) { 170 result.append(next); 171 } 172 } 173 return result.toString(); 174 } 175 176 public String [] getNewFiles() { 177 return new String [] { getStringOption(KEY_INTRO_DIR) + "/" }; } 179 } | Popular Tags |