KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > templates > PerspectiveExtensionsTemplate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc KEY_TARGET_PERSPECTIVE = "targetPerspective"; //$NON-NLS-1$
22
public static final String JavaDoc KEY_PERSPECTIVE_SHORTCUT = "perspectiveShortcut"; //$NON-NLS-1$
23
public static final String JavaDoc KEY_VIEW_SHORTCUT = "viewShortcut"; //$NON-NLS-1$
24
public static final String JavaDoc KEY_WIZARD_SHORTCUT = "wizardShortcut"; //$NON-NLS-1$
25
public static final String JavaDoc KEY_VIEW = "view"; //$NON-NLS-1$
26
public static final String JavaDoc KEY_VIEW_RELATIVE = "viewRelative"; //$NON-NLS-1$
27
public static final String JavaDoc KEY_VIEW_RELATIONSHIP = "viewRelationship"; //$NON-NLS-1$
28
public static final String JavaDoc KEY_ACTION_SET = "actionSet"; //$NON-NLS-1$
29

30     private static final String JavaDoc NL_TITLE0 = "PerspectiveExtensionsTemplate.title0"; //$NON-NLS-1$
31
private static final String JavaDoc NL_DESC0 = "PerspectiveExtensionsTemplate.desc0"; //$NON-NLS-1$
32
private static final String JavaDoc NL_TITLE1 = "PerspectiveExtensionsTemplate.title1"; //$NON-NLS-1$
33
private static final String JavaDoc NL_DESC1 = "PerspectiveExtensionsTemplate.desc1"; //$NON-NLS-1$
34

35     private static final String JavaDoc NL_PERSPECTIVE_ID =
36         "PerspectiveExtensionsTemplate.perspectiveId"; //$NON-NLS-1$
37
private static final String JavaDoc NL_ACTION_SET =
38         "PerspectiveExtensionsTemplate.actionSet"; //$NON-NLS-1$
39
private static final String JavaDoc NL_SHORTCUT_ID =
40         "PerspectiveExtensionsTemplate.shortcutId"; //$NON-NLS-1$
41
private static final String JavaDoc NL_VIEW_SHORTCUT_ID =
42         "PerspectiveExtensionsTemplate.viewShortcutId"; //$NON-NLS-1$
43
private static final String JavaDoc NL_WIZARD_SHORTCUT_ID =
44         "PerspectiveExtensionsTemplate.wizardShortcutId"; //$NON-NLS-1$
45

46     private static final String JavaDoc NL_VIEW_ID = "PerspectiveExtensionsTemplate.viewId"; //$NON-NLS-1$
47
private static final String JavaDoc NL_RELATIVE_VIEW =
48         "PerspectiveExtensionsTemplate.relativeView"; //$NON-NLS-1$
49
private static final String JavaDoc NL_RELATIVE_LOCATION =
50         "PerspectiveExtensionsTemplate.relativePosition"; //$NON-NLS-1$
51
private static final String JavaDoc NL_STACK = "PerspectiveExtensionsTemplate.stack"; //$NON-NLS-1$
52
private static final String JavaDoc NL_FAST = "PerspectiveExtensionsTemplate.fast"; //$NON-NLS-1$
53
private static final String JavaDoc NL_LEFT = "PerspectiveExtensionsTemplate.left"; //$NON-NLS-1$
54
private static final String JavaDoc NL_RIGHT = "PerspectiveExtensionsTemplate.right"; //$NON-NLS-1$
55
private static final String JavaDoc NL_TOP = "PerspectiveExtensionsTemplate.top"; //$NON-NLS-1$
56
private static final String JavaDoc NL_BOTTOM = "PerspectiveExtensionsTemplate.buttom"; //$NON-NLS-1$
57

58     /**
59      * Constructor for PerspectiveExtensionsTemplate.
60      */

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         // add options to first page
81
addOption(
82             KEY_TARGET_PERSPECTIVE,
83             PDEPlugin.getResourceString(NL_PERSPECTIVE_ID),
84             "org.eclipse.ui.resourcePerspective", //$NON-NLS-1$
85
0);
86         addOption(
87             KEY_ACTION_SET,
88             PDEPlugin.getResourceString(NL_ACTION_SET),
89             "org.eclipse.jdt.ui.JavaActionSet", //$NON-NLS-1$
90
0);
91         addOption(
92             KEY_PERSPECTIVE_SHORTCUT,
93             PDEPlugin.getResourceString(NL_SHORTCUT_ID),
94             "org.eclipse.debug.ui.DebugPerspective", //$NON-NLS-1$
95
0);
96         addOption(
97             KEY_VIEW_SHORTCUT,
98             PDEPlugin.getResourceString(NL_VIEW_SHORTCUT_ID),
99             "org.eclipse.jdt.ui.TypeHierarchy", //$NON-NLS-1$
100
0);
101         addOption(
102             KEY_WIZARD_SHORTCUT,
103             PDEPlugin.getResourceString(NL_WIZARD_SHORTCUT_ID),
104             "org.eclipse.jdt.ui.wizards.NewProjectCreationWizard", //$NON-NLS-1$
105
0);
106
107         // add options to second page
108
addOption(
109             KEY_VIEW,
110             PDEPlugin.getResourceString(NL_VIEW_ID),
111             "org.eclipse.jdt.ui.PackageExplorer", //$NON-NLS-1$
112
1);
113         addOption(
114             KEY_VIEW_RELATIVE,
115             PDEPlugin.getResourceString(NL_RELATIVE_VIEW),
116             "org.eclipse.ui.views.ResourceNavigator", //$NON-NLS-1$
117
1);
118         addOption(
119             KEY_VIEW_RELATIONSHIP,
120             PDEPlugin.getResourceString(NL_RELATIVE_LOCATION),
121             new String JavaDoc[][] {
122                 {"stack", PDEPlugin.getResourceString(NL_STACK)}, //$NON-NLS-1$
123
{"fast", PDEPlugin.getResourceString(NL_FAST)}, //$NON-NLS-1$
124
{"left", PDEPlugin.getResourceString(NL_LEFT)}, //$NON-NLS-1$
125
{"right", PDEPlugin.getResourceString(NL_RIGHT)}, //$NON-NLS-1$
126
{"top", PDEPlugin.getResourceString(NL_TOP)}, //$NON-NLS-1$
127
{"bottom", PDEPlugin.getResourceString(NL_BOTTOM)}}, //$NON-NLS-1$
128
"stack", //$NON-NLS-1$
129
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     /**
140      * @see PDETemplateSection#getSectionId()
141      */

142     public String JavaDoc getSectionId() {
143         return "perspectiveExtensions"; //$NON-NLS-1$
144
}
145
146     /**
147      * @see GenericTemplateSection#validateOptions(TemplateOption)
148      */

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     /**
170      * @see AbstractTemplateSection#updateModel(IProgressMonitor)
171      */

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"); //$NON-NLS-1$
179
perspectiveElement.setAttribute(
180             "targetID", //$NON-NLS-1$
181
getStringOption(KEY_TARGET_PERSPECTIVE));
182
183         IPluginElement wizardShortcutElement =
184             factory.createElement(perspectiveElement);
185         wizardShortcutElement.setName("newWizardShortcut"); //$NON-NLS-1$
186
wizardShortcutElement.setAttribute("id", getStringOption(KEY_WIZARD_SHORTCUT)); //$NON-NLS-1$
187
perspectiveElement.add(wizardShortcutElement);
188
189         IPluginElement viewShortcutElement = factory.createElement(perspectiveElement);
190         viewShortcutElement.setName("viewShortcut"); //$NON-NLS-1$
191
viewShortcutElement.setAttribute("id", getStringOption(KEY_VIEW_SHORTCUT)); //$NON-NLS-1$
192
perspectiveElement.add(viewShortcutElement);
193
194         IPluginElement perspectiveShortcutElement =
195             factory.createElement(perspectiveElement);
196         perspectiveShortcutElement.setName("perspectiveShortcut"); //$NON-NLS-1$
197
perspectiveShortcutElement.setAttribute(
198             "id", //$NON-NLS-1$
199
getStringOption(KEY_PERSPECTIVE_SHORTCUT));
200         perspectiveElement.add(perspectiveShortcutElement);
201
202         IPluginElement actionSetElement = factory.createElement(perspectiveElement);
203         actionSetElement.setName("actionSet"); //$NON-NLS-1$
204
actionSetElement.setAttribute("id", getStringOption(KEY_ACTION_SET)); //$NON-NLS-1$
205
perspectiveElement.add(actionSetElement);
206
207         IPluginElement viewElement = factory.createElement(perspectiveElement);
208         viewElement.setName("view"); //$NON-NLS-1$
209
viewElement.setAttribute("id", getStringOption(KEY_VIEW)); //$NON-NLS-1$
210
viewElement.setAttribute("relative", getStringOption(KEY_VIEW_RELATIVE)); //$NON-NLS-1$
211
String JavaDoc relationship = getValue(KEY_VIEW_RELATIONSHIP).toString();
212         viewElement.setAttribute("relationship", relationship); //$NON-NLS-1$
213
if (!relationship.equals("stack") && !relationship.equals("fast")) { //$NON-NLS-1$ //$NON-NLS-2$
214
viewElement.setAttribute("ratio", "0.5"); //$NON-NLS-1$ //$NON-NLS-2$
215
}
216         perspectiveElement.add(viewElement);
217
218         extension.add(perspectiveElement);
219         if (!extension.isInTheModel())
220             plugin.add(extension);
221     }
222
223     /**
224      * @see ITemplateSection#getUsedExtensionPoint()
225      */

226     public String JavaDoc getUsedExtensionPoint() {
227         return "org.eclipse.ui.perspectiveExtensions"; //$NON-NLS-1$
228
}
229
230 }
231
Popular Tags