KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 HelloNonUIRCPTemplate extends PDETemplateSection {
30     
31     public static final String JavaDoc KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$
32
public static final String JavaDoc KEY_APPLICATION_MESSAGE = "message"; //$NON-NLS-1$
33

34     public HelloNonUIRCPTemplate() {
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.HelloNonUIRCPTemplate_title);
42         page.setDescription(PDETemplateMessages.HelloNonUIRCPTemplate_desc);
43         wizard.addPage(page);
44         markPagesAdded();
45     }
46
47     
48     private void createOptions() {
49         addOption(KEY_PACKAGE_NAME,
50                 PDETemplateMessages.MailTemplate_packageName,
51                 (String JavaDoc) null, 0);
52         
53         addOption(KEY_APPLICATION_CLASS,
54                 PDETemplateMessages.HelloNonUIRCPTemplate_appClass,
55                 "Application", 0); //$NON-NLS-1$
56

57         addOption(KEY_APPLICATION_MESSAGE,
58                 PDETemplateMessages.HelloNonUIRCPTemplate_messageText,
59                 PDETemplateMessages.HelloNonUIRCPTemplate_defaultMessage, 0);
60     }
61     
62     protected void initializeFields(IFieldData data) {
63         // In a new project wizard, we don't know this yet - the
64
// model has not been created
65
String JavaDoc packageName = getFormattedPackageName(data.getId());
66         initializeOption(KEY_PACKAGE_NAME, packageName);
67     }
68     
69     public void initializeFields(IPluginModelBase model) {
70         String JavaDoc packageName = getFormattedPackageName(model.getPluginBase().getId());
71         initializeOption(KEY_PACKAGE_NAME, packageName);
72     }
73     
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
78      */

79     public String JavaDoc getSectionId() {
80         return "helloNonUIRCP"; //$NON-NLS-1$
81
}
82
83     /* (non-Javadoc)
84      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
85      */

86     protected void updateModel(IProgressMonitor monitor) throws CoreException {
87         createApplicationExtension();
88     }
89     
90     private void createApplicationExtension() throws CoreException {
91         IPluginBase plugin = model.getPluginBase();
92         
93         IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
94
extension.setId("application"); //$NON-NLS-1$
95

96         IPluginElement element = model.getPluginFactory().createElement(extension);
97         element.setName("application"); //$NON-NLS-1$
98
extension.add(element);
99         
100         IPluginElement run = model.getPluginFactory().createElement(element);
101         run.setName("run"); //$NON-NLS-1$
102
run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
103
element.add(run);
104         
105         if (!extension.isInTheModel())
106             plugin.add(extension);
107     }
108     
109     /* (non-Javadoc)
110      * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
111      */

112     public String JavaDoc getUsedExtensionPoint() {
113         return null;
114     }
115     
116     /* (non-Javadoc)
117      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
118      */

119     public boolean isDependentOnParentWizard() {
120         return true;
121     }
122     
123     /* (non-Javadoc)
124      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
125      */

126     public int getNumberOfWorkUnits() {
127         return super.getNumberOfWorkUnits() + 1;
128     }
129     
130     /* (non-Javadoc)
131      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
132      */

133     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
134         IPluginReference[] dep = new IPluginReference[1];
135         dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
136
return dep;
137     }
138     
139 }
140
Popular Tags