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.PDETemplateSection; 26 import org.eclipse.pde.internal.ui.templates.PluginReference; 27 import org.eclipse.pde.ui.IFieldData; 28 29 public class PreferencePageTemplate extends PDETemplateSection { 30 private static final String KEY_PAGE_NAME = "pageName"; private static final String KEY_PAGE_CLASS_NAME = "pageClassName"; 33 public PreferencePageTemplate() { 34 setPageCount(1); 35 createOptions(); 36 } 37 38 public String getSectionId() { 39 return "preferences"; } 41 44 public int getNumberOfWorkUnits() { 45 return super.getNumberOfWorkUnits() + 1; 46 } 47 48 private void createOptions() { 49 addOption( 51 KEY_PACKAGE_NAME, 52 PDETemplateMessages.PreferencePageTemplate_packageName, 53 (String ) null, 54 0); 55 addOption( 56 KEY_PAGE_CLASS_NAME, 57 PDETemplateMessages.PreferencePageTemplate_className, 58 "SamplePreferencePage", 0); 60 addOption( 61 KEY_PAGE_NAME, 62 PDETemplateMessages.PreferencePageTemplate_pageName, 63 PDETemplateMessages.PreferencePageTemplate_defaultPageName, 64 0); 65 } 66 67 protected void initializeFields(IFieldData data) { 68 String id = data.getId(); 71 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 72 } 73 74 public void initializeFields(IPluginModelBase model) { 75 String pluginId = model.getPluginBase().getId(); 78 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 79 } 80 81 protected String getTemplateDirectory() { 82 String schemaVersion = model.getPluginBase().getSchemaVersion(); 83 return "templates_" + schemaVersion == null ? "3.0" : schemaVersion; } 85 86 public boolean isDependentOnParentWizard() { 87 return true; 88 } 89 90 93 public IPluginReference[] getDependencies(String schemaVersion) { 94 if (schemaVersion == null) 95 return super.getDependencies(schemaVersion); 96 PluginReference[] deps = new PluginReference[2]; 97 deps[0] = new PluginReference("org.eclipse.core.runtime", null, 0); deps[1] = new PluginReference("org.eclipse.ui", null, 0); return deps; 100 } 101 102 public void addPages(Wizard wizard) { 103 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_PREFERENCE_PAGE); 104 page.setTitle(PDETemplateMessages.PreferencePageTemplate_title); 105 page.setDescription(PDETemplateMessages.PreferencePageTemplate_desc); 106 wizard.addPage(page); 107 markPagesAdded(); 108 } 109 110 public String getUsedExtensionPoint() { 111 return "org.eclipse.ui.preferencePages"; } 113 114 protected void updateModel(IProgressMonitor monitor) throws CoreException { 115 IPluginBase plugin = model.getPluginBase(); 116 IPluginExtension extension = createExtension(getUsedExtensionPoint(), true); 117 IPluginModelFactory factory = model.getPluginFactory(); 118 119 String fullClassName = 120 getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_PAGE_CLASS_NAME); 122 IPluginElement pageElement = factory.createElement(extension); 123 pageElement.setName("page"); pageElement.setAttribute("id", fullClassName); pageElement.setAttribute("name", getStringOption(KEY_PAGE_NAME)); pageElement.setAttribute("class", fullClassName); extension.add(pageElement); 128 if (!extension.isInTheModel()) 129 plugin.add(extension); 130 131 IPluginExtension extension2 = createExtension("org.eclipse.core.runtime.preferences", true); IPluginElement prefElement = factory.createElement(extension); 133 prefElement.setName("initializer"); prefElement.setAttribute("class", getStringOption(KEY_PACKAGE_NAME)+".PreferenceInitializer"); extension2.add(prefElement); 136 if (!extension2.isInTheModel()) 137 plugin.add(extension2); 138 } 139 140 141 144 protected String getFormattedPackageName(String id) { 145 String packageName = super.getFormattedPackageName(id); 146 if (packageName.length() != 0) 147 return packageName + ".preferences"; return "preferences"; } 150 } 151 | Popular Tags |