1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2000 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: OpenJMSServer.java,v 1.3 2003/08/17 01:32:24 tanderson Exp $
44 *
45 * Date Author Changes
46 * $Date jimm Created
47 */
48
49 package org.exolab.jms.jndiadministration;
50
51 import java.awt.Rectangle;
52 import java.awt.event.ActionEvent;
53 import java.awt.event.ActionListener;
54 import java.util.Enumeration;
55
56 import javax.naming.NameClassPair;
57 import javax.swing.JMenuItem;
58 import javax.swing.JOptionPane;
59 import javax.swing.JPopupMenu;
60 import javax.swing.JTree;
61 import javax.swing.tree.DefaultMutableTreeNode;
62 import javax.swing.tree.DefaultTreeModel;
63
64
65 /***
66 * This class controls all dispay characteristics and menus related to an
67 * OpenJMS Jndi Server. Currently only add context is supported.
68 *
69 * @version $Revision: 1.3 $ $Date: 2003/08/17 01:32:24 $
70 * @author <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
71 * @see OpenJMSContext
72 * @see AdminMgr
73 * @see ObjectDialog
74 * @see OpenJMSObject
75 */
76 public class OpenJMSServer extends DefaultMutableTreeNode {
77
78 // The server name.
79 private String serverName_;
80
81 // A reference to the tree this node belongs to.
82 static private JTree tree_ = null;
83
84 // A flag indicating if the menu has been created yet.
85 static private boolean commandsCreated_ = false;
86
87 // The popup menu for all contexts
88 static private JPopupMenu commands_ = null;
89
90 /***
91 * The OpenJMS server connection. Currently there is only one
92 * OpenJMSServer connection at a time.
93 *
94 * @param serverName The name of this server
95 * @param tree The parent tree this root node belongs to.
96 *
97 */
98 public OpenJMSServer(String serverName, JTree tree) {
99 serverName_ = serverName;
100 if (!commandsCreated_) {
101 tree_ = tree;
102 createCommands();
103 commandsCreated_ = true;
104 }
105 }
106
107
108 /***
109 * Create the menu for all servers and set up the Action events for
110 * each menu item. Since menus are shared, the callbacks called are
111 * static. Once a menu is slected, the slected node can be determined
112 * from the parent object.
113 *
114 */
115 protected void createCommands() {
116 commands_ = new JPopupMenu();
117 JMenuItem m = new JMenuItem("Create Context");
118 m.addActionListener(new ActionListener() {
119
120 public void actionPerformed(ActionEvent evt) {
121 createContext();
122 }
123 }
124 );
125 commands_.add(m);
126 }
127
128
129 /***
130 * Determine all known OpenJMSServers. For the moment only the offline
131 * mode is supported, which is basically opening up the database directly.
132 *
133 * @param tree The parent tree this root node belongs to.
134 *
135 */
136 static public DefaultTreeModel createServerList(JTree tree) {
137 // todo try and connect to all known servers.
138 // for the moment just add one.
139 OpenJMSServer server = new OpenJMSServer("Root", tree);
140 return new DefaultTreeModel(server);
141 }
142
143
144 /***
145 * Get all Contexts from the database for this JMS server and display
146 * them as children of the root node.
147 *
148 */
149 public void displayContexts() {
150 Enumeration e = AdminConnection.instance().getAllContexts(null);
151 if (e != null) {
152 while (e.hasMoreElements()) {
153 NameClassPair pair = (NameClassPair) e.nextElement();
154 add(new OpenJMSContext(pair.getName(), null, tree_));
155 }
156 refresh();
157 }
158 }
159
160
161 /***
162 * Children are allowed for all servers
163 *
164 * @return boolean Always returns true.
165 *
166 */
167 public boolean getAllowsChildren() {
168 return true;
169 }
170
171
172 /***
173 * This node has been right clicked. The locations of this node is given
174 * by the loc object. Use this location to popup the server message
175 * menu.
176 *
177 * @param The location of this node.
178 *
179 */
180 public void displayCommands(Rectangle loc) {
181 double x;
182 double y;
183
184 x = loc.getX();
185 y = loc.getY();
186 y += loc.getHeight();
187
188 commands_.show(tree_, (int) x, (int) y);
189 }
190
191
192 /***
193 * The unique name of this server
194 *
195 * @return String the server name.
196 *
197 */
198 public String toString() {
199 return serverName_;
200 }
201
202
203 /***
204 * This node has changed. Inform the parent tree that it needs to be
205 * re-drawn.
206 *
207 */
208 public void refresh() {
209 DefaultTreeModel model = (DefaultTreeModel) tree_.getModel();
210 model.nodeStructureChanged((DefaultMutableTreeNode) this);
211 }
212
213 /***
214 * Get the particular instance of the server that has been selected.
215 *
216 * @return OpenJMSServer the instance selected.
217 *
218 */
219 static private OpenJMSServer getInstanceSelected() {
220 Object loc = tree_.getLastSelectedPathComponent();
221 return (OpenJMSServer) loc;
222 }
223
224
225 /***
226 * A new context is being added for this server. Popup a context
227 * add dialog, to collect relevent information, then update the database.
228 * If the database update is successful, add the context node as a
229 * a child of this server node, and refresh.
230 *
231 */
232 static private void createContext() {
233 OpenJMSServer This = getInstanceSelected();
234 ObjectDialog.instance().display("Enter a unique context name",
235 "Context Creation");
236 if (ObjectDialog.instance().isConfirmed()) {
237 try {
238 AdminConnection.instance().createContext
239 (ObjectDialog.instance().getName());
240 This.add(new OpenJMSContext
241 (ObjectDialog.instance().getName(), null, tree_));
242 This.refresh();
243 } catch (javax.naming.NamingException err) {
244 JOptionPane.showMessageDialog
245 (tree_, err.getMessage(),
246 "Context Create Error", JOptionPane.ERROR_MESSAGE);
247 }
248 }
249 }
250
251 } // End ServerList
This page was automatically generated by Maven