KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.wizards.templates;
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.IPluginReference;
22 import org.eclipse.pde.internal.ui.IHelpContextIds;
23 import org.eclipse.pde.internal.ui.PDEUIMessages;
24 import org.eclipse.pde.ui.IFieldData;
25 import org.eclipse.pde.ui.templates.TemplateOption;
26
27
28 public class ViewRCPTemplate extends PDETemplateSection {
29     
30     public static final String JavaDoc KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$
31
public static final String JavaDoc KEY_APPLICATION_ID = "applicationID"; //$NON-NLS-1$
32
public static final String JavaDoc KEY_WINDOW_TITLE = "windowTitle"; //$NON-NLS-1$
33

34     public ViewRCPTemplate() {
35         setPageCount(1);
36         createOptions();
37     }
38     
39     public void addPages(Wizard wizard) {
40         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL);
41         page.setTitle(PDEUIMessages.ViewRCPTemplate_title);
42         page.setDescription(PDEUIMessages.ViewRCPTemplate_desc);
43         wizard.addPage(page);
44         markPagesAdded();
45     }
46
47     
48     private void createOptions() {
49         addOption(KEY_WINDOW_TITLE, PDEUIMessages.ViewRCPTemplate_windowTitle, "RCP Application", 0); //$NON-NLS-1$
50

51         addOption(KEY_APPLICATION_ID, PDEUIMessages.ViewRCPTemplate_appId, "application", 0); //$NON-NLS-1$
52

53         addOption(KEY_PACKAGE_NAME, PDEUIMessages.ViewRCPTemplate_packageName, (String JavaDoc) null, 0);
54         
55         addOption(KEY_APPLICATION_CLASS, PDEUIMessages.ViewRCPTemplate_appClass, "Application", 0); //$NON-NLS-1$
56
}
57     
58     protected void initializeFields(IFieldData data) {
59         // In a new project wizard, we don't know this yet - the
60
// model has not been created
61
String JavaDoc id = data.getId();
62         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
63     }
64     
65     public void initializeFields(IPluginModelBase model) {
66         // In the new extension wizard, the model exists so
67
// we can initialize directly from it
68
String JavaDoc pluginId = model.getPluginBase().getId();
69         initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId));
70     }
71     
72     /*
73      * (non-Javadoc)
74      *
75      * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
76      */

77     public String JavaDoc getSectionId() {
78         return "viewRCP"; //$NON-NLS-1$
79
}
80
81     /* (non-Javadoc)
82      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#validateOptions(org.eclipse.pde.ui.templates.TemplateOption)
83      */

84     public void validateOptions(TemplateOption source) {
85         if (source.isRequired() && source.isEmpty()) {
86             flagMissingRequiredOption(source);
87         } else {
88             validateContainerPage(source);
89         }
90     }
91     
92     private void validateContainerPage(TemplateOption source) {
93         TemplateOption[] allPageOptions = getOptions(0);
94         for (int i = 0; i < allPageOptions.length; i++) {
95             TemplateOption nextOption = allPageOptions[i];
96             if (nextOption.isRequired() && nextOption.isEmpty()) {
97                 flagMissingRequiredOption(nextOption);
98                 return;
99             }
100         }
101         resetPageState();
102     }
103
104     /* (non-Javadoc)
105      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
106      */

107     protected void updateModel(IProgressMonitor monitor) throws CoreException {
108         createApplicationExtension();
109         createPerspectiveExtension();
110         createViewExtension();
111     }
112     
113     private void createApplicationExtension() throws CoreException {
114         IPluginBase plugin = model.getPluginBase();
115         
116         IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
117
extension.setId(getStringOption(KEY_APPLICATION_ID));
118         
119         IPluginElement element = model.getPluginFactory().createElement(extension);
120         element.setName("application"); //$NON-NLS-1$
121
extension.add(element);
122         
123         IPluginElement run = model.getPluginFactory().createElement(element);
124         run.setName("run"); //$NON-NLS-1$
125
run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
126
element.add(run);
127         
128         if (!extension.isInTheModel())
129             plugin.add(extension);
130     }
131
132     private void createPerspectiveExtension() throws CoreException {
133         IPluginBase plugin = model.getPluginBase();
134         
135         IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); //$NON-NLS-1$
136
IPluginElement element = model.getPluginFactory().createElement(extension);
137         element.setName("perspective"); //$NON-NLS-1$
138
element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
139
element.setAttribute("name", "Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
140
element.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$
141
extension.add(element);
142         
143         if (!extension.isInTheModel())
144             plugin.add(extension);
145     }
146     
147     private void createViewExtension() throws CoreException {
148         IPluginBase plugin = model.getPluginBase();
149         String JavaDoc id = plugin.getId();
150         IPluginExtension extension = createExtension("org.eclipse.ui.views", true); //$NON-NLS-1$
151

152         IPluginElement view = model.getPluginFactory().createElement(extension);
153         view.setName("view"); //$NON-NLS-1$
154
view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".View" ); //$NON-NLS-1$ //$NON-NLS-2$
155
view.setAttribute("name", "View"); //$NON-NLS-1$ //$NON-NLS-2$
156
view.setAttribute("id", id + ".view"); //$NON-NLS-1$ //$NON-NLS-2$
157
extension.add(view);
158         
159         if (!extension.isInTheModel())
160             plugin.add(extension);
161     }
162     
163     /* (non-Javadoc)
164      * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
165      */

166     public String JavaDoc getUsedExtensionPoint() {
167         return null;
168     }
169     
170     /* (non-Javadoc)
171      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
172      */

173     public boolean isDependentOnParentWizard() {
174         return true;
175     }
176     
177     /* (non-Javadoc)
178      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
179      */

180     public int getNumberOfWorkUnits() {
181         return super.getNumberOfWorkUnits() + 1;
182     }
183     
184     /* (non-Javadoc)
185      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
186      */

187     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
188         IPluginReference[] dep = new IPluginReference[2];
189         dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
190
dep[1] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
191
return dep;
192     }
193     
194 }
195
Popular Tags