1 11 package org.eclipse.pde.internal.ui.wizards.templates; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.jface.wizard.*; 15 import org.eclipse.pde.core.plugin.*; 16 import org.eclipse.pde.internal.ui.*; 17 import org.eclipse.pde.ui.templates.TemplateOption; 18 19 public class PerspectiveExtensionsTemplate extends PDETemplateSection { 20 21 public static final String KEY_TARGET_PERSPECTIVE = "targetPerspective"; public static final String KEY_PERSPECTIVE_SHORTCUT = "perspectiveShortcut"; public static final String KEY_VIEW_SHORTCUT = "viewShortcut"; public static final String KEY_WIZARD_SHORTCUT = "wizardShortcut"; public static final String KEY_VIEW = "view"; public static final String KEY_VIEW_RELATIVE = "viewRelative"; public static final String KEY_VIEW_RELATIONSHIP = "viewRelationship"; public static final String KEY_ACTION_SET = "actionSet"; 30 private static final String NL_TITLE0 = "PerspectiveExtensionsTemplate.title0"; private static final String NL_DESC0 = "PerspectiveExtensionsTemplate.desc0"; private static final String NL_TITLE1 = "PerspectiveExtensionsTemplate.title1"; private static final String NL_DESC1 = "PerspectiveExtensionsTemplate.desc1"; 35 private static final String NL_PERSPECTIVE_ID = 36 "PerspectiveExtensionsTemplate.perspectiveId"; private static final String NL_ACTION_SET = 38 "PerspectiveExtensionsTemplate.actionSet"; private static final String NL_SHORTCUT_ID = 40 "PerspectiveExtensionsTemplate.shortcutId"; private static final String NL_VIEW_SHORTCUT_ID = 42 "PerspectiveExtensionsTemplate.viewShortcutId"; private static final String NL_WIZARD_SHORTCUT_ID = 44 "PerspectiveExtensionsTemplate.wizardShortcutId"; 46 private static final String NL_VIEW_ID = "PerspectiveExtensionsTemplate.viewId"; private static final String NL_RELATIVE_VIEW = 48 "PerspectiveExtensionsTemplate.relativeView"; private static final String NL_RELATIVE_LOCATION = 50 "PerspectiveExtensionsTemplate.relativePosition"; private static final String NL_STACK = "PerspectiveExtensionsTemplate.stack"; private static final String NL_FAST = "PerspectiveExtensionsTemplate.fast"; private static final String NL_LEFT = "PerspectiveExtensionsTemplate.left"; private static final String NL_RIGHT = "PerspectiveExtensionsTemplate.right"; private static final String NL_TOP = "PerspectiveExtensionsTemplate.top"; private static final String NL_BOTTOM = "PerspectiveExtensionsTemplate.buttom"; 58 61 public PerspectiveExtensionsTemplate() { 62 setPageCount(2); 63 createOptions(); 64 } 65 66 public void addPages(Wizard wizard) { 67 WizardPage page0 = createPage(0,IHelpContextIds.TEMPLATE_PERSPECTIVE_EXTENSIONS); 68 page0.setTitle(PDEPlugin.getResourceString(NL_TITLE0)); 69 page0.setDescription(PDEPlugin.getResourceString(NL_DESC0)); 70 wizard.addPage(page0); 71 72 WizardPage page1 = createPage(1, IHelpContextIds.TEMPLATE_PERSPECTIVE_EXTENSIONS); 73 page1.setTitle(PDEPlugin.getResourceString(NL_TITLE1)); 74 page1.setDescription(PDEPlugin.getResourceString(NL_DESC1)); 75 wizard.addPage(page1); 76 markPagesAdded(); 77 } 78 79 private void createOptions() { 80 addOption( 82 KEY_TARGET_PERSPECTIVE, 83 PDEPlugin.getResourceString(NL_PERSPECTIVE_ID), 84 "org.eclipse.ui.resourcePerspective", 0); 86 addOption( 87 KEY_ACTION_SET, 88 PDEPlugin.getResourceString(NL_ACTION_SET), 89 "org.eclipse.jdt.ui.JavaActionSet", 0); 91 addOption( 92 KEY_PERSPECTIVE_SHORTCUT, 93 PDEPlugin.getResourceString(NL_SHORTCUT_ID), 94 "org.eclipse.debug.ui.DebugPerspective", 0); 96 addOption( 97 KEY_VIEW_SHORTCUT, 98 PDEPlugin.getResourceString(NL_VIEW_SHORTCUT_ID), 99 "org.eclipse.jdt.ui.TypeHierarchy", 0); 101 addOption( 102 KEY_WIZARD_SHORTCUT, 103 PDEPlugin.getResourceString(NL_WIZARD_SHORTCUT_ID), 104 "org.eclipse.jdt.ui.wizards.NewProjectCreationWizard", 0); 106 107 addOption( 109 KEY_VIEW, 110 PDEPlugin.getResourceString(NL_VIEW_ID), 111 "org.eclipse.jdt.ui.PackageExplorer", 1); 113 addOption( 114 KEY_VIEW_RELATIVE, 115 PDEPlugin.getResourceString(NL_RELATIVE_VIEW), 116 "org.eclipse.ui.views.ResourceNavigator", 1); 118 addOption( 119 KEY_VIEW_RELATIONSHIP, 120 PDEPlugin.getResourceString(NL_RELATIVE_LOCATION), 121 new String [][] { 122 {"stack", PDEPlugin.getResourceString(NL_STACK)}, {"fast", PDEPlugin.getResourceString(NL_FAST)}, {"left", PDEPlugin.getResourceString(NL_LEFT)}, {"right", PDEPlugin.getResourceString(NL_RIGHT)}, {"top", PDEPlugin.getResourceString(NL_TOP)}, {"bottom", PDEPlugin.getResourceString(NL_BOTTOM)}}, "stack", 1); 130 } 131 132 private TemplateOption[] getAllPageOptions(TemplateOption source) { 133 int pageIndex = getPageIndex(source); 134 if (pageIndex != -1) 135 return getOptions(pageIndex); 136 return new TemplateOption[0]; 137 } 138 139 142 public String getSectionId() { 143 return "perspectiveExtensions"; } 145 146 149 public void validateOptions(TemplateOption source) { 150 if (source.isRequired() && source.isEmpty()) { 151 flagMissingRequiredOption(source); 152 } else { 153 validateContainerPage(source); 154 } 155 } 156 157 private void validateContainerPage(TemplateOption source) { 158 TemplateOption[] siblings = getAllPageOptions(source); 159 for (int i = 0; i < siblings.length; i++) { 160 TemplateOption nextOption = siblings[i]; 161 if (nextOption.isRequired() && nextOption.isEmpty()) { 162 flagMissingRequiredOption(nextOption); 163 return; 164 } 165 } 166 resetPageState(); 167 } 168 169 172 protected void updateModel(IProgressMonitor monitor) throws CoreException { 173 IPluginBase plugin = model.getPluginBase(); 174 IPluginExtension extension = createExtension(getUsedExtensionPoint(), true); 175 IPluginModelFactory factory = model.getPluginFactory(); 176 177 IPluginElement perspectiveElement = factory.createElement(extension); 178 perspectiveElement.setName("perspectiveExtension"); perspectiveElement.setAttribute( 180 "targetID", getStringOption(KEY_TARGET_PERSPECTIVE)); 182 183 IPluginElement wizardShortcutElement = 184 factory.createElement(perspectiveElement); 185 wizardShortcutElement.setName("newWizardShortcut"); wizardShortcutElement.setAttribute("id", getStringOption(KEY_WIZARD_SHORTCUT)); perspectiveElement.add(wizardShortcutElement); 188 189 IPluginElement viewShortcutElement = factory.createElement(perspectiveElement); 190 viewShortcutElement.setName("viewShortcut"); viewShortcutElement.setAttribute("id", getStringOption(KEY_VIEW_SHORTCUT)); perspectiveElement.add(viewShortcutElement); 193 194 IPluginElement perspectiveShortcutElement = 195 factory.createElement(perspectiveElement); 196 perspectiveShortcutElement.setName("perspectiveShortcut"); perspectiveShortcutElement.setAttribute( 198 "id", getStringOption(KEY_PERSPECTIVE_SHORTCUT)); 200 perspectiveElement.add(perspectiveShortcutElement); 201 202 IPluginElement actionSetElement = factory.createElement(perspectiveElement); 203 actionSetElement.setName("actionSet"); actionSetElement.setAttribute("id", getStringOption(KEY_ACTION_SET)); perspectiveElement.add(actionSetElement); 206 207 IPluginElement viewElement = factory.createElement(perspectiveElement); 208 viewElement.setName("view"); viewElement.setAttribute("id", getStringOption(KEY_VIEW)); viewElement.setAttribute("relative", getStringOption(KEY_VIEW_RELATIVE)); String relationship = getValue(KEY_VIEW_RELATIONSHIP).toString(); 212 viewElement.setAttribute("relationship", relationship); if (!relationship.equals("stack") && !relationship.equals("fast")) { viewElement.setAttribute("ratio", "0.5"); } 216 perspectiveElement.add(viewElement); 217 218 extension.add(perspectiveElement); 219 if (!extension.isInTheModel()) 220 plugin.add(extension); 221 } 222 223 226 public String getUsedExtensionPoint() { 227 return "org.eclipse.ui.perspectiveExtensions"; } 229 230 } 231 | Popular Tags |