1 11 package org.eclipse.pde.internal.ui.templates.ide; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.jface.wizard.Wizard; 16 import org.eclipse.jface.wizard.WizardPage; 17 import org.eclipse.pde.core.plugin.IPluginBase; 18 import org.eclipse.pde.core.plugin.IPluginElement; 19 import org.eclipse.pde.core.plugin.IPluginExtension; 20 import org.eclipse.pde.core.plugin.IPluginModelBase; 21 import org.eclipse.pde.core.plugin.IPluginModelFactory; 22 import org.eclipse.pde.core.plugin.IPluginReference; 23 import org.eclipse.pde.internal.ui.templates.IHelpContextIds; 24 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 25 import org.eclipse.pde.internal.ui.templates.PluginReference; 26 import org.eclipse.pde.ui.IFieldData; 27 import org.eclipse.pde.ui.templates.TemplateOption; 28 29 public class MultiPageEditorTemplate extends BaseEditorTemplate { 30 33 public MultiPageEditorTemplate() { 34 setPageCount(1); 35 createOptions(); 36 } 37 38 public String getSectionId() { 39 return "multiPageEditor"; } 41 42 public IPluginReference[] getDependencies(String schemaVersion) { 43 if (schemaVersion != null) { 44 IPluginReference[] dep = new IPluginReference[6]; 45 dep[0] = new PluginReference("org.eclipse.jface.text", null, 0); dep[1] = new PluginReference("org.eclipse.core.resources", null, 0); dep[2] = new PluginReference("org.eclipse.ui", null, 0); dep[3] = new PluginReference("org.eclipse.ui.editors", null, 0); dep[4] = new PluginReference("org.eclipse.ui.ide", null, 0); dep[5] = new PluginReference("org.eclipse.core.runtime", null, 0); return dep; 52 } 53 return super.getDependencies(schemaVersion); 54 } 55 56 59 public int getNumberOfWorkUnits() { 60 return super.getNumberOfWorkUnits() + 1; 61 } 62 63 private void createOptions() { 64 addOption( 66 KEY_PACKAGE_NAME, 67 PDETemplateMessages.MultiPageEditorTemplate_packageName, 68 (String ) null, 69 0); 70 addOption( 71 "editorClassName", PDETemplateMessages.MultiPageEditorTemplate_className, 73 "MultiPageEditor", 0); 75 addOption( 76 "contributorClassName", PDETemplateMessages.MultiPageEditorTemplate_contributor, 78 "MultiPageEditorContributor", 0); 80 addOption( 81 "editorName", PDETemplateMessages.MultiPageEditorTemplate_editorName, 83 PDETemplateMessages.MultiPageEditorTemplate_defaultEditorName, 84 0); 85 addOption( 86 "extensions", PDETemplateMessages.MultiPageEditorTemplate_extensions, 88 "mpe", 0); 90 } 91 92 protected void initializeFields(IFieldData data) { 93 String id = data.getId(); 96 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 97 } 98 public void initializeFields(IPluginModelBase model) { 99 String pluginId = model.getPluginBase().getId(); 102 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 103 } 104 105 public boolean isDependentOnParentWizard() { 106 return true; 107 } 108 109 public void addPages(Wizard wizard) { 110 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_MULTIPAGE_EDITOR); 111 page.setTitle(PDETemplateMessages.MultiPageEditorTemplate_title); 112 page.setDescription(PDETemplateMessages.MultiPageEditorTemplate_desc); 113 wizard.addPage(page); 114 markPagesAdded(); 115 } 116 117 public void validateOptions(TemplateOption source) { 118 if (source.isRequired() && source.isEmpty()) { 119 flagMissingRequiredOption(source); 120 } else { 121 validateContainerPage(source); 122 } 123 } 124 125 private void validateContainerPage(TemplateOption source) { 126 TemplateOption[] allPageOptions = getOptions(0); 127 for (int i = 0; i < allPageOptions.length; i++) { 128 TemplateOption nextOption = allPageOptions[i]; 129 if (nextOption.isRequired() && nextOption.isEmpty()) { 130 flagMissingRequiredOption(nextOption); 131 return; 132 } 133 } 134 resetPageState(); 135 } 136 137 protected void updateModel(IProgressMonitor monitor) throws CoreException { 138 IPluginBase plugin = model.getPluginBase(); 139 IPluginExtension extension = createExtension("org.eclipse.ui.editors", true); IPluginModelFactory factory = model.getPluginFactory(); 141 142 String editorClassName = 143 getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption("editorClassName"); String contributorClassName = 145 getStringOption(KEY_PACKAGE_NAME) 146 + "." + getStringOption("contributorClassName"); 149 IPluginElement editorElement = factory.createElement(extension); 150 editorElement.setName("editor"); editorElement.setAttribute("id", editorClassName); editorElement.setAttribute("name", getStringOption("editorName")); editorElement.setAttribute("icon", "icons/sample.gif"); editorElement.setAttribute("extensions", getStringOption("extensions")); 156 editorElement.setAttribute("class", editorClassName); editorElement.setAttribute("contributorClass", contributorClassName); extension.add(editorElement); 159 if (!extension.isInTheModel()) 160 plugin.add(extension); 161 } 162 163 166 protected String getFormattedPackageName(String id) { 167 String packageName = super.getFormattedPackageName(id); 168 if (packageName.length() != 0) 169 return packageName + ".editors"; return "editors"; } 172 173 } 174 | Popular Tags |