1 11 12 package org.eclipse.pde.internal.ui.wizards.templates; 13 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.jface.wizard.Wizard; 19 import org.eclipse.jface.wizard.WizardPage; 20 import org.eclipse.pde.core.plugin.IPluginAttribute; 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.IPluginObject; 27 import org.eclipse.pde.core.plugin.IPluginReference; 28 import org.eclipse.pde.internal.ui.IHelpContextIds; 29 import org.eclipse.pde.internal.ui.PDEUIMessages; 30 import org.eclipse.pde.ui.IFieldData; 31 import org.eclipse.pde.ui.templates.TemplateOption; 32 33 public class NewWizardTemplate extends PDETemplateSection { 34 public NewWizardTemplate() { 35 setPageCount(1); 36 createOptions(); 37 } 38 39 public String getSectionId() { 40 return "newWizard"; } 42 45 public int getNumberOfWorkUnits() { 46 return super.getNumberOfWorkUnits()+1; 47 } 48 49 private void createOptions() { 50 addOption(KEY_PACKAGE_NAME, PDEUIMessages.NewWizardTemplate_packageName, (String )null, 0); 52 addOption("categoryId", PDEUIMessages.NewWizardTemplate_categoryId, (String )null, 0); addOption("categoryName", PDEUIMessages.NewWizardTemplate_categoryName, "Sample Wizards", 0); addOption("wizardClassName", PDEUIMessages.NewWizardTemplate_className, "SampleNewWizard", 0); addOption("wizardPageClassName", PDEUIMessages.NewWizardTemplate_pageClassName, "SampleNewWizardPage", 0); addOption("wizardName", PDEUIMessages.NewWizardTemplate_wizardName, PDEUIMessages.NewWizardTemplate_defaultName, 0); addOption("extension", PDEUIMessages.NewWizardTemplate_extension, "mpe", 0); addOption("initialFileName", PDEUIMessages.NewWizardTemplate_fileName,"new_file.mpe", 0); } 60 61 protected void initializeFields(IFieldData data) { 62 String id = data.getId(); 65 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 66 initializeOption("categoryId", id); } 68 public void initializeFields(IPluginModelBase model) { 69 String pluginId = model.getPluginBase().getId(); 72 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 73 initializeOption("categoryId", pluginId); } 75 76 79 public IPluginReference[] getDependencies(String schemaVersion) { 80 ArrayList result = new ArrayList (); 81 result.add(new PluginReference("org.eclipse.core.resources", null, 0)); result.add(new PluginReference("org.eclipse.ui", null, 0)); if (schemaVersion != null) { 84 result.add(new PluginReference("org.eclipse.ui.ide", null, 0)); result.add(new PluginReference("org.eclipse.core.runtime", null, 0)); } 87 return (IPluginReference[])result.toArray(new IPluginReference[result.size()]); 88 } 89 90 public boolean isDependentOnParentWizard() { 91 return true; 92 } 93 94 public void addPages(Wizard wizard) { 95 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_NEW_WIZARD); 96 page.setTitle(PDEUIMessages.NewWizardTemplate_title); 97 page.setDescription(PDEUIMessages.NewWizardTemplate_desc); 98 wizard.addPage(page); 99 markPagesAdded(); 100 } 101 102 public void validateOptions(TemplateOption source) { 103 if (source.isRequired() && source.isEmpty()) { 104 flagMissingRequiredOption(source); 105 } else { 106 validateContainerPage(source); 107 } 108 } 109 110 private void validateContainerPage(TemplateOption source) { 111 TemplateOption[] allPageOptions = getOptions(0); 112 for (int i = 0; i < allPageOptions.length; i++) { 113 TemplateOption nextOption = allPageOptions[i]; 114 if (nextOption.isRequired() && nextOption.isEmpty()) { 115 flagMissingRequiredOption(nextOption); 116 return; 117 } 118 } 119 resetPageState(); 120 } 121 122 public String getUsedExtensionPoint() { 123 return "org.eclipse.ui.newWizards"; } 125 126 protected void updateModel(IProgressMonitor monitor) throws CoreException { 127 IPluginBase plugin = model.getPluginBase(); 128 IPluginExtension extension = createExtension("org.eclipse.ui.newWizards", true); IPluginModelFactory factory = model.getPluginFactory(); 130 131 String cid = getStringOption("categoryId"); 133 createCategory(extension, cid); 134 String fullClassName = getStringOption(KEY_PACKAGE_NAME)+"."+getStringOption("wizardClassName"); 136 IPluginElement viewElement = factory.createElement(extension); 137 viewElement.setName("wizard"); viewElement.setAttribute("id", fullClassName); viewElement.setAttribute("name", getStringOption("wizardName")); viewElement.setAttribute("icon", "icons/sample.gif"); viewElement.setAttribute("class", fullClassName); viewElement.setAttribute("category", cid); extension.add(viewElement); 144 if (!extension.isInTheModel()) 145 plugin.add(extension); 146 } 147 148 private void createCategory(IPluginExtension extension, String id) throws CoreException { 149 IPluginObject [] elements = extension.getChildren(); 150 for (int i=0; i<elements.length; i++) { 151 IPluginElement element = (IPluginElement)elements[i]; 152 if (element.getName().equalsIgnoreCase("category")) { IPluginAttribute att = element.getAttribute("id"); if (att!=null) { 155 String cid = att.getValue(); 156 if (cid!=null && cid.equals(id)) 157 return; 158 } 159 } 160 } 161 IPluginElement categoryElement = model.getFactory().createElement(extension); 162 categoryElement.setName("category"); categoryElement.setAttribute("name", getStringOption("categoryName")); categoryElement.setAttribute("id", id); extension.add(categoryElement); 166 } 167 168 171 public String [] getNewFiles() { 172 return new String [] {"icons/"}; } 174 175 178 protected String getFormattedPackageName(String id) { 179 String packageName = super.getFormattedPackageName(id); 180 if (packageName.length() != 0 ) 181 return packageName + ".wizards"; return "wizards"; } 184 } 185 | Popular Tags |