1 22 package org.objectweb.joram.client.tools.admin; 23 24 import java.awt.*; 25 import java.awt.event.*; 26 import javax.swing.*; 27 import javax.swing.event.*; 28 import javax.swing.tree.*; 29 import javax.jms.*; 30 import java.util.List ; 31 import java.util.Iterator ; 32 import java.net.ConnectException ; 33 34 import org.objectweb.joram.client.jms.admin.*; 35 import org.objectweb.joram.client.jms.tcp.*; 36 import org.objectweb.joram.client.jms.Queue; 37 import org.objectweb.joram.client.jms.Topic; 38 39 import org.objectweb.util.monolog.api.*; 40 41 public class AdminTool extends JFrame 42 implements ControllerEventListener 43 { 44 private static AdminTool adminTool = null; 45 46 private final AdminController c; 47 48 private final JTree configTree; 49 private final JTree jndiTree; 50 private final JTabbedPane tabbedPane; 51 private final JEditorPane msgPane; 52 private final ServerPanel serverPanel; 53 private final UserPanel userPanel; 54 private final DestinationPanel destPanel; 55 private final SubscriptionPanel subscriptionPanel; 56 private final MessagePanel messagePanel; 57 private final JPanel editPanel; 58 private final JSplitPane splitter; 59 private final JLabel connStatus; 60 61 private final Action exitAction, adminConnectAction, adminDisconnectAction, adminRefreshAction, 62 jndiConnectAction, jndiDisconnectAction, jndiRefreshAction, jndiCreateFactoryAction; 63 64 public AdminTool(final AdminController c) 65 { 66 super("JORAM Administration Tool"); 67 this.c = c; 68 69 ConnectAdminDialog.initialize(this); 70 ConnectJndiDialog.initialize(this); 71 CreateFactoryDialog.initialize(this); 72 CreateUserDialog.initialize(this); 73 CreateDestinationDialog.initialize(this); 74 CreateServerDialog.initialize(this); 75 CreateDomainDialog.initialize(this); 76 77 jndiConnectAction = new JndiConnectAction(); 78 jndiDisconnectAction = new JndiDisconnectAction(); 79 jndiDisconnectAction.setEnabled(false); 80 jndiRefreshAction = new JndiRefreshAction(); 81 jndiRefreshAction.setEnabled(false); 82 jndiCreateFactoryAction = new JndiCreateFactoryAction(); 83 jndiCreateFactoryAction.setEnabled(false); 84 85 adminConnectAction = new AdminConnectAction(); 86 adminDisconnectAction = new AdminDisconnectAction(); 87 adminDisconnectAction.setEnabled(false); 88 adminRefreshAction = new AdminRefreshAction(); 89 adminRefreshAction.setEnabled(false); 90 exitAction = new ExitAction(); 91 92 configTree = new JTree(c.getAdminTreeModel()); 94 configTree.expandRow(0); 95 configTree.setScrollsOnExpand(true); 96 configTree.setCellRenderer(new ConfigTreeCellRenderer()); 97 98 final TreeSelectionModel configTsm = new DefaultTreeSelectionModel(); 99 configTsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 100 configTree.setSelectionModel(configTsm); 101 102 jndiTree = new JTree(c.getJndiTreeModel()); 104 jndiTree.expandRow(0); 105 jndiTree.setScrollsOnExpand(true); 106 jndiTree.setCellRenderer(new ConfigTreeCellRenderer()); 107 108 final TreeSelectionModel jndiTsm = new DefaultTreeSelectionModel(); 109 jndiTsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 110 jndiTree.setSelectionModel(jndiTsm); 111 112 tabbedPane = new JTabbedPane(); 113 tabbedPane.add("Configuration", new JScrollPane(configTree)); 114 tabbedPane.add("JNDI", new JScrollPane(jndiTree)); 115 116 JPanel statusPanel = new JPanel(); 117 statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); 118 JLabel statusTitle = new JLabel("Admin connection: "); 119 statusPanel.add(statusTitle); 120 connStatus = new JLabel("Not connected"); 121 connStatus.setForeground(AdminToolConstants.COLOR_DISCONNECTED); 122 statusPanel.add(connStatus); 123 statusPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 124 125 msgPane = new JEditorPane("text/html", ""); 126 msgPane.setEditable(false); 127 128 serverPanel = new ServerPanel(c); 129 userPanel = new UserPanel(c); 130 destPanel = new DestinationPanel(c); 131 subscriptionPanel = new SubscriptionPanel(c); 132 messagePanel = new MessagePanel(); 133 134 editPanel = new JPanel(new CardLayout()); 135 editPanel.add(msgPane, "html"); 136 editPanel.add(serverPanel, "server"); 137 editPanel.add(userPanel, "user"); 138 editPanel.add(destPanel, "destination"); 139 editPanel.add(subscriptionPanel, "subscription"); 140 editPanel.add(messagePanel, "message"); 141 142 Component rightPane = new JScrollPane(editPanel); 143 144 JPanel rightPanel = new JPanel(new BorderLayout()); 145 rightPanel.add(statusPanel, BorderLayout.NORTH); 146 rightPanel.add(rightPane, BorderLayout.CENTER); 147 148 splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 149 tabbedPane, 150 rightPanel); 151 152 getContentPane().add(splitter, BorderLayout.CENTER); 153 154 setJMenuBar(buildMenuBar()); 155 156 c.getAdminTreeModel().addTreeModelListener(new TreeModelListener() { 159 public void treeNodesRemoved(TreeModelEvent e) {} 160 161 public void treeNodesChanged(TreeModelEvent e) {} 162 163 public void treeStructureChanged(final TreeModelEvent e) {} 164 165 public void treeNodesInserted(final TreeModelEvent e) 166 { 167 SwingUtilities.invokeLater(new Runnable () { 169 public void run() 170 { 171 configTree.expandPath(e.getTreePath()); 172 } 173 }); 174 } 175 }); 176 177 c.getJndiTreeModel().addTreeModelListener(new TreeModelListener() { 178 public void treeNodesRemoved(TreeModelEvent e) {} 179 180 public void treeNodesChanged(TreeModelEvent e) {} 181 182 public void treeStructureChanged(final TreeModelEvent e) {} 183 184 public void treeNodesInserted(final TreeModelEvent e) 185 { 186 SwingUtilities.invokeLater(new Runnable () { 188 public void run() 189 { 190 jndiTree.expandPath(e.getTreePath()); 191 } 192 }); 193 } 194 }); 195 196 configTree.addTreeSelectionListener(new TreeSelectionListener() { 200 public void valueChanged(javax.swing.event.TreeSelectionEvent e) { 201 if (Log.logger.isLoggable(BasicLevel.DEBUG)) 202 Log.logger.log(BasicLevel.DEBUG, 203 "TreeSelectionListener[configTree].valueChanged(" + e + ')'); 204 if (!configTsm.isSelectionEmpty()) { 205 TreeNode selection = (TreeNode) configTsm.getSelectionPath().getLastPathComponent(); 206 updateMessagePaneFromNode(selection); 207 } 208 } 209 }); 210 211 jndiTree.addTreeSelectionListener(new TreeSelectionListener() { 212 public void valueChanged(javax.swing.event.TreeSelectionEvent e) { 213 if (Log.logger.isLoggable(BasicLevel.DEBUG)) 214 Log.logger.log(BasicLevel.DEBUG, 215 "TreeSelectionListener[jndiTree].valueChanged(" + e + ')'); 216 if (!jndiTsm.isSelectionEmpty()) { 217 TreeNode selection = (TreeNode) jndiTsm.getSelectionPath().getLastPathComponent(); 218 updateMessagePaneFromNode(selection); 219 } 220 } 221 }); 222 223 MouseListener popupListener = new PopupListener(); 225 configTree.addMouseListener(popupListener); 226 jndiTree.addMouseListener(popupListener); 227 } 228 229 private void displayError(String errorMsg) { 230 if (Log.logger.isLoggable(BasicLevel.DEBUG)) 231 Log.logger.log(BasicLevel.DEBUG, 232 "AdminTool.displayError(" + errorMsg + ')'); 233 msgPane.setText("<font face=Arial><br><br><br><br><br><center><b>" + 234 errorMsg + 235 "</b></center></font>"); 236 ((CardLayout) editPanel.getLayout()).show(editPanel, "html"); 237 } 238 239 private JMenuBar buildMenuBar() 240 { 241 JMenuBar menuBar = new JMenuBar(); 242 243 JMenu adminMenu = new JMenu("Admin"); 245 adminMenu.add(adminConnectAction); 246 adminMenu.add(adminDisconnectAction); 247 adminMenu.addSeparator(); 248 adminMenu.add(adminRefreshAction); 249 adminMenu.addSeparator(); 250 adminMenu.add(exitAction); 251 252 JMenu jndiMenu = new JMenu("JNDI"); 254 jndiMenu.add(jndiConnectAction); 255 jndiMenu.add(jndiDisconnectAction); 256 jndiMenu.addSeparator(); 257 jndiMenu.add(jndiRefreshAction); 258 jndiMenu.addSeparator(); 259 jndiMenu.add(jndiCreateFactoryAction); 260 261 menuBar.add(adminMenu); 263 menuBar.add(jndiMenu); 264 265 return menuBar; 266 } 267 268 public void adminControllerEvent(ControllerEvent e) 269 { 270 int id = e.getId(); 271 if (id == ControllerEvent.ADMIN_CONNECTED) { 272 connStatus.setText(c.getAdminConnectionStatus()); 273 connStatus.setForeground(AdminToolConstants.COLOR_CONNECTED); 274 } 275 else if (id == ControllerEvent.ADMIN_DISCONNECTED) { 276 connStatus.setText(c.getAdminConnectionStatus()); 277 connStatus.setForeground(AdminToolConstants.COLOR_DISCONNECTED); 278 } 279 } 280 281 285 291 297 private void updateMessagePaneFromNode(final TreeNode selection) { 298 if (Log.logger.isLoggable(BasicLevel.DEBUG)) 299 Log.logger.log(BasicLevel.DEBUG, 300 "AdminTool.updateMessagePaneFromNode(" + selection + ')'); 301 if (selection instanceof AdminTreeNode) { 302 invokeLater(new CommandWorker() { 303 public void run() { 304 deferredMessagePaneUpdate(selection); 305 } 306 }); 307 } 308 else if (selection instanceof AdminTreeNode) { 309 msgPane.setText(((AdminTreeNode) selection).getDescription()); 310 ((CardLayout) editPanel.getLayout()).show(editPanel, "html"); 311 } 312 else { 313 msgPane.setText(""); 314 ((CardLayout) editPanel.getLayout()).show(editPanel, "html"); 315 } 316 } 317 318 public static void invokeLater(final CommandWorker worker) { 319 final AdminCommandDialog dlg = new AdminCommandDialog( 320 getInstance(), getInstance().c); 321 new Thread (new Runnable () { 322 public void run() { 323 try { 324 worker.run(); 325 dlg.close(); 326 } catch (Exception exc) { 327 if (Log.logger.isLoggable(BasicLevel.ERROR)) 328 Log.logger.log(BasicLevel.ERROR, "", exc); 329 dlg.close(); 330 JOptionPane.showMessageDialog(AdminTool.getInstance(), 331 exc.getMessage()); 332 } 333 } 334 }).start(); 335 dlg.showDialog(); 336 } 337 338 void updateSubscriptions(User user, 339 MutableTreeNode subRoot) 340 throws ConnectException , AdminException { 341 Subscription[] subscriptions = user.getSubscriptions(); 342 for (int i = 0; i < subscriptions.length; i++) { 343 SubscriptionTreeNode subNode = new SubscriptionTreeNode( 344 c, subscriptions[i]); 345 c.getAdminTreeModel().insertNodeInto( 346 subNode, 347 subRoot, 348 subRoot.getChildCount()); 349 } 350 } 351 352 private void deferredMessagePaneUpdate(TreeNode selection) { 353 if (Log.logger.isLoggable(BasicLevel.DEBUG)) 354 Log.logger.log(BasicLevel.DEBUG, 355 "AdminTool.deferredMessagepaneUpdate(" + selection + ')'); 356 try { 357 if (selection instanceof ServerTreeNode) { 358 ServerTreeNode stn = (ServerTreeNode) selection; 359 serverPanel.setServerId(stn.getServerId()); 360 int threshold = c.getDefaultThreshold(stn.getServerId()); 361 serverPanel.setDefaultThreshold((threshold < 0 ? "" : Integer.toString(threshold))); 362 serverPanel.setDMQList(stn.getDeadMessageQueues(), c.getDefaultDMQ(stn.getServerId())); 363 ((CardLayout) editPanel.getLayout()).show(editPanel, "server"); 364 365 try { 366 if (stn.getDestinationRoot().getChildCount() == 0) { 367 c.updateDestinations(stn.getServerId(), 369 stn.getDestinationRoot()); 370 } 371 372 if (stn.getUserRoot().getChildCount() == 0) { 373 c.updateUsers(stn.getServerId(), 375 stn.getUserRoot()); 376 } 377 } catch (AdminException exc) { 378 if (Log.logger.isLoggable(BasicLevel.WARN)) 379 Log.logger.log(BasicLevel.WARN, "", exc); 380 } catch (ConnectException ce) { 381 if (Log.logger.isLoggable(BasicLevel.WARN)) 382 Log.logger.log(BasicLevel.WARN, "", ce); 383 } 384 } else if (selection instanceof UserTreeNode) { 385 UserTreeNode utn = (UserTreeNode) selection; 386 userPanel.setUser(utn.getUser()); 387 int threshold = c.getUserThreshold(utn.getUser()); 388 userPanel.setThreshold((threshold < 0 ? "" : Integer.toString(threshold))); 389 userPanel.setDMQList(utn.getParentServerTreeNode().getDeadMessageQueues(), 390 c.getUserDMQ(utn.getUser())); 391 392 ((CardLayout) editPanel.getLayout()).show(editPanel, "user"); 393 } else if (selection instanceof DestinationTreeNode) { 394 DestinationTreeNode dtn = (DestinationTreeNode) selection; 395 destPanel.setDestination(dtn.getDestination()); 396 int threshold = -1; 397 try { 398 Queue q = (Queue) dtn.getDestination(); 399 threshold = c.getQueueThreshold(q); 400 destPanel.setThresholdActive(true); 401 destPanel.setPendingMessages(c.getPendingMessages(q)); 402 destPanel.setPendingRequests(c.getPendingRequests(q)); 403 } 404 catch (ClassCastException cce) { 405 destPanel.setThresholdActive(false); 406 destPanel.setPendingMessages(-1); 407 destPanel.setPendingRequests(-1); 408 } 409 finally { 410 destPanel.setThreshold((threshold < 0 ? "" : Integer.toString(threshold))); 411 } 412 413 destPanel.setDMQList(dtn.getParentServerTreeNode().getDeadMessageQueues(), 414 c.getDestinationDMQ(dtn.getDestination())); 415 416 destPanel.setFreeReading(c.isFreelyReadable(dtn.getDestination())); 417 destPanel.setFreeWriting(c.isFreelyWritable(dtn.getDestination())); 418 419 java.util.List users = dtn.getParentServerTreeNode().getUsers(); 420 destPanel.setReadingACL(users, c.getAuthorizedReaders(dtn.getDestination())); 421 destPanel.setWritingACL(users, c.getAuthorizedWriters(dtn.getDestination())); 422 423 ((CardLayout) editPanel.getLayout()).show(editPanel, "destination"); 424 } else if (selection instanceof DestinationRootTreeNode) { 425 if (selection.getChildCount() == 0) { 426 DestinationRootTreeNode drtn = (DestinationRootTreeNode)selection; 428 ServerTreeNode stn = drtn.getParentServerTreeNode(); 429 c.updateDestinations(stn.getServerId(), 430 stn.getDestinationRoot()); 431 } 432 } else if (selection instanceof UserRootTreeNode) { 433 if (selection.getChildCount() == 0) { 434 UserRootTreeNode urtn = (UserRootTreeNode)selection; 436 ServerTreeNode stn = urtn.getParentServerTreeNode(); 437 c.updateUsers(stn.getServerId(), 438 stn.getUserRoot()); 439 } 440 } else if (selection instanceof SubscriptionRootTreeNode) { 441 if (selection.getChildCount() == 0) { 442 SubscriptionRootTreeNode subRootTn = (SubscriptionRootTreeNode)selection; 444 UserTreeNode userTn = (UserTreeNode)subRootTn.getParent(); 445 updateSubscriptions(userTn.getUser(), 446 subRootTn); 447 } 448 } else if (selection instanceof SubscriptionTreeNode) { 449 SubscriptionTreeNode subTn = (SubscriptionTreeNode) selection; 450 SubscriptionRootTreeNode subRootTn = 451 (SubscriptionRootTreeNode)subTn.getParent(); 452 UserTreeNode userTn = (UserTreeNode)subRootTn.getParent(); 453 ServerTreeNode serverTn = userTn.getParentServerTreeNode(); 454 if (subTn.getChildCount() == 0) { 460 String [] ids = userTn.getUser().getMessageIds( 461 subTn.getSubscription().getName()); 462 for (int i = 0; i < ids.length; i++) { 463 MessageTreeNode msgNode = new MessageTreeNode( 464 c, ids[i]); 465 c.getAdminTreeModel().insertNodeInto( 466 msgNode, 467 subTn, 468 subTn.getChildCount()); 469 } 470 } 471 } else if (selection instanceof MessageTreeNode) { 472 Message msg; 473 MessageTreeNode msgTn = (MessageTreeNode)selection; 474 DefaultMutableTreeNode parentTn = 475 (DefaultMutableTreeNode)msgTn.getParent(); 476 if (parentTn instanceof SubscriptionTreeNode) { 477 SubscriptionTreeNode subTn = 478 (SubscriptionTreeNode)parentTn; 479 SubscriptionRootTreeNode subRootTn = 480 (SubscriptionRootTreeNode)subTn.getParent(); 481 UserTreeNode userTn = (UserTreeNode)subRootTn.getParent(); 482 ServerTreeNode serverTn = userTn.getParentServerTreeNode(); 483 msg = userTn.getUser().readMessage( 484 subTn.getSubscription().getName(), 485 msgTn.getMessageId()); 486 } else { 487 MessageRootTreeNode msgRootTn = 488 (MessageRootTreeNode)parentTn; 489 QueueTreeNode queueTn = 490 (QueueTreeNode)msgRootTn.getParent(); 491 msg = queueTn.getQueue().readMessage( 492 msgTn.getMessageId()); 493 } 494 messagePanel.setMessage(msg); 495 ((CardLayout) editPanel.getLayout()).show(editPanel, "message"); 496 } else if (selection instanceof SubscriberRootTreeNode) { 497 SubscriberRootTreeNode subRootTn = 498 (SubscriberRootTreeNode)selection; 499 if (subRootTn.getChildCount() == 0) { 500 TopicTreeNode topicTn = (TopicTreeNode)subRootTn.getParent(); 501 String [] subscriberIds = 502 topicTn.getTopic().getSubscriberIds(); 503 for (int i = 0; i < subscriberIds.length; i++) { 504 SubscriberTreeNode subTn = new SubscriberTreeNode( 505 subscriberIds[i]); 506 c.getAdminTreeModel().insertNodeInto( 507 subTn, 508 subRootTn, 509 subRootTn.getChildCount()); 510 } 511 } 512 } else if (selection instanceof MessageRootTreeNode) { 513 MessageRootTreeNode msgRootTn = 514 (MessageRootTreeNode)selection; 515 if (msgRootTn.getChildCount() == 0) { 516 QueueTreeNode queueTn = 517 (QueueTreeNode)msgRootTn.getParent(); 518 String [] msgIds = queueTn.getQueue().getMessageIds(); 519 for (int i = 0; i < msgIds.length; i++) { 520 MessageTreeNode msgTn = new MessageTreeNode( 521 c, msgIds[i]); 522 c.getAdminTreeModel().insertNodeInto( 523 msgTn, 524 msgRootTn, 525 msgRootTn.getChildCount()); 526 } 527 } 528 } 529 } catch (Exception exc) { 530 if (Log.logger.isLoggable(BasicLevel.DEBUG)) 531 Log.logger.log(BasicLevel.DEBUG, "", exc); 532 displayError(exc.getMessage()); 533 } 534 } 535 536 private class JndiConnectAction extends AbstractAction 537 { 538 public JndiConnectAction() 539 { 540 super("Connect..."); 541 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK)); 542 } 543 544 public void actionPerformed(ActionEvent e) 545 { 546 ConnectJndiDialog dialog; 547 try 548 { 549 dialog = ConnectJndiDialog.showDialog(); 550 } 551 catch (Exception exc) { 552 JOptionPane.showMessageDialog(AdminTool.this, exc.getMessage()); 553 return; 554 } 555 556 if (dialog.getActionCancelled()) 557 return; 558 559 try 560 { 561 c.connectJndi(dialog.getJndiHost(), dialog.getJndiPort(), dialog.getNamedContext()); 562 jndiConnectAction.setEnabled(false); 563 jndiDisconnectAction.setEnabled(true); 564 jndiRefreshAction.setEnabled(true); 565 if (c.isAdminConnected()) 566 jndiCreateFactoryAction.setEnabled(true); 567 } 568 catch (Exception x) { 569 JOptionPane.showMessageDialog(AdminTool.this, x.getMessage()); 570 } 571 } 572 } 573 574 private class JndiDisconnectAction extends AbstractAction 575 { 576 public JndiDisconnectAction() 577 { 578 super("Disconnect"); 579 } 580 581 public void actionPerformed(ActionEvent e) 582 { 583 try 584 { 585 c.disconnectJndi(); 586 } 587 catch (Exception x) { 588 JOptionPane.showMessageDialog(AdminTool.this, x.getMessage()); 589 } 590 finally { 591 jndiDisconnectAction.setEnabled(false); 592 jndiConnectAction.setEnabled(true); 593 jndiRefreshAction.setEnabled(false); 594 jndiCreateFactoryAction.setEnabled(false); 595 596 if (tabbedPane.getSelectedIndex() == 0) { 597 msgPane.setText(""); 598 ((CardLayout) editPanel.getLayout()).show(editPanel, "html"); 599 } 600 } 601 } 602 } 603 604 private class JndiRefreshAction extends AbstractAction 605 { 606 public JndiRefreshAction() 607 { 608 super("Refresh", AdminToolConstants.refreshIcon); 609 } 610 611 public void actionPerformed(ActionEvent e) 612 { 613 try 614 { 615 c.refreshJndiData(); 616 } 617 catch (Exception x) { 618 JOptionPane.showMessageDialog(AdminTool.this, x.getMessage()); 619 } 620 } 621 } 622 623 private class JndiCreateFactoryAction extends AbstractAction 624 { 625 public JndiCreateFactoryAction() 626 { 627 super("Create Connection Factory..."); 628 } 629 630 public void actionPerformed(ActionEvent e) 631 { 632 try 633 { 634 CreateFactoryDialog dialog = CreateFactoryDialog.showDialog(); 635 if (!dialog.getActionCancelled()) 636 c.createConnectionFactory(dialog.getHost(), dialog.getPort(), dialog.getFactoryName(), 637 dialog.getFactoryType()); 638 } 639 catch (Exception x) { 640 JOptionPane.showMessageDialog(AdminTool.this, x.getMessage()); 641 } 642 } 643 } 644 645 private class AdminConnectAction extends AbstractAction 646 { 647 public AdminConnectAction() 648 { 649 super("Connect..."); 650 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, KeyEvent.ALT_DOWN_MASK)); 651 } 652 653 public void actionPerformed(ActionEvent e) 654 { 655 ConnectAdminDialog dialog; 656 try 657 { 658 dialog = ConnectAdminDialog.showDialog(); 659 } 660 catch (Exception exc) { 661 JOptionPane.showMessageDialog(AdminTool.this, exc.getMessage()); 662 return; 663 } 664 665 if (dialog.getActionCancelled()) 666 return; 667 668 try 669 { 670 c.connectAdmin(dialog.getAdminHost(), dialog.getAdminPort(), 671 dialog.getAdminUser(), dialog.getAdminPassword()); 672 adminConnectAction.setEnabled(false); 673 adminDisconnectAction.setEnabled(true); 674 adminRefreshAction.setEnabled(true); 675 if (c.isJndiConnected()) 676 jndiCreateFactoryAction.setEnabled(true); 677 } 678 catch (Exception x) { 679 if (Log.logger.isLoggable(BasicLevel.DEBUG)) 680 Log.logger.log( 681 BasicLevel.DEBUG, "", x); 682 JOptionPane.showMessageDialog(AdminTool.this, x.getMessage()); 683 } 684 } 685 } 686 687 private class AdminDisconnectAction extends AbstractAction 688 { 689 public AdminDisconnectAction() 690 { 691 super("Disconnect"); 692 } 693 694 public void actionPerformed(ActionEvent e) 695 { 696 try 697 { 698 c.disconnectAdmin(); 699 } 700 catch (Exception x) { 701 JOptionPane.showMessageDialog(AdminTool.this, x.getMessage()); 702 } 703 finally { 704 adminDisconnectAction.setEnabled(false); 705 adminConnectAction.setEnabled(true); 706 adminRefreshAction.setEnabled(false); 707 jndiCreateFactoryAction.setEnabled(false); 708 709 if (tabbedPane.getSelectedIndex() == 0) { 710 msgPane.setText(""); 711 ((CardLayout) editPanel.getLayout()).show(editPanel, "html"); 712 } 713 } 714 } 715 } 716 717 private class AdminRefreshAction extends AbstractAction 718 { 719 public AdminRefreshAction() 720 { 721 super("Refresh", AdminToolConstants.refreshIcon); 722 } 723 724 public void actionPerformed(ActionEvent e) 725 { 726 AdminTool.invokeLater(new CommandWorker() { 727 public void run() throws Exception { 728 c.refreshAdminData(); 729 } 730 }); 731 } 732 } 733 734 private class ExitAction extends AbstractAction 735 { 736 public ExitAction() { super("Exit"); } 737 738 public void actionPerformed(ActionEvent e) 739 { 740 System.exit(0); 741 } 742 } 743 744 private class ConfigTreeCellRenderer extends DefaultTreeCellRenderer 745 { 746 public ConfigTreeCellRenderer() { 747 super(); 748 setClosedIcon(AdminToolConstants.collapsedIcon); 749 setOpenIcon(AdminToolConstants.expandedIcon); 750 } 751 752 public Component getTreeCellRendererComponent( 753 JTree tree, 754 Object value, 755 boolean sel, 756 boolean expanded, 757 boolean leaf, 758 int row, 759 boolean hasFocus) 760 { 761 super.getTreeCellRendererComponent( 762 tree, value, sel, 763 expanded, leaf, row, 764 hasFocus); 765 766 ImageIcon icon = null; 767 if (value instanceof AdminTreeNode) { 768 icon = ((AdminTreeNode) value).getImageIcon(); 769 setText(value.toString()); 770 } 771 else if (value == c.getAdminTreeModel().getRoot()) 772 icon = AdminToolConstants.homeIcon; 773 774 if (icon != null) 775 setIcon(icon); 776 777 return this; 778 } 779 } 780 781 private class PopupListener extends MouseAdapter { 782 public void mousePressed(MouseEvent e) { 783 maybeShowPopup(e); 784 } 785 786 public void mouseReleased(MouseEvent e) { 787 maybeShowPopup(e); 788 } 789 790 private void maybeShowPopup(MouseEvent e) { 791 if (e.isPopupTrigger()) { 792 TreePath tp; 793 if (tabbedPane.getSelectedIndex() == 0) { 794 tp = configTree.getPathForLocation( 795 e.getPoint().x, e.getPoint().y); 796 } else { 797 tp = jndiTree.getPathForLocation( 798 e.getPoint().x, e.getPoint().y); 799 } 800 if (tp != null) { 801 Object o = tp.getLastPathComponent(); 802 if (o instanceof AdminTreeNode) { 803 JPopupMenu popup = ((AdminTreeNode) o).getContextMenu(); 804 if (popup != null) { 805 popup.show(e.getComponent(), e.getX(), e.getY()); 806 } 807 } 808 } 809 } 810 } 811 } 812 813 public static AdminTool getInstance() 814 { 815 if (adminTool == null) { 816 AdminController c = new AdminController(); 817 adminTool = new AdminTool(c); 818 c.setControllerEventListener(adminTool); 819 820 adminTool.addWindowListener(new WindowAdapter() { 821 public void windowClosing(WindowEvent e) { System.exit(0); } 822 }); 823 } 824 825 return adminTool; 826 } 827 828 831 public static void main(String [] args) 832 { 833 AdminTool frame = getInstance(); 834 835 frame.setSize(AdminToolConstants.STARTUP_SIZE); 836 frame.setVisible(true); 837 frame.splitter.setDividerLocation(AdminToolConstants.DIVIDER_PROPORTION); 838 frame.repaint(); 839 } 840 } 841 | Popular Tags |