KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > templates > ide > PerspectiveTemplate


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

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 JavaDoc PERSPECTIVE_CLASS_NAME = "perspectiveClassName"; //$NON-NLS-1$
31
public static final String JavaDoc PERSPECTIVE_NAME = "perspectiveCategoryName"; //$NON-NLS-1$
32

33     public static final String JavaDoc BLN_PERSPECTIVE_SHORTS = "perspectiveShortcuts"; //$NON-NLS-1$
34
public static final String JavaDoc BLN_NEW_WIZARD_SHORTS = "newWizardShortcuts"; //$NON-NLS-1$
35
public static final String JavaDoc BLN_SHOW_VIEW_SHORTS = "showViewShortcuts"; //$NON-NLS-1$
36
public static final String JavaDoc BLN_ACTION_SETS = "actionSets"; //$NON-NLS-1$
37

38     private WizardPage page;
39     
40     /**
41      * Constructor for PerspectiveTemplate.
42      */

43     public PerspectiveTemplate() {
44         setPageCount(1);
45         createOptions();
46     }
47     
48     /* (non-Javadoc)
49      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
50      */

51     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
52         // Additional dependencies required
53
if (schemaVersion != null) {
54             IPluginReference[] dep = new IPluginReference[2];
55             dep[0] = new PluginReference("org.eclipse.ui.console", null, 0); //$NON-NLS-1$
56
dep[1] = new PluginReference("org.eclipse.jdt.ui", null, 0); //$NON-NLS-1$
57
return dep;
58         }
59         return super.getDependencies(schemaVersion);
60     }
61
62     /* (non-Javadoc)
63      * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
64      * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getDirectoryCandidates()
65      */

66     public String JavaDoc getSectionId() {
67         return "perspective"; //$NON-NLS-1$
68
}
69     
70     /* (non-Javadoc)
71      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
72      */

73     public int getNumberOfWorkUnits() {
74         return super.getNumberOfWorkUnits() + 1;
75     }
76     
77     /**
78      * Creates the options to be displayed on the template wizard.
79      * Various string options, blank fields and a multiple choice
80      * option are used.
81      */

82     private void createOptions() {
83         addOption(
84                 KEY_PACKAGE_NAME,
85                 PDETemplateMessages.PerspectiveTemplate_packageName,
86                 (String JavaDoc) 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     /* (non-Javadoc)
121      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#addPages(org.eclipse.jface.wizard.Wizard)
122      */

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     /* (non-Javadoc)
135      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
136      */

137     public boolean isDependentOnParentWizard() {
138         return true;
139     }
140
141     /* (non-Javadoc)
142      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#initializeFields(org.eclipse.pde.ui.IFieldData)
143      */

144     protected void initializeFields(IFieldData data) {
145          // In a new project wizard, we don't know this yet - the
146
// model has not been created
147
String JavaDoc id = data.getId();
148         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
149     }
150     
151     /* (non-Javadoc)
152      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#initializeFields(org.eclipse.pde.core.plugin.IPluginModelBase)
153      */

154     public void initializeFields(IPluginModelBase model) {
155          // In the new extension wizard, the model exists so
156
// we can initialize directly from it
157
String JavaDoc pluginId = model.getPluginBase().getId();
158         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId));
159     }
160
161     /* (non-Javadoc)
162      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
163      */

164     protected void updateModel(IProgressMonitor monitor) throws CoreException {
165          // This method creates the extension point structure through the use
166
// of IPluginElement objects. The element attributes are set based on
167
// user input from the wizard page as well as values required for the
168
// operation of the extension point.
169
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"); //$NON-NLS-1$
175
perspectiveElement.setAttribute(
176                 "id", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(PERSPECTIVE_CLASS_NAME)); //$NON-NLS-1$ //$NON-NLS-2$
177
perspectiveElement.setAttribute(
178                 "name", getStringOption(PERSPECTIVE_NAME)); //$NON-NLS-1$
179
perspectiveElement.setAttribute(
180                 "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(PERSPECTIVE_CLASS_NAME)); //$NON-NLS-1$ //$NON-NLS-2$
181
perspectiveElement.setAttribute(
182                 "icon", "icons/releng_gears.gif"); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
183

184
185         extension.add(perspectiveElement);
186         if (!extension.isInTheModel())
187             plugin.add(extension);
188     }
189
190     /* (non-Javadoc)
191      * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getNewFiles()
192      */

193     public String JavaDoc[] getNewFiles() {
194         return new String JavaDoc[] { "icons/" }; //$NON-NLS-1$
195
}
196
197     /* (non-Javadoc)
198      * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#getFormattedPackageName(java.lang.String)
199      */

200     protected String JavaDoc getFormattedPackageName(String JavaDoc id) {
201          // Package name addition to create a location for containing
202
// any classes required by the decorator.
203
String JavaDoc packageName = super.getFormattedPackageName(id);
204         if (packageName.length() != 0)
205             return packageName + ".perspectives"; //$NON-NLS-1$
206
return "perspectives"; //$NON-NLS-1$
207
}
208
209     /* (non-Javadoc)
210      * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
211      */

212     public String JavaDoc getUsedExtensionPoint() {
213         return "org.eclipse.ui.perspectives"; //$NON-NLS-1$
214
}
215 }
216
Popular Tags