1 11 package org.eclipse.pde.internal.ui.wizards.templates; 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.IHelpContextIds; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 import org.eclipse.pde.ui.IFieldData; 28 import org.eclipse.pde.ui.templates.TemplateOption; 29 30 public class PropertyPageTemplate extends PDETemplateSection { 31 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"; 36 39 public PropertyPageTemplate() { 40 setPageCount(1); 41 createOptions(); 42 } 43 44 public void addPages(Wizard wizard) { 45 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_PROPERTY_PAGE); 46 page.setTitle(PDEUIMessages.PropertyPageTemplate_title); 47 page.setDescription(PDEUIMessages.PropertyPageTemplate_desc); 48 wizard.addPage(page); 49 markPagesAdded(); 50 } 51 52 private void createOptions() { 53 addOption( 54 KEY_PACKAGE_NAME, 55 PDEUIMessages.PropertyPageTemplate_packageName, 56 (String ) null, 57 0); 58 addOption( 59 KEY_CLASSNAME, 60 PDEUIMessages.PropertyPageTemplate_pageClass, 61 "SamplePropertyPage", 0); 63 addOption( 64 KEY_PAGE_NAME, 65 PDEUIMessages.PropertyPageTemplate_pageName, 66 PDEUIMessages.PropertyPageTemplate_defaultPageName, 67 0); 68 addOption( 69 KEY_TARGET_CLASS, 70 PDEUIMessages.PropertyPageTemplate_targetClass, 71 "org.eclipse.core.resources.IFile", 0); 73 addOption( 74 KEY_NAME_FILTER, 75 PDEUIMessages.PropertyPageTemplate_nameFilter, 76 "*.*", 0); 78 } 79 82 public String getSectionId() { 83 return "propertyPages"; } 85 86 public boolean isDependentOnParentWizard() { 87 return true; 88 } 89 90 91 protected void initializeFields(IFieldData data) { 92 String id = data.getId(); 95 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 96 } 97 98 public void initializeFields(IPluginModelBase model) { 99 String pluginId = model.getPluginBase().getId(); 102 initializeOption(KEY_PACKAGE_NAME,getFormattedPackageName(pluginId)); 103 } 104 105 108 public void validateOptions(TemplateOption source) { 109 if (source.isRequired() && source.isEmpty()) { 110 flagMissingRequiredOption(source); 111 } else { 112 validateContainerPage(source); 113 } 114 } 115 116 private void validateContainerPage(TemplateOption source) { 117 TemplateOption[] allPageOptions = getOptions(0); 118 for (int i = 0; i < allPageOptions.length; i++) { 119 TemplateOption nextOption = allPageOptions[i]; 120 if (nextOption.isRequired() && nextOption.isEmpty()) { 121 flagMissingRequiredOption(nextOption); 122 return; 123 } 124 } 125 resetPageState(); 126 } 127 128 131 protected void updateModel(IProgressMonitor monitor) throws CoreException { 132 IPluginBase plugin = model.getPluginBase(); 133 IPluginExtension extension = createExtension(getUsedExtensionPoint(), true); 134 IPluginModelFactory factory = model.getPluginFactory(); 135 136 IPluginElement pageElement = factory.createElement(extension); 137 pageElement.setName("page"); pageElement.setAttribute( 139 "id", getStringOption(KEY_PACKAGE_NAME) + ".samplePropertyPage"); pageElement.setAttribute("name", getStringOption(KEY_PAGE_NAME)); pageElement.setAttribute("objectClass", getStringOption(KEY_TARGET_CLASS)); pageElement.setAttribute( 144 "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_CLASSNAME)); pageElement.setAttribute("nameFilter", getStringOption(KEY_NAME_FILTER)); 148 extension.add(pageElement); 149 if (!extension.isInTheModel()) 150 plugin.add(extension); 151 } 152 153 156 public String getUsedExtensionPoint() { 157 return "org.eclipse.ui.propertyPages"; } 159 160 163 public IPluginReference[] getDependencies(String schemaVersion) { 164 ArrayList result = new ArrayList (); 165 result.add(new PluginReference("org.eclipse.core.resources", null, 0)); if (schemaVersion != null) 167 result.add(new PluginReference("org.eclipse.core.runtime", null, 0)); result.add(new PluginReference("org.eclipse.ui", null, 0)); 170 return (IPluginReference[])result.toArray(new IPluginReference[result.size()]); 171 } 172 173 176 protected String getFormattedPackageName(String id) { 177 String packageName = super.getFormattedPackageName(id); 178 if (packageName.length() != 0) 179 return packageName + ".properties"; return "properties"; } 182 183 } 184 | Popular Tags |