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 PerspectiveTemplate extends PDETemplateSection { 30 public static final String PERSPECTIVE_CLASS_NAME = "perspectiveClassName"; public static final String PERSPECTIVE_NAME = "perspectiveCategoryName"; 33 public static final String BLN_PERSPECTIVE_SHORTS = "perspectiveShortcuts"; public static final String BLN_NEW_WIZARD_SHORTS = "newWizardShortcuts"; public static final String BLN_SHOW_VIEW_SHORTS = "showViewShortcuts"; public static final String BLN_ACTION_SETS = "actionSets"; 38 private WizardPage page; 39 40 43 public PerspectiveTemplate() { 44 setPageCount(1); 45 createOptions(); 46 } 47 48 51 public IPluginReference[] getDependencies(String schemaVersion) { 52 if (schemaVersion != null) { 54 IPluginReference[] dep = new IPluginReference[2]; 55 dep[0] = new PluginReference("org.eclipse.ui.console", null, 0); dep[1] = new PluginReference("org.eclipse.jdt.ui", null, 0); return dep; 58 } 59 return super.getDependencies(schemaVersion); 60 } 61 62 66 public String getSectionId() { 67 return "perspective"; } 69 70 73 public int getNumberOfWorkUnits() { 74 return super.getNumberOfWorkUnits() + 1; 75 } 76 77 82 private void createOptions() { 83 addOption( 84 KEY_PACKAGE_NAME, 85 PDETemplateMessages.PerspectiveTemplate_packageName, 86 (String ) null, 87 0); 88 addOption( 89 PERSPECTIVE_CLASS_NAME, 90 PDETemplateMessages.PerspectiveTemplate_perspectiveClass, 91 PDETemplateMessages.PerspectiveTemplate_perspectiveClassName, 92 0); 93 addOption( 94 PERSPECTIVE_NAME, 95 PDETemplateMessages.PerspectiveTemplate_perspective, 96 PDETemplateMessages.PerspectiveTemplate_perspectiveName, 97 0); 98 99 addBlankField(0); 100 101 102 addOption(BLN_PERSPECTIVE_SHORTS, 103 PDETemplateMessages.PerspectiveTemplate_perspectiveShortcuts, 104 true, 105 0); 106 addOption(BLN_SHOW_VIEW_SHORTS, 107 PDETemplateMessages.PerspectiveTemplate_showViewShortcuts, 108 true, 109 0); 110 addOption(BLN_NEW_WIZARD_SHORTS, 111 PDETemplateMessages.PerspectiveTemplate_newWizardShortcuts, 112 true, 113 0); 114 addOption(BLN_ACTION_SETS, 115 PDETemplateMessages.PerspectiveTemplate_actionSets, 116 true, 117 0); 118 } 119 120 123 public void addPages(Wizard wizard) { 124 int pageIndex = 0; 125 126 page = createPage(pageIndex, IHelpContextIds.TEMPLATE_EDITOR); 127 page.setTitle(PDETemplateMessages.PerspectiveTemplate_title); 128 page.setDescription(PDETemplateMessages.PerspectiveTemplate_desc); 129 130 wizard.addPage(page); 131 markPagesAdded(); 132 } 133 134 137 public boolean isDependentOnParentWizard() { 138 return true; 139 } 140 141 144 protected void initializeFields(IFieldData data) { 145 String id = data.getId(); 148 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 149 } 150 151 154 public void initializeFields(IPluginModelBase model) { 155 String pluginId = model.getPluginBase().getId(); 158 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 159 } 160 161 164 protected void updateModel(IProgressMonitor monitor) throws CoreException { 165 IPluginBase plugin = model.getPluginBase(); 170 IPluginExtension extension = createExtension(getUsedExtensionPoint(),true); 171 IPluginModelFactory factory = model.getPluginFactory(); 172 173 IPluginElement perspectiveElement = factory.createElement(extension); 174 perspectiveElement.setName("perspective"); perspectiveElement.setAttribute( 176 "id", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(PERSPECTIVE_CLASS_NAME)); perspectiveElement.setAttribute( 178 "name", getStringOption(PERSPECTIVE_NAME)); perspectiveElement.setAttribute( 180 "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(PERSPECTIVE_CLASS_NAME)); perspectiveElement.setAttribute( 182 "icon", "icons/releng_gears.gif"); 184 185 extension.add(perspectiveElement); 186 if (!extension.isInTheModel()) 187 plugin.add(extension); 188 } 189 190 193 public String [] getNewFiles() { 194 return new String [] { "icons/" }; } 196 197 200 protected String getFormattedPackageName(String id) { 201 String packageName = super.getFormattedPackageName(id); 204 if (packageName.length() != 0) 205 return packageName + ".perspectives"; return "perspectives"; } 208 209 212 public String getUsedExtensionPoint() { 213 return "org.eclipse.ui.perspectives"; } 215 } 216 | Popular Tags |