1 11 package org.eclipse.pde.internal.ui.templates.ide; 12 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.jface.wizard.Wizard; 17 import org.eclipse.jface.wizard.WizardPage; 18 import org.eclipse.pde.core.plugin.IPluginBase; 19 import org.eclipse.pde.core.plugin.IPluginElement; 20 import org.eclipse.pde.core.plugin.IPluginExtension; 21 import org.eclipse.pde.core.plugin.IPluginModelBase; 22 import org.eclipse.pde.core.plugin.IPluginModelFactory; 23 import org.eclipse.pde.core.plugin.IPluginReference; 24 import org.eclipse.pde.internal.ui.templates.IHelpContextIds; 25 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 26 import org.eclipse.pde.internal.ui.templates.PluginReference; 27 import org.eclipse.pde.ui.IFieldData; 28 import org.eclipse.pde.ui.templates.TemplateOption; 29 30 public class EditorTemplate extends BaseEditorTemplate { 31 public static final String EDITOR_CLASS_NAME = "editorClass"; public static final String EDITOR_NAME = "editorName"; public static final String EXTENSIONS = "extensions"; 37 public EditorTemplate() { 38 setPageCount(1); 39 createOptions(); 40 } 41 42 45 public IPluginReference[] getDependencies(String schemaVersion) { 46 if (schemaVersion != null) { 47 IPluginReference[] dep = new IPluginReference[4]; 48 dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); dep[1] = new PluginReference("org.eclipse.ui", null, 0); dep[2] = new PluginReference("org.eclipse.jface.text", null, 0); dep[3] = new PluginReference("org.eclipse.ui.editors", null, 0); return dep; 53 } 54 return super.getDependencies(schemaVersion); 55 } 56 57 public void addPages(Wizard wizard) { 58 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_EDITOR); 59 page.setTitle(PDETemplateMessages.EditorTemplate_title); 60 page.setDescription(PDETemplateMessages.EditorTemplate_desc); 61 wizard.addPage(page); 62 markPagesAdded(); 63 } 64 65 private void createOptions() { 66 addOption( 68 KEY_PACKAGE_NAME, 69 PDETemplateMessages.EditorTemplate_packageName, 70 (String ) null, 71 0); 72 addOption( 73 EDITOR_CLASS_NAME, 74 PDETemplateMessages.EditorTemplate_editorClass, 75 "XMLEditor", 0); 77 addOption( 78 EDITOR_NAME, 79 PDETemplateMessages.EditorTemplate_editorName, 80 PDETemplateMessages.EditorTemplate_defaultEditorName, 81 0); 82 addOption( 83 EXTENSIONS, 84 PDETemplateMessages.EditorTemplate_fileExtension, 85 "xml", 0); 87 } 88 89 public String getSectionId() { 90 return "editor"; } 92 95 public int getNumberOfWorkUnits() { 96 return super.getNumberOfWorkUnits() + 1; 97 } 98 99 protected void initializeFields(IFieldData data) { 100 String id = data.getId(); 103 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 104 } 105 public void initializeFields(IPluginModelBase model) { 106 String pluginId = model.getPluginBase().getId(); 109 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 110 } 111 112 public boolean isDependentOnParentWizard() { 113 return true; 114 } 115 116 119 public void validateOptions(TemplateOption source) { 120 if (source.isRequired() && source.isEmpty()) { 121 flagMissingRequiredOption(source); 122 } else { 123 validateContainerPage(source); 124 } 125 } 126 127 private void validateContainerPage(TemplateOption source) { 128 TemplateOption[] options = getOptions(0); 129 for (int i = 0; i < options.length; i++) { 130 TemplateOption nextOption = options[i]; 131 if (nextOption.isRequired() && nextOption.isEmpty()) { 132 flagMissingRequiredOption(nextOption); 133 return; 134 } 135 } 136 resetPageState(); 137 } 138 139 protected void updateModel(IProgressMonitor monitor) throws CoreException { 140 IPluginBase plugin = model.getPluginBase(); 141 IPluginExtension extension = createExtension(getUsedExtensionPoint(), true); 142 IPluginModelFactory factory = model.getPluginFactory(); 143 144 IPluginElement editorElement = factory.createElement(extension); 145 editorElement.setName("editor"); editorElement.setAttribute( 147 "id", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(EDITOR_CLASS_NAME)); editorElement.setAttribute("name", getStringOption(EDITOR_NAME)); editorElement.setAttribute("icon", "icons/sample.gif"); editorElement.setAttribute("extensions", getStringOption(EXTENSIONS)); 153 editorElement.setAttribute( 154 "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(EDITOR_CLASS_NAME)); editorElement.setAttribute( 157 "contributorClass", "org.eclipse.ui.texteditor.BasicTextEditorActionContributor"); extension.add(editorElement); 160 if (!extension.isInTheModel()) 161 plugin.add(extension); 162 } 163 164 167 protected String getFormattedPackageName(String id) { 168 String packageName = super.getFormattedPackageName(id); 169 if (packageName.length() != 0) 170 return packageName + ".editors"; return "editors"; } 173 } 174 | Popular Tags |