KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > ui > templates > AbstractNewPluginTemplateWizard


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui.templates;
12 import java.util.ArrayList JavaDoc;
13
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.SubProgressMonitor;
18 import org.eclipse.jface.wizard.Wizard;
19 import org.eclipse.pde.core.plugin.IPluginModelBase;
20 import org.eclipse.pde.core.plugin.IPluginReference;
21 import org.eclipse.pde.internal.ui.PDEPlugin;
22 import org.eclipse.pde.internal.ui.PDEPluginImages;
23 import org.eclipse.pde.internal.ui.PDEUIMessages;
24 import org.eclipse.pde.ui.IBundleContentWizard;
25 import org.eclipse.pde.ui.IFieldData;
26 /**
27  * This class is used as a common base for plug-in content wizards that are
28  * implemented using PDE template support. The assumption is that one or more
29  * templates will be used to generate plug-in content. Dependencies, new files
30  * and wizard pages are all computed based on the templates.
31  *
32  * @since 2.0
33  */

34 public abstract class AbstractNewPluginTemplateWizard extends Wizard
35         implements
36             IBundleContentWizard {
37     private IFieldData data;
38     /**
39      * Creates a new template wizard.
40      */

41     public AbstractNewPluginTemplateWizard() {
42         super();
43         setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
44         setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWEXPRJ_WIZ);
45         setNeedsProgressMonitor(true);
46     }
47     /**
48      * @see org.eclipse.pde.ui.IPluginContentWizard#init(IFieldData)
49      */

50     public void init(IFieldData data) {
51         this.data = data;
52         setWindowTitle(PDEUIMessages.PluginCodeGeneratorWizard_title);
53     }
54     /**
55      * Returns the field data passed to the wizard during the initialization.
56      *
57      * @return the parent wizard field data
58      */

59     public IFieldData getData() {
60         return data;
61     }
62     /**
63      * This wizard adds a mandatory first page. Subclasses implement this method
64      * to add additional pages to the wizard.
65      */

66     protected abstract void addAdditionalPages();
67     /**
68      * Implements wizard method. Subclasses cannot override it.
69      */

70     public final void addPages() {
71         addAdditionalPages();
72     }
73     /**
74      * @see org.eclipse.jface.wizard.Wizard#performFinish()
75      */

76     public boolean performFinish() {
77         // do nothing - all the work is in the other 'performFinish'
78
return true;
79     }
80     /**
81      * Implements the interface method by looping through template sections and
82      * executing them sequentially.
83      *
84      * @param project
85      * the project
86      * @param model
87      * the plug-in model
88      * @param monitor
89      * the progress monitor to track the execution progress as part
90      * of the overall new project creation operation
91      * @return <code>true</code> if the wizard completed the operation with
92      * success, <code>false</code> otherwise.
93      */

94     public boolean performFinish(IProject project, IPluginModelBase model,
95             IProgressMonitor monitor) {
96         try {
97             ITemplateSection[] sections = getTemplateSections();
98             monitor.beginTask("", sections.length); //$NON-NLS-1$
99
for (int i = 0; i < sections.length; i++) {
100                 sections[i].execute(project, model, new SubProgressMonitor(
101                         monitor, 1));
102             }
103             //No reason to do this any more with the new editors
104
//saveTemplateFile(project, null);
105
} catch (CoreException e) {
106             PDEPlugin.logException(e);
107             return false;
108         } finally {
109             monitor.done();
110         }
111         return true;
112     }
113     /**
114      * Returns the template sections used in this wizard.
115      *
116      * @return the array of template sections
117      */

118     public abstract ITemplateSection[] getTemplateSections();
119     /**
120      * @see org.eclipse.pde.ui.IPluginContentWizard#getDependencies(String)
121      */

122     public IPluginReference[] getDependencies(String JavaDoc schemaVersion) {
123         ArrayList JavaDoc result = new ArrayList JavaDoc();
124         ITemplateSection[] sections = getTemplateSections();
125         for (int i = 0; i < sections.length; i++) {
126             IPluginReference[] refs = sections[i]
127                     .getDependencies(schemaVersion);
128             for (int j = 0; j < refs.length; j++) {
129                 if (!result.contains(refs[j]))
130                     result.add(refs[j]);
131             }
132         }
133         return (IPluginReference[]) result.toArray(new IPluginReference[result
134                 .size()]);
135     }
136     /**
137      * @see org.eclipse.pde.ui.IPluginContentWizard#getNewFiles()
138      */

139     public String JavaDoc[] getNewFiles() {
140         ArrayList JavaDoc result = new ArrayList JavaDoc();
141         ITemplateSection[] sections = getTemplateSections();
142         for (int i = 0; i < sections.length; i++) {
143             String JavaDoc[] newFiles = sections[i].getNewFiles();
144             for (int j = 0; j < newFiles.length; j++) {
145                 if (!result.contains(newFiles[j]))
146                     result.add(newFiles[j]);
147             }
148         }
149         return (String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]);
150     }
151     
152     /* (non-Javadoc)
153      * @see org.eclipse.pde.ui.IPluginContentWizard#hasPages()
154      */

155     public boolean hasPages() {
156         return getTemplateSections().length > 0;
157     }
158     
159     public String JavaDoc[] getImportPackages() {
160         return new String JavaDoc[0];
161     }
162 }
163
Popular Tags