KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005 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.IPluginReference;
18 import org.eclipse.pde.internal.ui.IHelpContextIds;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20 import org.eclipse.pde.ui.templates.TemplateOption;
21
22
23 public class HelloOSGiTemplate extends PDETemplateSection {
24     
25     public static final String JavaDoc KEY_START_MESSAGE = "startMessage"; //$NON-NLS-1$
26
public static final String JavaDoc KEY_STOP_MESSAGE = "stopMessage"; //$NON-NLS-1$
27
public static final String JavaDoc KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$
28

29     private HelloOSGiNewWizard osgiWizard;
30     
31     public HelloOSGiTemplate(HelloOSGiNewWizard wizard) {
32         setPageCount(1);
33         osgiWizard = wizard;
34         addOption(KEY_START_MESSAGE, PDEUIMessages.HelloOSGiTemplate_startMessage, "Hello World!!", 0); //$NON-NLS-1$
35
addOption(KEY_STOP_MESSAGE, PDEUIMessages.HelloOSGiTemplate_stopMessage, "Goodbye World!!", 0); //$NON-NLS-1$
36
}
37     
38     public void addPages(Wizard wizard) {
39         WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL);
40         page.setTitle(PDEUIMessages.HelloOSGiTemplate_pageTitle);
41         page.setDescription(PDEUIMessages.HelloOSGiTemplate_pageDescription);
42         wizard.addPage(page);
43         markPagesAdded();
44     }
45     
46     public String JavaDoc getReplacementString(String JavaDoc fileName, String JavaDoc key) {
47         if (KEY_APPLICATION_CLASS.equals(key)) {
48             String JavaDoc className = osgiWizard.fData.getClassname();
49             return className.substring(className.lastIndexOf(".") + 1); //$NON-NLS-1$
50
} else if (KEY_PACKAGE_NAME.equals(key))
51             return getFormattedPackageName(osgiWizard.fData.getId());
52         return super.getReplacementString(fileName, key);
53     }
54     
55     /*
56      * (non-Javadoc)
57      *
58      * @see org.eclipse.pde.ui.templates.OptionTemplateSection#getSectionId()
59      */

60     public String JavaDoc getSectionId() {
61         return "helloOSGi"; //$NON-NLS-1$
62
}
63
64     /* (non-Javadoc)
65      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#validateOptions(org.eclipse.pde.ui.templates.TemplateOption)
66      */

67     public void validateOptions(TemplateOption source) {
68         if (source.isRequired() && source.isEmpty()) {
69             flagMissingRequiredOption(source);
70         } else {
71             validateContainerPage(source);
72         }
73     }
74     
75     private void validateContainerPage(TemplateOption source) {
76         TemplateOption[] allPageOptions = getOptions(0);
77         for (int i = 0; i < allPageOptions.length; i++) {
78             TemplateOption nextOption = allPageOptions[i];
79             if (nextOption.isRequired() && nextOption.isEmpty()) {
80                 flagMissingRequiredOption(nextOption);
81                 return;
82             }
83         }
84         resetPageState();
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#updateModel(org.eclipse.core.runtime.IProgressMonitor)
89      */

90     protected void updateModel(IProgressMonitor monitor) throws CoreException {
91         
92     }
93     
94     /* (non-Javadoc)
95      * @see org.eclipse.pde.ui.templates.ITemplateSection#getUsedExtensionPoint()
96      */

97     public String JavaDoc getUsedExtensionPoint() {
98         return null;
99     }
100     
101     /* (non-Javadoc)
102      * @see org.eclipse.pde.ui.templates.BaseOptionTemplateSection#isDependentOnParentWizard()
103      */

104     public boolean isDependentOnParentWizard() {
105         return true;
106     }
107     
108     /* (non-Javadoc)
109      * @see org.eclipse.pde.ui.templates.AbstractTemplateSection#getNumberOfWorkUnits()
110      */

111     public int getNumberOfWorkUnits() {
112         return super.getNumberOfWorkUnits() + 1;
113     }
114     
115     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
116         return new IPluginReference[0];
117     }
118 }
119
Popular Tags