1 11 package org.eclipse.pde.internal.ui.templates.ide; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.jface.wizard.Wizard; 18 import org.eclipse.jface.wizard.WizardPage; 19 import org.eclipse.pde.core.plugin.IPluginBase; 20 import org.eclipse.pde.core.plugin.IPluginElement; 21 import org.eclipse.pde.core.plugin.IPluginExtension; 22 import org.eclipse.pde.core.plugin.IPluginModelBase; 23 import org.eclipse.pde.core.plugin.IPluginModelFactory; 24 import org.eclipse.pde.core.plugin.IPluginReference; 25 import org.eclipse.pde.internal.ui.templates.IHelpContextIds; 26 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 27 import org.eclipse.pde.internal.ui.templates.PDETemplateSection; 28 import org.eclipse.pde.internal.ui.templates.PluginReference; 29 import org.eclipse.pde.ui.IFieldData; 30 31 public class PropertyPageTemplate extends PDETemplateSection { 32 public static final String KEY_CLASSNAME = "className"; public static final String KEY_PAGE_NAME = "pageName"; public static final String KEY_TARGET_CLASS = "targetClass"; public static final String KEY_NAME_FILTER = "nameFilter"; 37 40 public PropertyPageTemplate() { 41 setPageCount(1); 42 createOptions(); 43 } 44 45 public void addPages(Wizard wizard) { 46 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_PROPERTY_PAGE); 47 page.setTitle(PDETemplateMessages.PropertyPageTemplate_title); 48 page.setDescription(PDETemplateMessages.PropertyPageTemplate_desc); 49 wizard.addPage(page); 50 markPagesAdded(); 51 } 52 53 private void createOptions() { 54 addOption( 55 KEY_PACKAGE_NAME, 56 PDETemplateMessages.PropertyPageTemplate_packageName, 57 (String ) null, 58 0); 59 addOption( 60 KEY_CLASSNAME, 61 PDETemplateMessages.PropertyPageTemplate_pageClass, 62 "SamplePropertyPage", 0); 64 addOption( 65 KEY_PAGE_NAME, 66 PDETemplateMessages.PropertyPageTemplate_pageName, 67 PDETemplateMessages.PropertyPageTemplate_defaultPageName, 68 0); 69 addOption( 70 KEY_TARGET_CLASS, 71 PDETemplateMessages.PropertyPageTemplate_targetClass, 72 "org.eclipse.core.resources.IFile", 0); 74 addOption( 75 KEY_NAME_FILTER, 76 PDETemplateMessages.PropertyPageTemplate_nameFilter, 77 "*.*", 0); 79 } 80 83 public String getSectionId() { 84 return "propertyPages"; } 86 87 public boolean isDependentOnParentWizard() { 88 return true; 89 } 90 91 92 protected void initializeFields(IFieldData data) { 93 String id = data.getId(); 96 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 97 } 98 99 public void initializeFields(IPluginModelBase model) { 100 String pluginId = model.getPluginBase().getId(); 103 initializeOption(KEY_PACKAGE_NAME,getFormattedPackageName(pluginId)); 104 } 105 106 109 protected void updateModel(IProgressMonitor monitor) throws CoreException { 110 IPluginBase plugin = model.getPluginBase(); 111 IPluginExtension extension = createExtension(getUsedExtensionPoint(), true); 112 IPluginModelFactory factory = model.getPluginFactory(); 113 114 IPluginElement pageElement = factory.createElement(extension); 115 pageElement.setName("page"); pageElement.setAttribute( 117 "id", getStringOption(KEY_PACKAGE_NAME) + ".samplePropertyPage"); pageElement.setAttribute("name", getStringOption(KEY_PAGE_NAME)); pageElement.setAttribute("objectClass", getStringOption(KEY_TARGET_CLASS)); pageElement.setAttribute( 122 "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_CLASSNAME)); pageElement.setAttribute("nameFilter", getStringOption(KEY_NAME_FILTER)); 126 extension.add(pageElement); 127 if (!extension.isInTheModel()) 128 plugin.add(extension); 129 } 130 131 134 public String getUsedExtensionPoint() { 135 return "org.eclipse.ui.propertyPages"; } 137 138 141 public IPluginReference[] getDependencies(String schemaVersion) { 142 ArrayList result = new ArrayList (); 143 result.add(new PluginReference("org.eclipse.core.resources", null, 0)); if (schemaVersion != null) 145 result.add(new PluginReference("org.eclipse.core.runtime", null, 0)); result.add(new PluginReference("org.eclipse.ui", null, 0)); 148 return (IPluginReference[])result.toArray(new IPluginReference[result.size()]); 149 } 150 151 154 protected String getFormattedPackageName(String id) { 155 String packageName = super.getFormattedPackageName(id); 156 if (packageName.length() != 0) 157 return packageName + ".properties"; return "properties"; } 160 161 } 162 | Popular Tags |