KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jbuilder > wizard > ImportWizard


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.jbuilder.wizard;
24
25 // ToolBox imports
26
import org.enhydra.tool.common.IconSet;
27 import org.enhydra.tool.common.ProgressMeter;
28
29 // JBuilder imports
30
import com.borland.jbuilder.node.HTMLFileNode;
31 import com.borland.jbuilder.node.JBProject;
32 import com.borland.primetime.ide.Browser;
33 import com.borland.primetime.node.Node;
34 import com.borland.primetime.wizard.BasicWizard;
35 import com.borland.primetime.wizard.BasicWizardPage;
36 import com.borland.primetime.wizard.Wizard;
37 import com.borland.primetime.wizard.WizardAction;
38 import com.borland.primetime.wizard.WizardHost;
39 import com.borland.primetime.wizard.WizardManager;
40 import com.borland.primetime.wizard.WizardPage;
41 import com.borland.primetime.util.VetoException;
42
43 // Kelp imports
44
import org.enhydra.kelp.KelpInfo;
45 import org.enhydra.kelp.common.ResUtil;
46 import org.enhydra.kelp.common.ValidationException;
47 import org.enhydra.kelp.common.importer.ImportPaths;
48 import org.enhydra.kelp.common.importer.ImportTool;
49 import org.enhydra.kelp.common.node.OtterProject;
50 import org.enhydra.kelp.common.node.OtterNodeFactory;
51 import org.enhydra.kelp.common.node.OtterFolderNode;
52 import org.enhydra.kelp.common.swing.KelpIconSet;
53 import org.enhydra.kelp.common.importer.ImportMapPanel;
54 import org.enhydra.kelp.common.importer.RootPanel;
55 import org.enhydra.kelp.common.importer.PathPanel;
56 import org.enhydra.kelp.common.importer.ImporterPanel;
57 import org.enhydra.kelp.jbuilder.wizard.AbstractBasicWizard;
58 import org.enhydra.kelp.jbuilder.node.PrimeProject;
59 import org.enhydra.kelp.jbuilder.node.PrimeProject;
60
61 // Standard imports
62
import java.awt.BorderLayout JavaDoc;
63 import java.io.File JavaDoc;
64 import javax.swing.JPanel JavaDoc;
65 import javax.swing.JOptionPane JavaDoc;
66 import javax.swing.SwingUtilities JavaDoc;
67 import java.util.ResourceBundle JavaDoc;
68
69 /**
70  * Class declaration
71  *
72  * @author Paul Mahar
73  */

74 public class ImportWizard extends AbstractBasicWizard {
75
76     // string not to be resourced
77
private final String JavaDoc HELP_LINK = KelpInfo.getAddinHelpURL(); // nores
78

79     //
80
private static String JavaDoc WIZARD_NAME = res.getString("Enhydra_Import");
81     private ImportPaths paths = null;
82     private OtterProject project = null;
83     public static WizardAction action = new LocalWizardAction();
84
85     /**
86      * Class declaration
87      */

88     static class LocalWizardAction extends WizardAction {
89         static ResourceBundle JavaDoc res =
90             ResourceBundle.getBundle("org.enhydra.kelp.jbuilder.Res");
91
92         public LocalWizardAction() {
93             super(ResUtil.format(res.getString("_0_dots"), ImportWizard.WIZARD_NAME),
94                   'p', res.getString("importNotEmpty1"),
95                   KelpIconSet.getSmallIcon(), KelpIconSet.getLargeIcon(),
96                   false);
97         }
98
99         protected Wizard createWizard() {
100             ImportWizard wizard = new ImportWizard();
101
102             return wizard;
103         }
104
105         public void update(Object JavaDoc source) {
106             setEnabled(AbstractBasicWizard.enableMenu);
107         }
108
109     }
110     ;
111
112     /**
113      * Method declaration
114      *
115      *
116      * @exception VetoException
117      */

118     public WizardPage finish(WizardPage currentPage,
119                              WizardHost host) throws VetoException {
120         ImportTool tool = null;
121         ProgressMeter progress = null;
122
123         tool = new ImportTool();
124         if (currentPage instanceof LocalWizardPage) {
125             LocalWizardPage localPage = (LocalWizardPage) currentPage;
126
127             localPage.checkPage();
128         }
129         progress = new ProgressMeter();
130         progress.setOwner(Browser.getActiveBrowser());
131         progress.setModal(true);
132         progress.setTitle(getWizardTitle());
133         tool.setPaths(paths);
134         tool.addProgressListener(progress);
135         progress.startDialogThread();
136         tool.importFilesFromRoot();
137         return super.finish(currentPage, host);
138     }
139
140     protected void finish() throws VetoException {
141         super.finish();
142     }
143
144     /**
145      * Method declaration
146      *
147      *
148      * @param majorVersion
149      * @param minorVersion
150      */

151     public static void initOpenTool(byte majorVersion, byte minorVersion) {
152         WizardManager.registerWizardAction(action);
153     }
154
155     /**
156      * Method declaration
157      *
158      *
159      * @param currentPage
160      * @param host
161      */

162     public String JavaDoc getHelpTopic() {
163         return HELP_LINK;
164     }
165
166     /**
167      * Method declaration
168      *
169      * @return
170      */

171     public String JavaDoc getDisplayName() {
172         return ImportWizard.WIZARD_NAME;
173     }
174
175     public static String JavaDoc getName() {
176         return ImportWizard.WIZARD_NAME;
177     }
178
179     public WizardPage invokeWizard(WizardHost host) {
180         WizardPage page = null;
181         boolean invokeIt = false;
182
183         try {
184           KelpInfo.verifyIDEClassPath();
185           invokeIt = true;
186         } catch (Exception JavaDoc e) {
187            JOptionPane.showMessageDialog(host.getDialogParent(),
188                       e.getMessage(),
189                       KelpInfo.getMessageBoxTitle(),
190                       JOptionPane.ERROR_MESSAGE);
191         }
192
193         if (invokeIt) {
194
195             setNativeProject((JBProject) host.getBrowser().getActiveProject());
196             if (!isProjectEmpty(getNativeProject())) {
197                 StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
198                 int choice = -1;
199
200                 buf.append(res.getString("importNotEmpty2"));
201                 buf.append(res.getString("importNotEmpty3"));
202                 buf.append(res.getString("importNotEmpty4"));
203                 buf.append(res.getString("importNotEmpty5"));
204                 choice =
205                     JOptionPane.showConfirmDialog(host.getDialogParent(),
206                                                   buf.toString(),
207                                                   ResUtil.format(res.getString("_0_Wizard_Error"), getDisplayName()),
208                                                   JOptionPane.WARNING_MESSAGE);
209                 if (choice == JOptionPane.CANCEL_OPTION) {
210                     invokeIt = false;
211                 }
212             }
213             if (invokeIt) {
214                 project = new PrimeProject(getNativeProject());
215                 paths = new ImportPaths();
216                 paths.setProject(project);
217                 String JavaDoc rootPath = project.getRootPath();
218
219                 if (rootPath != null && rootPath.trim().length() > 0) {
220                     try {
221                         paths.setRootPath(rootPath);
222                     } catch (ValidationException e) {
223                         e.printStackTrace();
224                     }
225                 }
226                 LocalWizardPage rootPage = new LocalWizardPage();
227                 LocalWizardPage pathPage = new LocalWizardPage();
228                 LocalWizardPage mapPage = new LocalWizardPage();
229
230                 rootPage.setPanel(new RootPanel());
231                 rootPage.setPaths(paths);
232                 pathPage.setPanel(new PathPanel());
233                 pathPage.setPaths(paths);
234                 mapPage.setPanel(new ImportMapPanel());
235                 mapPage.setPaths(paths);
236                 addWizardPage(rootPage);
237                 addWizardPage(pathPage);
238                 addWizardPage(mapPage);
239                 page = super.invokeWizard(host);
240             }
241         }
242         return page;
243     }
244
245     /**
246      * Method declaration
247      *
248      *
249      * @param nativeProject
250      *
251      * @return
252      */

253     private boolean isProjectEmpty(JBProject nativeProject) {
254         Node[] nodes = null;
255         boolean empty = true;
256
257         if (nativeProject != null) {
258             nodes = nativeProject.getChildren();
259         }
260         if (nodes != null) {
261             if (nodes.length > 1) {
262                 empty = false;
263             } else if (nodes.length == 1) {
264                 if (!(nodes[0] instanceof HTMLFileNode)) {
265                     empty = false;
266                 }
267             }
268         }
269         return empty;
270     }
271
272     /**
273      * Class declaration
274      *
275      *
276      * @author Paul Mahar
277      */

278     private class LocalWizardPage extends BasicWizardPage {
279         private ImporterPanel panel;
280
281         /**
282          * Constructor declaration
283          *
284          */

285         public LocalWizardPage() {
286             BorderLayout JavaDoc layout = new BorderLayout JavaDoc();
287
288             layout.setHgap(5);
289             layout.setVgap(5);
290             this.setLayout(layout);
291             if (KelpInfo.isToolBoxVersionInSynch()) {
292                 this.setLargeIcon(IconSet.getOtterWizard());
293             }
294         }
295
296         /**
297          * Method declaration
298          *
299          * @param host
300          */

301         public void activated(WizardHost host) {
302             panel.activated();
303         }
304
305         /**
306          * Method declaration
307          *
308          * @exception VetoException
309          */

310         public void checkPage() throws VetoException {
311             try {
312                 panel.checkPage();
313             } catch (ValidationException e) {
314                 JOptionPane.showMessageDialog(getWizardHost().getDialogParent(),
315                                               e.getMessage(),
316                                               getDisplayName(),
317                                               JOptionPane.ERROR_MESSAGE);
318                 throw new VetoException(e.toString());
319             }
320         }
321
322         /**
323          * Method declaration
324          *
325          * @param importer
326          */

327         public void setPaths(ImportPaths paths) {
328             panel.setPaths(paths);
329         }
330
331         /**
332          * Method declaration
333          *
334          * @return
335          */

336         public ImportPaths getPaths() {
337             return panel.getPaths();
338         }
339
340         protected void setPanel(ImporterPanel panel) {
341             this.panel = panel;
342             this.setPageTitle(panel.getPageTitle());
343             this.setInstructions(panel.getInstructions());
344             this.add(panel, BorderLayout.CENTER);
345         }
346
347         protected JPanel JavaDoc getPanel() {
348             return panel;
349         }
350
351     }
352 }
353
Popular Tags