1 11 12 package org.eclipse.pde.internal.ui.templates.ide; 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.templates.IHelpContextIds; 29 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 30 import org.eclipse.pde.internal.ui.templates.PDETemplateSection; 31 import org.eclipse.pde.internal.ui.templates.PluginReference; 32 import org.eclipse.pde.ui.IFieldData; 33 34 public class NewWizardTemplate extends PDETemplateSection { 35 public NewWizardTemplate() { 36 setPageCount(1); 37 createOptions(); 38 } 39 40 public String getSectionId() { 41 return "newWizard"; } 43 46 public int getNumberOfWorkUnits() { 47 return super.getNumberOfWorkUnits()+1; 48 } 49 50 private void createOptions() { 51 addOption(KEY_PACKAGE_NAME, PDETemplateMessages.NewWizardTemplate_packageName, (String )null, 0); 53 addOption("categoryId", PDETemplateMessages.NewWizardTemplate_categoryId, (String )null, 0); addOption("categoryName", PDETemplateMessages.NewWizardTemplate_categoryName, "Sample Wizards", 0); addOption("wizardClassName", PDETemplateMessages.NewWizardTemplate_className, "SampleNewWizard", 0); addOption("wizardPageClassName", PDETemplateMessages.NewWizardTemplate_pageClassName, "SampleNewWizardPage", 0); addOption("wizardName", PDETemplateMessages.NewWizardTemplate_wizardName, PDETemplateMessages.NewWizardTemplate_defaultName, 0); addOption("extension", PDETemplateMessages.NewWizardTemplate_extension, "mpe", 0); addOption("initialFileName", PDETemplateMessages.NewWizardTemplate_fileName,"new_file.mpe", 0); } 61 62 protected void initializeFields(IFieldData data) { 63 String id = data.getId(); 66 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 67 initializeOption("categoryId", id); } 69 public void initializeFields(IPluginModelBase model) { 70 String pluginId = model.getPluginBase().getId(); 73 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 74 initializeOption("categoryId", pluginId); } 76 77 80 public IPluginReference[] getDependencies(String schemaVersion) { 81 ArrayList result = new ArrayList (); 82 result.add(new PluginReference("org.eclipse.core.resources", null, 0)); result.add(new PluginReference("org.eclipse.ui", null, 0)); if (schemaVersion != null) { 85 result.add(new PluginReference("org.eclipse.ui.ide", null, 0)); result.add(new PluginReference("org.eclipse.core.runtime", null, 0)); } 88 return (IPluginReference[])result.toArray(new IPluginReference[result.size()]); 89 } 90 91 public boolean isDependentOnParentWizard() { 92 return true; 93 } 94 95 public void addPages(Wizard wizard) { 96 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_NEW_WIZARD); 97 page.setTitle(PDETemplateMessages.NewWizardTemplate_title); 98 page.setDescription(PDETemplateMessages.NewWizardTemplate_desc); 99 wizard.addPage(page); 100 markPagesAdded(); 101 } 102 103 public String getUsedExtensionPoint() { 104 return "org.eclipse.ui.newWizards"; } 106 107 protected void updateModel(IProgressMonitor monitor) throws CoreException { 108 IPluginBase plugin = model.getPluginBase(); 109 IPluginExtension extension = createExtension("org.eclipse.ui.newWizards", true); IPluginModelFactory factory = model.getPluginFactory(); 111 112 String cid = getStringOption("categoryId"); 114 createCategory(extension, cid); 115 String fullClassName = getStringOption(KEY_PACKAGE_NAME)+"."+getStringOption("wizardClassName"); 117 IPluginElement viewElement = factory.createElement(extension); 118 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); 125 if (!extension.isInTheModel()) 126 plugin.add(extension); 127 } 128 129 private void createCategory(IPluginExtension extension, String id) throws CoreException { 130 IPluginObject [] elements = extension.getChildren(); 131 for (int i=0; i<elements.length; i++) { 132 IPluginElement element = (IPluginElement)elements[i]; 133 if (element.getName().equalsIgnoreCase("category")) { IPluginAttribute att = element.getAttribute("id"); if (att!=null) { 136 String cid = att.getValue(); 137 if (cid!=null && cid.equals(id)) 138 return; 139 } 140 } 141 } 142 IPluginElement categoryElement = model.getFactory().createElement(extension); 143 categoryElement.setName("category"); categoryElement.setAttribute("name", getStringOption("categoryName")); categoryElement.setAttribute("id", id); extension.add(categoryElement); 147 } 148 149 152 public String [] getNewFiles() { 153 return new String [] {"icons/"}; } 155 156 159 protected String getFormattedPackageName(String id) { 160 String packageName = super.getFormattedPackageName(id); 161 if (packageName.length() != 0 ) 162 return packageName + ".wizards"; return "wizards"; } 165 } 166 | Popular Tags |