KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jbuilder > tool > AbstractBasicTool


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.tool;
24
25 // ToolBox imports
26
import org.enhydra.tool.ToolBoxInfo;
27 import org.enhydra.tool.common.event.HelpEvent;
28 import org.enhydra.tool.common.event.HelpListener;
29
30 // Enhydra imports
31
import org.enhydra.xml.xmlc.XMLCException;
32
33 // JBuilder imports
34
import com.borland.jbuilder.JBuilderHelp;
35 import com.borland.jbuilder.JBuilderMenu;
36 import com.borland.jbuilder.node.JBProject;
37 import com.borland.primetime.actions.ActionGroup;
38 import com.borland.primetime.help.ZipHelpBook;
39 import com.borland.primetime.help.ZipHelpTopic;
40 import com.borland.primetime.ide.Browser;
41 import com.borland.primetime.ide.BrowserAction;
42 import com.borland.primetime.node.Project;
43 import com.borland.primetime.wizard.WizardHost;
44 import com.borland.primetime.wizard.WizardPage;
45
46 // Kelp imports
47
import org.enhydra.kelp.KelpInfo;
48 import org.enhydra.kelp.common.Constants;
49 import org.enhydra.kelp.common.node.OtterNode;
50 import org.enhydra.kelp.jbuilder.node.PrimeProject;
51
52 // Standard imports
53
import javax.swing.Action JavaDoc;
54 import javax.swing.JDialog JavaDoc;
55 import javax.swing.JOptionPane JavaDoc;
56 import java.awt.Component JavaDoc;
57 import java.awt.Container JavaDoc;
58 import java.util.ResourceBundle JavaDoc;
59
60 //
61
abstract public class AbstractBasicTool extends BrowserAction
62     implements HelpListener {
63     private static boolean init = true;
64
65     //
66
public static ResourceBundle JavaDoc res =
67         ResourceBundle.getBundle("org.enhydra.kelp.jbuilder.Res"); // nores
68

69     //
70
private JBProject nativeProject = null;
71
72     //
73
public static void initAllTools(byte majorVersion, byte minorVersion) {
74         if (AbstractBasicTool.init) {
75             ActionGroup group;
76
77             // standard check
78
if (majorVersion != 4) {
79                 return;
80             }
81
82             // Initialize OpenTool here...
83
System.out.println("Initializing Kelp Tools");
84
85             // Add to Tools menu.
86
group = new ActionGroup();
87             group.add(new DodsTool());
88             group.add(new XMLCTool());
89             group.add(new DeployTool());
90             JBuilderMenu.GROUP_Tools.add(group);
91             init = false;
92         }
93     }
94
95     //
96
abstract public String JavaDoc getDescription();
97     abstract public String JavaDoc getTitle();
98     abstract public String JavaDoc getHelpAnchor();
99
100     // implement: org.enhydra.kelp.common.event.HelpListener
101
public void onHelp(HelpEvent event) {
102         ZipHelpTopic topic = null;
103         ZipHelpBook book = null;
104         Object JavaDoc source = null;
105
106         source = event.getSource();
107         book = JBuilderHelp.createBook(Constants.KELP);
108         topic = new ZipHelpTopic(book, getHelpAnchor());
109         if (source instanceof JDialog JavaDoc) {
110             topic.show((JDialog JavaDoc) source);
111         } else if (source instanceof Component JavaDoc) {
112             topic.show((Component JavaDoc) source);
113         } else {
114             topic.show();
115         }
116     }
117
118     // Override: javax.swing.AbstractAction
119
public boolean isEnabled() {
120         return (Browser.getActiveBrowser().getActiveProject() != null);
121     }
122
123     // Override: javax.swing.AbstractAction
124
public Object JavaDoc getValue(String JavaDoc key) {
125         if (key.equals(Action.NAME)) {
126             return getTitle();
127         } else if (key.equals(Action.SHORT_DESCRIPTION)) {
128             return getTitle();
129         } else if (key.equals(Action.LONG_DESCRIPTION)) {
130             return getDescription();
131         }
132         return (super.getValue(key));
133     }
134
135     public JBProject getNativeProject() {
136         return nativeProject;
137     }
138
139     public void setNativeProject(JBProject p) {
140         nativeProject = p;
141     }
142
143     public void saveNodes(OtterNode[] nodes) {
144         if (nodes != null) {
145             for (int i = 0; i < nodes.length; i++) {
146                 nodes[i].save();
147             }
148         }
149     }
150
151     public boolean verifyAllClassPaths(Container JavaDoc owner) {
152         boolean valid = false;
153
154         try {
155             KelpInfo.verifyIDEClassPath();
156             valid = true;
157         } catch (Exception JavaDoc e) {
158             JOptionPane.showMessageDialog(owner, e.getMessage(),
159                                           KelpInfo.getMessageBoxTitle(),
160                                           JOptionPane.WARNING_MESSAGE);
161         }
162         if (valid) {
163             valid =
164                 nativeProject.getPaths().putClassOnFullPath(ToolBoxInfo.XMLC_VERSION_CLASS);
165             if (!valid) {
166                 StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
167
168                 buf.append(res.getString("EnhydraLibError1"));
169                 buf.append('\n');
170                 buf.append(res.getString("EnhydraLibError2"));
171                 JOptionPane.showMessageDialog(owner, buf.toString(),
172                                               KelpInfo.getMessageBoxTitle(),
173                                               JOptionPane.WARNING_MESSAGE);
174             }
175         }
176         return (valid);
177     }
178
179 }
180
Popular Tags