KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.rcp;
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.templates.IHelpContextIds;
23 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
24 import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
25 import org.eclipse.pde.internal.ui.templates.PluginReference;
26 import org.eclipse.pde.ui.IFieldData;
27
28
29 public class ViewRCPTemplate extends PDETemplateSection {
30     
31     public static final String JavaDoc KEY_APPLICATION_CLASS = "applicationClass"; //$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(PDETemplateMessages.ViewRCPTemplate_title);
42         page.setDescription(PDETemplateMessages.ViewRCPTemplate_desc);
43         wizard.addPage(page);
44         markPagesAdded();
45     }
46
47     
48     private void createOptions() {
49         addOption(KEY_WINDOW_TITLE, PDETemplateMessages.ViewRCPTemplate_windowTitle, "RCP Application", 0); //$NON-NLS-1$
50

51         addOption(KEY_PACKAGE_NAME, PDETemplateMessages.ViewRCPTemplate_packageName, (String JavaDoc) null, 0);
52         
53         addOption(KEY_APPLICATION_CLASS, PDETemplateMessages.ViewRCPTemplate_appClass, "Application", 0); //$NON-NLS-1$
54

55         createBrandingOptions();
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.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
83      */

84     protected void updateModel(IProgressMonitor monitor) throws CoreException {
85         createApplicationExtension();
86         createPerspectiveExtension();
87         createViewExtension();
88         if (getBooleanOption(KEY_PRODUCT_BRANDING))
89             createProductExtension();
90     }
91     
92     private void createApplicationExtension() throws CoreException {
93         IPluginBase plugin = model.getPluginBase();
94         
95         IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
96
extension.setId(VALUE_APPLICATION_ID);
97         
98         IPluginElement element = model.getPluginFactory().createElement(extension);
99         element.setName("application"); //$NON-NLS-1$
100
extension.add(element);
101         
102         IPluginElement run = model.getPluginFactory().createElement(element);
103         run.setName("run"); //$NON-NLS-1$
104
run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
105
element.add(run);
106         
107         if (!extension.isInTheModel())
108             plugin.add(extension);
109     }
110
111     private void createPerspectiveExtension() throws CoreException {
112         IPluginBase plugin = model.getPluginBase();
113         
114         IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); //$NON-NLS-1$
115
IPluginElement element = model.getPluginFactory().createElement(extension);
116         element.setName("perspective"); //$NON-NLS-1$
117
element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
118
element.setAttribute("name", "Perspective"); //$NON-NLS-1$ //$NON-NLS-2$
119
element.setAttribute("id", plugin.getId() + ".perspective"); //$NON-NLS-1$ //$NON-NLS-2$
120
extension.add(element);
121         
122         if (!extension.isInTheModel())
123             plugin.add(extension);
124     }
125     
126     private void createViewExtension() throws CoreException {
127         IPluginBase plugin = model.getPluginBase();
128         String JavaDoc id = plugin.getId();
129         IPluginExtension extension = createExtension("org.eclipse.ui.views", true); //$NON-NLS-1$
130

131         IPluginElement view = model.getPluginFactory().createElement(extension);
132         view.setName("view"); //$NON-NLS-1$
133
view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".View" ); //$NON-NLS-1$ //$NON-NLS-2$
134
view.setAttribute("name", "View"); //$NON-NLS-1$ //$NON-NLS-2$
135
view.setAttribute("id", id + ".view"); //$NON-NLS-1$ //$NON-NLS-2$
136
extension.add(view);
137         
138         if (!extension.isInTheModel())
139             plugin.add(extension);
140     }
141     
142     private void createProductExtension() throws CoreException {
143         IPluginBase plugin = model.getPluginBase();
144         IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); //$NON-NLS-1$
145
extension.setId(VALUE_PRODUCT_ID);
146
147         IPluginElement element = model.getFactory().createElement(extension);
148         element.setName("product"); //$NON-NLS-1$
149
element.setAttribute("name", getStringOption(KEY_WINDOW_TITLE)); //$NON-NLS-1$
150
element.setAttribute("application", plugin.getId() + "." + VALUE_APPLICATION_ID); //$NON-NLS-1$ //$NON-NLS-2$
151

152         IPluginElement property = model.getFactory().createElement(element);
153
154         property = model.getFactory().createElement(element);
155         property.setName("property"); //$NON-NLS-1$
156
property.setAttribute("name", "windowImages"); //$NON-NLS-1$ //$NON-NLS-2$
157
property.setAttribute("value", "icons/alt_window_16.gif,icons/alt_window_32.gif"); //$NON-NLS-1$ //$NON-NLS-2$
158
element.add(property);
159
160         extension.add(element);
161
162         if (!extension.isInTheModel())
163             plugin.add(extension);
164     }
165    
166     /*
167      * (non-Javadoc)
168      *
169      * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
170      */

171     public String JavaDoc getUsedExtensionPoint() {
172         return null;
173     }
174     
175     /* (non-Javadoc)
176      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
177      */

178     public boolean isDependentOnParentWizard() {
179         return true;
180     }
181     
182     /* (non-Javadoc)
183      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
184      */

185     public int getNumberOfWorkUnits() {
186         return super.getNumberOfWorkUnits() + 1;
187     }
188     
189     /* (non-Javadoc)
190      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
191      */

192     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
193         IPluginReference[] dep = new IPluginReference[2];
194         dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
195
dep[1] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
196
return dep;
197     }
198     
199     /* (non-Javadoc)
200      * @see org.eclipse.pde.internal.ui.templates.PDETemplateSection#getNewFiles()
201      */

202     public String JavaDoc[] getNewFiles() {
203         if (copyBrandingDirectory())
204             return new String JavaDoc[] { "icons/", "splash.bmp" }; //$NON-NLS-1$ //$NON-NLS-2$
205
return super.getNewFiles();
206     }
207 }
208
Popular Tags