View Javadoc
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: AdminMgr.java,v 1.6 2003/08/07 13:32:59 tanderson Exp $ 44 * 45 * Date Author Changes 46 * $Date jimm Created 47 */ 48 49 50 package org.exolab.jms.jndiadministration; 51 52 import java.awt.BorderLayout; 53 import java.awt.Dimension; 54 import java.awt.Toolkit; 55 import java.awt.event.ActionEvent; 56 import java.awt.event.ActionListener; 57 import java.awt.event.MouseAdapter; 58 import java.awt.event.MouseEvent; 59 import java.awt.event.WindowAdapter; 60 import java.awt.event.WindowEvent; 61 import java.io.PrintStream; 62 63 import javax.swing.JComboBox; 64 import javax.swing.JFrame; 65 import javax.swing.JMenu; 66 import javax.swing.JMenuBar; 67 import javax.swing.JMenuItem; 68 import javax.swing.JOptionPane; 69 import javax.swing.JScrollPane; 70 import javax.swing.JTextField; 71 import javax.swing.JTree; 72 import javax.swing.SwingConstants; 73 import javax.swing.SwingUtilities; 74 import javax.swing.event.TreeExpansionEvent; 75 import javax.swing.event.TreeExpansionListener; 76 import javax.swing.tree.DefaultMutableTreeNode; 77 import javax.swing.tree.DefaultTreeModel; 78 import javax.swing.tree.TreePath; 79 80 import org.exolab.jms.config.Configuration; 81 import org.exolab.jms.config.ConfigurationManager; 82 import org.exolab.jms.util.CommandLine; 83 84 85 /*** 86 * This class is the Gui controller for the JMS JNDI administration. It 87 * displays data as a hierarchical set of tree nodes. 88 * 89 * <P>The Root is all the contactable JMS servers, idealy there can be several 90 * of these all on different ports, with one common admin port they all listen 91 * to. A user selects a JMSServer then connects via the menu item. This 92 * allows the admin GUI to connect to the server via the main port and begin 93 * displaying all its JndiContexts 94 * 95 * <P>For the moment this is not truly dynamic, that is a refresh needs to be 96 * activated on the Gui to cause an update (other than changes made 97 * through the Gui istelf). 98 * 99 * @version $Revision: 1.6 $ $Date: 2003/08/07 13:32:59 $ 100 * @author <a href="mailto:mourikis@exolab.org">Jim Mourikis</a> 101 * 102 **/ 103 104 public class AdminMgr extends JFrame { 105 106 // Gui Declarations 107 private JMenuBar menuBar_; 108 private JMenu file_; 109 private JMenuItem exit_; 110 private JMenu actions_; 111 private JMenu connections_; 112 private JMenuItem refresh_; 113 private JMenuItem online_; 114 private JMenuItem offline_; 115 private JMenuItem disconnect_; 116 private JScrollPane jMSServers_; 117 private JTree serverProperties_; 118 private JTextField messageArea_; 119 private JComboBox jMSCombo_; 120 121 // If this Admin object is connected to any OpenJMS 122 private boolean connected_ = false; 123 124 /*** 125 * The default constructor performs all gui creations. 126 * 127 */ 128 public AdminMgr() { 129 initComponents(); 130 pack(); 131 } 132 133 /*** This method is called from within the constructor to 134 * initialize the form. All the GUI objects are created, and callbacks 135 * registered. 136 */ 137 private void initComponents() { 138 menuBar_ = new JMenuBar(); 139 file_ = new JMenu(); 140 exit_ = new JMenuItem(); 141 actions_ = new JMenu(); 142 connections_ = new JMenu(); 143 refresh_ = new JMenuItem(); 144 online_ = new JMenuItem(); 145 offline_ = new JMenuItem(); 146 disconnect_ = new JMenuItem(); 147 jMSServers_ = new JScrollPane(); 148 jMSCombo_ = new JComboBox(); 149 serverProperties_ = new JTree(); 150 setTitle("OpenJMS JNDI Admin"); 151 DefaultTreeModel serverModel = 152 OpenJMSServer.createServerList(serverProperties_); 153 serverProperties_.setModel(serverModel); 154 155 messageArea_ = new JTextField(); 156 file_.setText("File"); 157 exit_.setToolTipText("Exit administration"); 158 exit_.setText("Exit"); 159 exit_.setMnemonic('x'); 160 161 serverProperties_.setRootVisible(false); 162 serverProperties_.setShowsRootHandles(true); 163 serverProperties_.putClientProperty("JTree.lineStyle", "Angled"); 164 // serverProperties_.setCellEditor(new OpenJMSEditor(serverProperties_, 165 // jMSCombo_)); 166 serverProperties_.setEditable(false); 167 setupCallbacks(); 168 file_.add(exit_); 169 file_.setMnemonic('F'); 170 menuBar_.add(file_); 171 actions_.setText("Actions"); 172 actions_.setMnemonic('A'); 173 connections_.setText("Connections"); 174 connections_.setMnemonic('C'); 175 refresh_.setToolTipText("Refresh the display"); 176 online_.setToolTipText("Connect to a running OpenJMS JNDI Server"); 177 offline_.setToolTipText("Connect directly to a JNDI database"); 178 refresh_.setText("Refresh"); 179 refresh_.setMnemonic('R'); 180 actions_.add(refresh_); 181 182 online_.setText("Online"); 183 online_.setMnemonic('O'); 184 offline_.setText("Offline"); 185 offline_.setMnemonic('f'); 186 connections_.add(online_); 187 connections_.add(offline_); 188 actions_.add(connections_); 189 disconnect_.setToolTipText 190 ("Disconnect from any connected OpenJMS JNDI Servers"); 191 disconnect_.setText("Disconnect"); 192 disconnect_.setMnemonic('D'); 193 actions_.add(disconnect_); 194 195 menuBar_.add(actions_); 196 197 jMSServers_.setViewportView(serverProperties_); 198 199 200 getContentPane().add(jMSServers_, BorderLayout.CENTER); 201 202 messageArea_.setToolTipText("Message Area"); 203 messageArea_.setEditable(false); 204 messageArea_.setForeground(java.awt.Color.red); 205 messageArea_.setText("Not Connected"); 206 messageArea_.setHorizontalAlignment(SwingConstants.CENTER); 207 208 209 getContentPane().add(messageArea_, BorderLayout.SOUTH); 210 setJMenuBar(menuBar_); 211 refresh_.setEnabled(false); 212 disconnect_.setEnabled(false); 213 } 214 215 /*** 216 * The exit method for the application, when the user shutdowns the form. 217 * 218 * @param evt The event that triggered this action. 219 * 220 */ 221 private void exitAdmin(ActionEvent evt) { 222 System.exit(0); 223 } 224 225 /*** 226 * Exit the Application when a user selects File->Exit from the menu 227 * 228 * @param evt The window event that triggered this call. 229 * 230 */ 231 private void exitForm(WindowEvent evt) { 232 System.exit(0); 233 } 234 235 236 /*** 237 * Refresh the display, and repaint all items. 238 * 239 * @param evt The event that triggered this operation. 240 * 241 */ 242 private void refresh(ActionEvent evt) { 243 if (AdminConnection.instance() instanceof OnlineConnection) { 244 setConnected(false, null); 245 setConnected(true, "Connected - Online Mode"); 246 } else { 247 ((OpenJMSServer) (serverProperties_.getModel().getRoot() 248 )).refresh(); 249 } 250 } 251 252 253 /*** 254 * When a user wishes to connect to all known OpenJMSServers. 255 * Attempt to create an RMI connection to the OpenJMSServer. If the server 256 * is not running, this will fail. The user can start the server through 257 * the start server command, and attempt to re-connect, or use the offline 258 * method below. 259 * 260 * @param evt The event that triggered this operation. 261 * 262 */ 263 private void onlineConnect(ActionEvent evt) { 264 try { 265 // if online. 266 new OnlineConnection(this); 267 setConnected(true, "Connected - Online Mode"); 268 } catch (Exception err) { 269 JOptionPane.showMessageDialog 270 (this, err.getMessage(), "Online Connection Error", 271 JOptionPane.ERROR_MESSAGE); 272 } 273 } 274 275 276 /*** 277 * Connect to the database in offline mode. This action causes 278 * the file chooser to be displayed, and the user must select an existing 279 * database, or enter a new name to create a new database. 280 * 281 * All databases are suffixed with a ".db". 282 * 283 * @param evt The event that triggered this operation. 284 * 285 */ 286 private void offlineConnect(ActionEvent evt) { 287 try { 288 // if online. 289 new OfflineConnection(this); 290 setConnected(true, "Connected - OFFLine Mode"); 291 } catch (Exception err) { 292 JOptionPane.showMessageDialog 293 (this, err.getMessage(), "Database Error", 294 JOptionPane.ERROR_MESSAGE); 295 } 296 } 297 298 /*** 299 * Disconnect from a connected OpenJMSServer. Close the database, set the 300 * connected flag to false, stop displaying the OpenJMS folder. 301 * 302 * @param evt The event that triggered this operation. 303 * 304 */ 305 private void disconnect(ActionEvent evt) { 306 try { 307 AdminConnection.instance().close(); 308 setConnected(false, null); 309 } catch (Exception e) { 310 JOptionPane.showMessageDialog 311 (this, e.getMessage(), "Database Close Error", 312 JOptionPane.ERROR_MESSAGE); 313 } 314 } 315 316 /*** 317 * A conveniance routine to open/close all database connections, 318 * and fix up the display. 319 * 320 * <P>When disconnecting, turn off the root, destroy all Gui objects 321 * close the db connection, turn off all context sensitive menus, 322 * disable disconnection menu and enable connection. Set the message 323 * text to disconnected. 324 * 325 * @param c a flag inidication if this is a connection or disconnection. 326 * 327 */ 328 329 private void setConnected(boolean c, String st) { 330 if (c) { 331 serverProperties_.setRootVisible(true); 332 ((OpenJMSServer) 333 (serverProperties_.getModel().getRoot())).displayContexts(); 334 connections_.setEnabled(false); 335 refresh_.setEnabled(true); 336 disconnect_.setEnabled(true); 337 messageArea_.setForeground(java.awt.Color.green.darker().darker()); 338 messageArea_.setText(st); 339 connected_ = true; 340 } else { 341 serverProperties_.setRootVisible(false); 342 OpenJMSServer root = 343 (OpenJMSServer) serverProperties_.getModel().getRoot(); 344 root.removeAllChildren(); 345 DefaultTreeModel model = 346 (DefaultTreeModel) serverProperties_.getModel(); 347 model.nodeStructureChanged((DefaultMutableTreeNode) root); 348 connections_.setEnabled(true); 349 refresh_.setEnabled(false); 350 disconnect_.setEnabled(false); 351 messageArea_.setForeground(java.awt.Color.red); 352 messageArea_.setText("Not Connected"); 353 connected_ = false; 354 } 355 } 356 357 358 /*** 359 * Set up all Action menu callbacks, and mouse events for the tree and its 360 * nodes. Check all mose 2 key presses on a node, select the node, 361 * then call the nodes appropriate display methos to display its 362 * specific popup menus. 363 * 364 */ 365 private void setupCallbacks() { 366 367 addWindowListener(new WindowAdapter() { 368 369 public void windowClosing(WindowEvent evt) { 370 exitForm(evt); 371 } 372 } 373 ); 374 375 376 serverProperties_.addMouseListener(new MouseAdapter() { 377 378 public void mousePressed(MouseEvent e) { 379 if (!connected_) { 380 return; 381 } 382 383 if (SwingUtilities.isRightMouseButton(e)) { 384 int selRow = serverProperties_.getRowForLocation 385 (e.getX(), e.getY()); 386 387 serverProperties_.setSelectionRow(selRow); 388 Object loc = 389 serverProperties_.getLastSelectedPathComponent(); 390 if (loc instanceof OpenJMSNode) { 391 OpenJMSNode node = (OpenJMSNode) loc; 392 node.displayCommands 393 (serverProperties_.getRowBounds(selRow)); 394 } else if (loc instanceof OpenJMSServer) { 395 ((OpenJMSServer) loc).displayCommands 396 (serverProperties_.getRowBounds(selRow)); 397 } 398 } 399 } 400 } 401 ); 402 403 serverProperties_.addTreeExpansionListener(new TreeExpansionListener() { 404 405 public void treeCollapsed(TreeExpansionEvent e) { 406 // todo Anything..... 407 } 408 409 public void treeExpanded(TreeExpansionEvent e) { 410 TreePath path = e.getPath(); 411 Object loc = path.getLastPathComponent(); 412 if (loc instanceof OpenJMSNode) { 413 OpenJMSNode node = (OpenJMSNode) loc; 414 node.update(); 415 } 416 } 417 } 418 ); 419 420 exit_.addActionListener(new ActionListener() { 421 422 public void actionPerformed(ActionEvent evt) { 423 exitAdmin(evt); 424 } 425 } 426 ); 427 428 429 refresh_.addActionListener(new ActionListener() { 430 431 public void actionPerformed(ActionEvent evt) { 432 refresh(evt); 433 } 434 } 435 ); 436 437 438 online_.addActionListener(new ActionListener() { 439 440 public void actionPerformed(ActionEvent evt) { 441 onlineConnect(evt); 442 } 443 } 444 ); 445 446 offline_.addActionListener(new ActionListener() { 447 448 public void actionPerformed(ActionEvent evt) { 449 offlineConnect(evt); 450 } 451 } 452 ); 453 454 disconnect_.addActionListener(new ActionListener() { 455 456 public void actionPerformed(ActionEvent evt) { 457 disconnect(evt); 458 } 459 } 460 ); 461 462 } 463 464 465 /*** 466 * The main entry point for this admin gui. 467 * The main form and any support dialogs are created. 468 * An initial size is given, and the gui placed in the middle of the screen 469 * 470 * @param args the command line arguments 471 * 472 */ 473 public static void main(String args[]) { 474 try { 475 CommandLine cmdline = new CommandLine(args); 476 if (cmdline.exists("help")) { 477 // print the usage information 478 usage(); 479 } else if (cmdline.exists("config")) { 480 ConfigurationManager.setConfig(cmdline.value("config")); 481 Configuration config = ConfigurationManager.getConfig(); 482 483 AdminMgr admin = new AdminMgr(); 484 QueryDialog.create(admin); 485 ObjectDialog.create(admin); 486 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 487 // About center of screen 488 admin.setLocation(screen.width / 2 - 150, screen.height / 2 - 150); 489 admin.setSize(300, 300); 490 admin.invalidate(); 491 admin.show(); 492 } else { 493 // anything else print the usage message 494 usage(); 495 } 496 } catch (Exception err) { 497 err.printStackTrace(); 498 System.err.println("Failed to initialize JNDI AdminMgr.\nExiting...."); 499 } 500 } 501 502 /*** 503 * Print out information on running this sevice 504 */ 505 static protected void usage() { 506 PrintStream out = System.out; 507 508 out.println("\n\n"); 509 out.println("====================================================="); 510 out.println("Usage information for org.exolab.jms." + 511 "jndiadministration.AdminMgr"); 512 out.println("====================================================="); 513 out.println("\norg.exolab.jms.jndiadministration.AdminMgr"); 514 out.println(" [-help | -config <xml config file>]\n"); 515 out.println("\t-help displays this screen\n"); 516 out.println("\t-config file name of xml-based config file\n"); 517 } 518 519 } // End AdminMgr 520

This page was automatically generated by Maven