1 11 12 package org.eclipse.pde.internal.ui.templates.ide; 13 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.jface.wizard.Wizard; 19 import org.eclipse.jface.wizard.WizardPage; 20 import org.eclipse.pde.core.plugin.IPluginAttribute; 21 import org.eclipse.pde.core.plugin.IPluginBase; 22 import org.eclipse.pde.core.plugin.IPluginElement; 23 import org.eclipse.pde.core.plugin.IPluginExtension; 24 import org.eclipse.pde.core.plugin.IPluginModelBase; 25 import org.eclipse.pde.core.plugin.IPluginModelFactory; 26 import org.eclipse.pde.core.plugin.IPluginObject; 27 import org.eclipse.pde.core.plugin.IPluginReference; 28 import org.eclipse.pde.internal.ui.templates.IHelpContextIds; 29 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 30 import org.eclipse.pde.internal.ui.templates.PDETemplateSection; 31 import org.eclipse.pde.internal.ui.templates.PluginReference; 32 import org.eclipse.pde.ui.IFieldData; 33 import org.eclipse.pde.ui.templates.BooleanOption; 34 35 public class ViewTemplate extends PDETemplateSection { 36 private BooleanOption addToPerspective; 37 40 public ViewTemplate() { 41 setPageCount(2); 42 createOptions(); 43 } 44 45 public String getSectionId() { 46 return "view"; } 48 51 public int getNumberOfWorkUnits() { 52 return super.getNumberOfWorkUnits()+1; 53 } 54 55 private void createOptions() { 56 addOption(KEY_PACKAGE_NAME, PDETemplateMessages.ViewTemplate_packageName, (String )null, 0); 58 addOption("className", PDETemplateMessages.ViewTemplate_className, "SampleView", 0); addOption("viewName", PDETemplateMessages.ViewTemplate_name, PDETemplateMessages.ViewTemplate_defaultName, 0); addOption("viewCategoryId", PDETemplateMessages.ViewTemplate_categoryId, (String )null, 0); addOption("viewCategoryName", PDETemplateMessages.ViewTemplate_categoryName, PDETemplateMessages.ViewTemplate_defaultCategoryName, 0); addOption("viewType", PDETemplateMessages.ViewTemplate_select, new String [][] { 64 {"tableViewer", PDETemplateMessages.ViewTemplate_table}, {"treeViewer", PDETemplateMessages.ViewTemplate_tree}}, "tableViewer", 0); addToPerspective = (BooleanOption)addOption("addToPerspective",PDETemplateMessages.ViewTemplate_addToPerspective,true,0); addOption("doubleClick", PDETemplateMessages.ViewTemplate_doubleClick, true, 1); addOption("popup", PDETemplateMessages.ViewTemplate_popup, true, 1); addOption("localToolbar", PDETemplateMessages.ViewTemplate_toolbar, true, 1); addOption("localPulldown", PDETemplateMessages.ViewTemplate_pulldown, true, 1); addOption("sorter", PDETemplateMessages.ViewTemplate_sorting, true, 1); } 76 77 protected void initializeFields(IFieldData data) { 78 String id = data.getId(); 81 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 82 initializeOption("viewCategoryId", id); } 84 public void initializeFields(IPluginModelBase model) { 85 String pluginId = model.getPluginBase().getId(); 88 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 89 initializeOption("viewCategoryId", pluginId); } 91 92 public boolean isDependentOnParentWizard() { 93 return true; 94 } 95 96 public void addPages(Wizard wizard) { 97 WizardPage page0 = createPage(0, IHelpContextIds.TEMPLATE_VIEW); 98 page0.setTitle(PDETemplateMessages.ViewTemplate_title0); 99 page0.setDescription(PDETemplateMessages.ViewTemplate_desc0); 100 wizard.addPage(page0); 101 102 WizardPage page1 = createPage(1, IHelpContextIds.TEMPLATE_VIEW); 103 page1.setTitle(PDETemplateMessages.ViewTemplate_title1); 104 page1.setDescription(PDETemplateMessages.ViewTemplate_desc1); 105 wizard.addPage(page1); 106 markPagesAdded(); 107 } 108 109 public String getUsedExtensionPoint() { 110 return "org.eclipse.ui.views"; } 112 113 protected void updateModel(IProgressMonitor monitor) throws CoreException { 114 IPluginBase plugin = model.getPluginBase(); 115 IPluginExtension extension = createExtension("org.eclipse.ui.views", true); IPluginModelFactory factory = model.getPluginFactory(); 117 118 String cid = getStringOption("viewCategoryId"); 120 createCategory(extension, cid); 121 String fullClassName = getStringOption(KEY_PACKAGE_NAME)+"."+getStringOption("className"); 123 IPluginElement viewElement = factory.createElement(extension); 124 viewElement.setName("view"); viewElement.setAttribute("id", fullClassName); viewElement.setAttribute("name", getStringOption("viewName")); viewElement.setAttribute("icon", "icons/sample.gif"); 129 viewElement.setAttribute("class", fullClassName); viewElement.setAttribute("category", cid); extension.add(viewElement); 132 if (!extension.isInTheModel()) 133 plugin.add(extension); 134 135 if (addToPerspective.isSelected()) { 136 IPluginExtension perspectiveExtension = 137 createExtension("org.eclipse.ui.perspectiveExtensions", true); 139 IPluginElement perspectiveElement = factory.createElement(perspectiveExtension); 140 perspectiveElement.setName("perspectiveExtension"); perspectiveElement.setAttribute( 142 "targetID", "org.eclipse.ui.resourcePerspective"); 145 IPluginElement view = factory.createElement(perspectiveElement); 146 view.setName("view"); view.setAttribute("id", fullClassName); view.setAttribute("relative", "org.eclipse.ui.views.TaskList"); view.setAttribute("relationship","right"); view.setAttribute("ratio", "0.5"); perspectiveElement.add(view); 152 153 perspectiveExtension.add(perspectiveElement); 154 if (!perspectiveExtension.isInTheModel()) 155 plugin.add(perspectiveExtension); 156 } 157 } 158 159 private void createCategory(IPluginExtension extension, String id) throws CoreException { 160 IPluginObject [] elements = extension.getChildren(); 161 for (int i=0; i<elements.length; i++) { 162 IPluginElement element = (IPluginElement)elements[i]; 163 if (element.getName().equalsIgnoreCase("category")) { IPluginAttribute att = element.getAttribute("id"); if (att!=null) { 166 String cid = att.getValue(); 167 if (cid!=null && cid.equals(id)) 168 return; 169 } 170 } 171 } 172 IPluginElement categoryElement = model.getFactory().createElement(extension); 173 categoryElement.setName("category"); categoryElement.setAttribute("name", getStringOption("viewCategoryName")); categoryElement.setAttribute("id", id); extension.add(categoryElement); 177 } 178 179 182 public String [] getNewFiles() { 183 return new String [] {"icons/"}; } 185 186 189 public IPluginReference[] getDependencies(String schemaVersion) { 190 ArrayList result = new ArrayList (); 191 if (schemaVersion != null) 192 result.add(new PluginReference("org.eclipse.core.runtime", null, 0)); result.add(new PluginReference("org.eclipse.ui", null, 0)); return (IPluginReference[]) result.toArray(new IPluginReference[result.size()]); 195 } 196 197 200 protected String getFormattedPackageName(String id) { 201 String packageName = super.getFormattedPackageName(id); 202 if (packageName.length() != 0) 203 return packageName + ".views"; return "views"; } 206 } 207 | Popular Tags |