1 11 package org.eclipse.pde.internal.ui.wizards.templates; 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.IHelpContextIds; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 import org.eclipse.pde.ui.IFieldData; 28 import org.eclipse.pde.ui.templates.TemplateOption; 29 30 public class ImportWizardTemplate extends PDETemplateSection { 31 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"; 37 private WizardPage page; 38 39 42 public ImportWizardTemplate() { 43 setPageCount(1); 44 createOptions(); 45 } 46 47 50 public IPluginReference[] getDependencies(String schemaVersion) { 51 if (schemaVersion != null) { 53 IPluginReference[] dep = new IPluginReference[2]; 54 dep[0] = new PluginReference("org.eclipse.ui.ide", null, 0); dep[1] = new PluginReference("org.eclipse.core.resources", null, 0); return dep; 57 } 58 return super.getDependencies(schemaVersion); 59 } 60 61 65 public String getSectionId() { 66 return "importWizard"; } 71 72 75 public int getNumberOfWorkUnits() { 76 return super.getNumberOfWorkUnits() + 1; 77 } 78 79 84 private void createOptions() { 85 String [][] choices = fromCommaSeparated(PDEUIMessages.ImportWizardTemplate_filterChoices); 86 87 addOption( 88 KEY_PACKAGE_NAME, 89 PDEUIMessages.ImportWizardTemplate_packageName, 90 (String ) null, 91 0); 92 addOption( 93 WIZARD_CLASS_NAME, 94 PDEUIMessages.ImportWizardTemplate_wizardClass, 95 PDEUIMessages.ImportWizardTemplate_wizardClassName, 96 0); 97 addOption( 98 WIZARD_PAGE_CLASS_NAME, 99 PDEUIMessages.ImportWizardTemplate_pageClass, 100 PDEUIMessages.ImportWizardTemplate_pageClassName, 101 0); 102 103 addBlankField(0); 104 105 addOption( 106 WIZARD_CATEGORY_NAME, 107 PDEUIMessages.ImportWizardTemplate_importWizardCategory, 108 PDEUIMessages.ImportWizardTemplate_importWizardCategoryName, 109 0); 110 addOption( 111 WIZARD_IMPORT_NAME, 112 PDEUIMessages.ImportWizardTemplate_wizardName, 113 PDEUIMessages.ImportWizardTemplate_wizardDefaultName, 114 0); 115 116 addBlankField(0); 117 118 addOption(WIZARD_FILE_FILTERS, 119 PDEUIMessages.ImportWizardTemplate_filters, 120 choices, 121 choices[0][0], 122 0); 123 } 124 125 128 public void addPages(Wizard wizard) { 129 int pageIndex = 0; 130 131 page = createPage(pageIndex, IHelpContextIds.TEMPLATE_EDITOR); 132 page.setTitle(PDEUIMessages.ImportWizardTemplate_title); 133 page.setDescription(PDEUIMessages.ImportWizardTemplate_desc); 134 135 wizard.addPage(page); 136 markPagesAdded(); 137 } 138 139 142 public void validateOptions(TemplateOption source) { 143 if (source.isRequired() && source.isEmpty()) { 146 flagMissingRequiredOption(source); 147 } else { 148 validateContainerPage(source); 149 } 150 } 151 152 160 private void validateContainerPage(TemplateOption source) { 161 TemplateOption[] allPageOptions = getOptions(0); 162 for (int i = 0; i < allPageOptions.length; i++) { 163 TemplateOption nextOption = allPageOptions[i]; 164 if (nextOption.isRequired() && nextOption.isEmpty()) { 165 flagMissingRequiredOption(nextOption); 166 return; 167 } 168 } 169 resetPageState(); 170 } 171 172 173 176 public boolean isDependentOnParentWizard() { 177 return true; 178 } 179 180 183 protected void initializeFields(IFieldData data) { 184 String id = data.getId(); 187 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 188 } 189 190 193 public void initializeFields(IPluginModelBase model) { 194 String pluginId = model.getPluginBase().getId(); 197 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 198 } 199 200 203 protected void updateModel(IProgressMonitor monitor) throws CoreException { 204 IPluginBase plugin = model.getPluginBase(); 209 IPluginExtension extension = createExtension(getUsedExtensionPoint(),true); 210 IPluginModelFactory factory = model.getPluginFactory(); 211 212 IPluginElement categoryElement = factory.createElement(extension); 213 categoryElement.setName("category"); categoryElement.setAttribute( 215 "id", getStringOption(KEY_PACKAGE_NAME) + ".sampleCategory"); categoryElement.setAttribute( 217 "name", getStringOption(WIZARD_CATEGORY_NAME)); 219 IPluginElement wizardElement = factory.createElement(extension); 220 wizardElement.setName("wizard"); wizardElement.setAttribute( 222 "id", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(WIZARD_CLASS_NAME)); wizardElement.setAttribute("name", getStringOption(WIZARD_IMPORT_NAME)); wizardElement.setAttribute( 225 "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(WIZARD_CLASS_NAME)); wizardElement.setAttribute( 227 "category", getStringOption(KEY_PACKAGE_NAME) + ".sampleCategory"); wizardElement.setAttribute("icon", "icons/sample.gif"); 230 IPluginElement descriptionElement = factory.createElement(extension); 231 descriptionElement.setName("description"); descriptionElement.setText(PDEUIMessages.ImportWizardTemplate_wizardDescription); 233 234 wizardElement.add(descriptionElement); 235 extension.add(categoryElement); 236 extension.add(wizardElement); 237 if (!extension.isInTheModel()) 238 plugin.add(extension); 239 } 240 241 244 public String [] getNewFiles() { 245 return new String [] { "icons/" }; } 247 248 251 protected String getFormattedPackageName(String id) { 252 String packageName = super.getFormattedPackageName(id); 255 if (packageName.length() != 0) 256 return packageName + ".importWizards"; return "importWizards"; } 259 260 263 public String getUsedExtensionPoint() { 264 return "org.eclipse.ui.importWizards"; } 266 267 276 protected String [][] fromCommaSeparated(String iconLocations) { 277 StringTokenizer tokens = new StringTokenizer (iconLocations, ","); String [][] choices = new String [tokens.countTokens() / 2][2]; 279 int x = 0, y = 0; 280 while (tokens.hasMoreTokens()) { 281 choices[x][y++] = tokens.nextToken(); 282 choices[x++][y--] = tokens.nextToken(); 283 } 284 return choices; 285 } 286 } 287 | Popular Tags |