1 11 package org.eclipse.pde.internal.ui.templates.ide; 12 13 import java.util.StringTokenizer ; 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.IPluginModelBase; 23 import org.eclipse.pde.core.plugin.IPluginModelFactory; 24 import org.eclipse.pde.core.plugin.IPluginReference; 25 import org.eclipse.pde.internal.ui.templates.IHelpContextIds; 26 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 27 import org.eclipse.pde.internal.ui.templates.PDETemplateSection; 28 import org.eclipse.pde.internal.ui.templates.PluginReference; 29 import org.eclipse.pde.ui.IFieldData; 30 31 public class ImportWizardTemplate extends PDETemplateSection { 32 public static final String WIZARD_CLASS_NAME = "wizardClassName"; public static final String WIZARD_CATEGORY_NAME = "wizardCategoryName"; public static final String WIZARD_PAGE_CLASS_NAME = "wizardPageClassName"; public static final String WIZARD_IMPORT_NAME = "wizardImportName"; public static final String WIZARD_FILE_FILTERS = "wizardFileFilters"; 38 private WizardPage page; 39 40 43 public ImportWizardTemplate() { 44 setPageCount(1); 45 createOptions(); 46 } 47 48 51 public IPluginReference[] getDependencies(String schemaVersion) { 52 if (schemaVersion != null) { 54 IPluginReference[] dep = new IPluginReference[2]; 55 dep[0] = new PluginReference("org.eclipse.ui.ide", null, 0); dep[1] = new PluginReference("org.eclipse.core.resources", null, 0); return dep; 58 } 59 return super.getDependencies(schemaVersion); 60 } 61 62 66 public String getSectionId() { 67 return "importWizard"; } 72 73 76 public int getNumberOfWorkUnits() { 77 return super.getNumberOfWorkUnits() + 1; 78 } 79 80 85 private void createOptions() { 86 String [][] choices = fromCommaSeparated(PDETemplateMessages.ImportWizardTemplate_filterChoices); 87 88 addOption( 89 KEY_PACKAGE_NAME, 90 PDETemplateMessages.ImportWizardTemplate_packageName, 91 (String ) null, 92 0); 93 addOption( 94 WIZARD_CLASS_NAME, 95 PDETemplateMessages.ImportWizardTemplate_wizardClass, 96 PDETemplateMessages.ImportWizardTemplate_wizardClassName, 97 0); 98 addOption( 99 WIZARD_PAGE_CLASS_NAME, 100 PDETemplateMessages.ImportWizardTemplate_pageClass, 101 PDETemplateMessages.ImportWizardTemplate_pageClassName, 102 0); 103 104 addBlankField(0); 105 106 addOption( 107 WIZARD_CATEGORY_NAME, 108 PDETemplateMessages.ImportWizardTemplate_importWizardCategory, 109 PDETemplateMessages.ImportWizardTemplate_importWizardCategoryName, 110 0); 111 addOption( 112 WIZARD_IMPORT_NAME, 113 PDETemplateMessages.ImportWizardTemplate_wizardName, 114 PDETemplateMessages.ImportWizardTemplate_wizardDefaultName, 115 0); 116 117 addBlankField(0); 118 119 addOption(WIZARD_FILE_FILTERS, 120 PDETemplateMessages.ImportWizardTemplate_filters, 121 choices, 122 choices[0][0], 123 0); 124 } 125 126 129 public void addPages(Wizard wizard) { 130 int pageIndex = 0; 131 132 page = createPage(pageIndex, IHelpContextIds.TEMPLATE_EDITOR); 133 page.setTitle(PDETemplateMessages.ImportWizardTemplate_title); 134 page.setDescription(PDETemplateMessages.ImportWizardTemplate_desc); 135 136 wizard.addPage(page); 137 markPagesAdded(); 138 } 139 140 143 public boolean isDependentOnParentWizard() { 144 return true; 145 } 146 147 150 protected void initializeFields(IFieldData data) { 151 String id = data.getId(); 154 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 155 } 156 157 160 public void initializeFields(IPluginModelBase model) { 161 String pluginId = model.getPluginBase().getId(); 164 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 165 } 166 167 170 protected void updateModel(IProgressMonitor monitor) throws CoreException { 171 IPluginBase plugin = model.getPluginBase(); 176 IPluginExtension extension = createExtension(getUsedExtensionPoint(),true); 177 IPluginModelFactory factory = model.getPluginFactory(); 178 179 IPluginElement categoryElement = factory.createElement(extension); 180 categoryElement.setName("category"); categoryElement.setAttribute( 182 "id", getStringOption(KEY_PACKAGE_NAME) + ".sampleCategory"); categoryElement.setAttribute( 184 "name", getStringOption(WIZARD_CATEGORY_NAME)); 186 IPluginElement wizardElement = factory.createElement(extension); 187 wizardElement.setName("wizard"); wizardElement.setAttribute( 189 "id", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(WIZARD_CLASS_NAME)); wizardElement.setAttribute("name", getStringOption(WIZARD_IMPORT_NAME)); wizardElement.setAttribute( 192 "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(WIZARD_CLASS_NAME)); wizardElement.setAttribute( 194 "category", getStringOption(KEY_PACKAGE_NAME) + ".sampleCategory"); wizardElement.setAttribute("icon", "icons/sample.gif"); 197 IPluginElement descriptionElement = factory.createElement(extension); 198 descriptionElement.setName("description"); descriptionElement.setText(PDETemplateMessages.ImportWizardTemplate_wizardDescription); 200 201 wizardElement.add(descriptionElement); 202 extension.add(categoryElement); 203 extension.add(wizardElement); 204 if (!extension.isInTheModel()) 205 plugin.add(extension); 206 } 207 208 211 public String [] getNewFiles() { 212 return new String [] { "icons/" }; } 214 215 218 protected String getFormattedPackageName(String id) { 219 String packageName = super.getFormattedPackageName(id); 222 if (packageName.length() != 0) 223 return packageName + ".importWizards"; return "importWizards"; } 226 227 230 public String getUsedExtensionPoint() { 231 return "org.eclipse.ui.importWizards"; } 233 234 243 protected String [][] fromCommaSeparated(String iconLocations) { 244 StringTokenizer tokens = new StringTokenizer (iconLocations, ","); String [][] choices = new String [tokens.countTokens() / 2][2]; 246 int x = 0, y = 0; 247 while (tokens.hasMoreTokens()) { 248 choices[x][y++] = tokens.nextToken(); 249 choices[x++][y--] = tokens.nextToken(); 250 } 251 return choices; 252 } 253 } 254 | Popular Tags |