KickJava   Java API By Example, From Geeks To Geeks.

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


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 HelloRCPTemplate 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 HelloRCPTemplate() {
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.HelloRCPTemplate_title);
42         page.setDescription(PDETemplateMessages.HelloRCPTemplate_desc);
43         wizard.addPage(page);
44         markPagesAdded();
45     }
46
47     
48     private void createOptions() {
49         addOption(KEY_WINDOW_TITLE, PDETemplateMessages.HelloRCPTemplate_windowTitle, "Hello RCP", 0); //$NON-NLS-1$
50

51         addOption(KEY_PACKAGE_NAME, PDETemplateMessages.MailTemplate_packageName, (String JavaDoc) null, 0);
52         
53         addOption(KEY_APPLICATION_CLASS, PDETemplateMessages.HelloRCPTemplate_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 packageName = getFormattedPackageName(data.getId());
62         initializeOption(KEY_PACKAGE_NAME, packageName);
63     }
64     
65     public void initializeFields(IPluginModelBase model) {
66         String JavaDoc packageName = getFormattedPackageName(model.getPluginBase().getId());
67         initializeOption(KEY_PACKAGE_NAME, packageName);
68     }
69     
70     /*
71      * (non-Javadoc)
72      *
73      * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
74      */

75     public String JavaDoc getSectionId() {
76         return "helloRCP"; //$NON-NLS-1$
77
}
78
79     /* (non-Javadoc)
80      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
81      */

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

133         IPluginElement property = model.getFactory().createElement(element);
134         
135         property = model.getFactory().createElement(element);
136         property.setName("property"); //$NON-NLS-1$
137
property.setAttribute("name", "windowImages"); //$NON-NLS-1$ //$NON-NLS-2$
138
property.setAttribute("value", "icons/alt_window_16.gif,icons/alt_window_32.gif"); //$NON-NLS-1$ //$NON-NLS-2$
139
element.add(property);
140
141         extension.add(element);
142         
143         if (!extension.isInTheModel())
144             plugin.add(extension);
145     }
146     
147     /* (non-Javadoc)
148      * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
149      */

150     public String JavaDoc getUsedExtensionPoint() {
151         return null;
152     }
153     
154     /* (non-Javadoc)
155      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
156      */

157     public boolean isDependentOnParentWizard() {
158         return true;
159     }
160     
161     /* (non-Javadoc)
162      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
163      */

164     public int getNumberOfWorkUnits() {
165         return super.getNumberOfWorkUnits() + 1;
166     }
167     
168     /* (non-Javadoc)
169      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
170      */

171     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
172         IPluginReference[] dep = new IPluginReference[2];
173         dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
174
dep[1] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
175
return dep;
176     }
177     
178     /* (non-Javadoc)
179      * @see org.eclipse.pde.internal.ui.templates.PDETemplateSection#getNewFiles()
180      */

181     public String JavaDoc[] getNewFiles() {
182         if (copyBrandingDirectory())
183             return new String JavaDoc[] { "icons/", "splash.bmp" }; //$NON-NLS-1$ //$NON-NLS-2$
184
return super.getNewFiles();
185     }
186 }
187
Popular Tags