KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > templates > 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.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 HelloNonUIRCPTemplate extends PDETemplateSection {
29     
30     public static final String JavaDoc KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$
31
public static final String JavaDoc KEY_APPLICATION_MESSAGE = "message"; //$NON-NLS-1$
32

33     public HelloNonUIRCPTemplate() {
34         setPageCount(1);
35         createOptions();
36     }
37     
38     public void addPages(Wizard wizard) {
39         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL);
40         page.setTitle(PDEUIMessages.HelloNonUIRCPTemplate_title);
41         page.setDescription(PDEUIMessages.HelloNonUIRCPTemplate_desc);
42         wizard.addPage(page);
43         markPagesAdded();
44     }
45
46     
47     private void createOptions() {
48         addOption(KEY_PACKAGE_NAME,
49                 PDEUIMessages.MailTemplate_packageName,
50                 (String JavaDoc) null, 0);
51         
52         addOption(KEY_APPLICATION_CLASS,
53                 PDEUIMessages.HelloNonUIRCPTemplate_appClass,
54                 "Application", 0); //$NON-NLS-1$
55

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

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

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

108     protected void updateModel(IProgressMonitor monitor) throws CoreException {
109         createApplicationExtension();
110     }
111     
112     private void createApplicationExtension() throws CoreException {
113         IPluginBase plugin = model.getPluginBase();
114         
115         IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$
116
extension.setId("application"); //$NON-NLS-1$
117

118         IPluginElement element = model.getPluginFactory().createElement(extension);
119         element.setName("application"); //$NON-NLS-1$
120
extension.add(element);
121         
122         IPluginElement run = model.getPluginFactory().createElement(element);
123         run.setName("run"); //$NON-NLS-1$
124
run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$
125
element.add(run);
126         
127         if (!extension.isInTheModel())
128             plugin.add(extension);
129     }
130     
131     /* (non-Javadoc)
132      * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
133      */

134     public String JavaDoc getUsedExtensionPoint() {
135         return null;
136     }
137     
138     /* (non-Javadoc)
139      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
140      */

141     public boolean isDependentOnParentWizard() {
142         return true;
143     }
144     
145     /* (non-Javadoc)
146      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
147      */

148     public int getNumberOfWorkUnits() {
149         return super.getNumberOfWorkUnits() + 1;
150     }
151     
152     /* (non-Javadoc)
153      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getDependencies(java.lang.String)
154      */

155     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
156         IPluginReference[] dep = new IPluginReference[1];
157         dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); //$NON-NLS-1$
158
return dep;
159     }
160     
161 }
162
Popular Tags