📄 admintool.java
字号:
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Initial developer(s): Alexander Fedorowicz * Contributor(s): */package org.objectweb.joram.client.tools.admin;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import javax.swing.tree.*;import javax.jms.*;import java.util.List;import java.util.Iterator;import java.net.ConnectException;import org.objectweb.joram.client.jms.admin.*;import org.objectweb.joram.client.jms.tcp.*;import org.objectweb.joram.client.jms.Queue;import org.objectweb.joram.client.jms.Topic;import org.objectweb.util.monolog.api.*;public class AdminTool extends JFrame implements ControllerEventListener{ private static AdminTool adminTool = null; private final AdminController c; private final JTree configTree; private final JTree jndiTree; private final JTabbedPane tabbedPane; private final JEditorPane msgPane; private final ServerPanel serverPanel; private final UserPanel userPanel; private final DestinationPanel destPanel; private final SubscriptionPanel subscriptionPanel; private final MessagePanel messagePanel; private final JPanel editPanel; private final JSplitPane splitter; private final JLabel connStatus; private final Action exitAction, adminConnectAction, adminDisconnectAction, adminRefreshAction, jndiConnectAction, jndiDisconnectAction, jndiRefreshAction, jndiCreateFactoryAction; public AdminTool(final AdminController c) { super("JORAM Administration Tool"); this.c = c; ConnectAdminDialog.initialize(this); ConnectJndiDialog.initialize(this); CreateFactoryDialog.initialize(this); CreateUserDialog.initialize(this); CreateDestinationDialog.initialize(this); CreateServerDialog.initialize(this); CreateDomainDialog.initialize(this); jndiConnectAction = new JndiConnectAction(); jndiDisconnectAction = new JndiDisconnectAction(); jndiDisconnectAction.setEnabled(false); jndiRefreshAction = new JndiRefreshAction(); jndiRefreshAction.setEnabled(false); jndiCreateFactoryAction = new JndiCreateFactoryAction(); jndiCreateFactoryAction.setEnabled(false); adminConnectAction = new AdminConnectAction(); adminDisconnectAction = new AdminDisconnectAction(); adminDisconnectAction.setEnabled(false); adminRefreshAction = new AdminRefreshAction(); adminRefreshAction.setEnabled(false); exitAction = new ExitAction(); // Build the configuration tree configTree = new JTree(c.getAdminTreeModel()); configTree.expandRow(0); configTree.setScrollsOnExpand(true); configTree.setCellRenderer(new ConfigTreeCellRenderer()); final TreeSelectionModel configTsm = new DefaultTreeSelectionModel(); configTsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); configTree.setSelectionModel(configTsm); // Build the JNDI tree jndiTree = new JTree(c.getJndiTreeModel()); jndiTree.expandRow(0); jndiTree.setScrollsOnExpand(true); jndiTree.setCellRenderer(new ConfigTreeCellRenderer()); final TreeSelectionModel jndiTsm = new DefaultTreeSelectionModel(); jndiTsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jndiTree.setSelectionModel(jndiTsm); tabbedPane = new JTabbedPane(); tabbedPane.add("Configuration", new JScrollPane(configTree)); tabbedPane.add("JNDI", new JScrollPane(jndiTree)); JPanel statusPanel = new JPanel(); statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); JLabel statusTitle = new JLabel("Admin connection: "); statusPanel.add(statusTitle); connStatus = new JLabel("Not connected"); connStatus.setForeground(AdminToolConstants.COLOR_DISCONNECTED); statusPanel.add(connStatus); statusPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); msgPane = new JEditorPane("text/html", ""); msgPane.setEditable(false); serverPanel = new ServerPanel(c); userPanel = new UserPanel(c); destPanel = new DestinationPanel(c); subscriptionPanel = new SubscriptionPanel(c); messagePanel = new MessagePanel(); editPanel = new JPanel(new CardLayout()); editPanel.add(msgPane, "html"); editPanel.add(serverPanel, "server"); editPanel.add(userPanel, "user"); editPanel.add(destPanel, "destination"); editPanel.add(subscriptionPanel, "subscription"); editPanel.add(messagePanel, "message"); Component rightPane = new JScrollPane(editPanel); JPanel rightPanel = new JPanel(new BorderLayout()); rightPanel.add(statusPanel, BorderLayout.NORTH); rightPanel.add(rightPane, BorderLayout.CENTER); splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tabbedPane, rightPanel); getContentPane().add(splitter, BorderLayout.CENTER); setJMenuBar(buildMenuBar()); // whenever the tree model gets a new node, we expand the // view so the user can see the new node. c.getAdminTreeModel().addTreeModelListener(new TreeModelListener() { public void treeNodesRemoved(TreeModelEvent e) {} public void treeNodesChanged(TreeModelEvent e) {} public void treeStructureChanged(final TreeModelEvent e) {} public void treeNodesInserted(final TreeModelEvent e) { // make sure the new node is visible. SwingUtilities.invokeLater(new Runnable() { public void run() { configTree.expandPath(e.getTreePath()); } }); } }); c.getJndiTreeModel().addTreeModelListener(new TreeModelListener() { public void treeNodesRemoved(TreeModelEvent e) {} public void treeNodesChanged(TreeModelEvent e) {} public void treeStructureChanged(final TreeModelEvent e) {} public void treeNodesInserted(final TreeModelEvent e) { // make sure the new node is visible. SwingUtilities.invokeLater(new Runnable() { public void run() { jndiTree.expandPath(e.getTreePath()); } }); } }); // when you select something in the tree, // the controller's populateList method is called to // fill the list with messages from the given node. configTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(javax.swing.event.TreeSelectionEvent e) { if (Log.logger.isLoggable(BasicLevel.DEBUG)) Log.logger.log(BasicLevel.DEBUG, "TreeSelectionListener[configTree].valueChanged(" + e + ')'); if (!configTsm.isSelectionEmpty()) { TreeNode selection = (TreeNode) configTsm.getSelectionPath().getLastPathComponent(); updateMessagePaneFromNode(selection); } } }); jndiTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(javax.swing.event.TreeSelectionEvent e) { if (Log.logger.isLoggable(BasicLevel.DEBUG)) Log.logger.log(BasicLevel.DEBUG, "TreeSelectionListener[jndiTree].valueChanged(" + e + ')'); if (!jndiTsm.isSelectionEmpty()) { TreeNode selection = (TreeNode) jndiTsm.getSelectionPath().getLastPathComponent(); updateMessagePaneFromNode(selection); } } }); // add popup menu listener MouseListener popupListener = new PopupListener(); configTree.addMouseListener(popupListener); jndiTree.addMouseListener(popupListener); } private void displayError(String errorMsg) { if (Log.logger.isLoggable(BasicLevel.DEBUG)) Log.logger.log(BasicLevel.DEBUG, "AdminTool.displayError(" + errorMsg + ')'); msgPane.setText("<font face=Arial><br><br><br><br><br><center><b>" + errorMsg + "</b></center></font>"); ((CardLayout) editPanel.getLayout()).show(editPanel, "html"); } private JMenuBar buildMenuBar() { JMenuBar menuBar = new JMenuBar(); // Configuration menu JMenu adminMenu = new JMenu("Admin"); adminMenu.add(adminConnectAction); adminMenu.add(adminDisconnectAction); adminMenu.addSeparator(); adminMenu.add(adminRefreshAction); adminMenu.addSeparator(); adminMenu.add(exitAction); // JNDI menu JMenu jndiMenu = new JMenu("JNDI"); jndiMenu.add(jndiConnectAction); jndiMenu.add(jndiDisconnectAction); jndiMenu.addSeparator(); jndiMenu.add(jndiRefreshAction); jndiMenu.addSeparator(); jndiMenu.add(jndiCreateFactoryAction); // add menus menuBar.add(adminMenu); menuBar.add(jndiMenu); return menuBar; } public void adminControllerEvent(ControllerEvent e) { int id = e.getId(); if (id == ControllerEvent.ADMIN_CONNECTED) { connStatus.setText(c.getAdminConnectionStatus()); connStatus.setForeground(AdminToolConstants.COLOR_CONNECTED); } else if (id == ControllerEvent.ADMIN_DISCONNECTED) { connStatus.setText(c.getAdminConnectionStatus()); connStatus.setForeground(AdminToolConstants.COLOR_DISCONNECTED); } } // class AdminCommandCaller implements Runnable {// private TreeNode selection;// private AdminCommandDialog dlg;// public AdminCommandCaller(TreeNode selection,// AdminCommandDialog dlg) {// this.selection = selection;// this.dlg = dlg;// }// public void run() {// deferredMessagePaneUpdate(selection);// dlg.close();// }// } private void updateMessagePaneFromNode(final TreeNode selection) { if (Log.logger.isLoggable(BasicLevel.DEBUG)) Log.logger.log(BasicLevel.DEBUG, "AdminTool.updateMessagePaneFromNode(" + selection + ')'); if (selection instanceof AdminTreeNode) { invokeLater(new CommandWorker() { public void run() { deferredMessagePaneUpdate(selection); } }); } else if (selection instanceof AdminTreeNode) { msgPane.setText(((AdminTreeNode) selection).getDescription()); ((CardLayout) editPanel.getLayout()).show(editPanel, "html"); } else { msgPane.setText(""); ((CardLayout) editPanel.getLayout()).show(editPanel, "html"); } } public static void invokeLater(final CommandWorker worker) { final AdminCommandDialog dlg = new AdminCommandDialog( getInstance(), getInstance().c); new Thread(new Runnable() { public void run() { try { worker.run(); dlg.close(); } catch (Exception exc) { if (Log.logger.isLoggable(BasicLevel.ERROR)) Log.logger.log(BasicLevel.ERROR, "", exc); dlg.close(); JOptionPane.showMessageDialog(AdminTool.getInstance(), exc.getMessage()); } } }).start(); dlg.showDialog(); } void updateSubscriptions(User user, MutableTreeNode subRoot) throws ConnectException, AdminException { Subscription[] subscriptions = user.getSubscriptions(); for (int i = 0; i < subscriptions.length; i++) { SubscriptionTreeNode subNode = new SubscriptionTreeNode( c, subscriptions[i]); c.getAdminTreeModel().insertNodeInto( subNode, subRoot, subRoot.getChildCount()); } } private void deferredMessagePaneUpdate(TreeNode selection) { if (Log.logger.isLoggable(BasicLevel.DEBUG)) Log.logger.log(BasicLevel.DEBUG, "AdminTool.deferredMessagepaneUpdate(" + selection + ')'); try { if (selection instanceof ServerTreeNode) { ServerTreeNode stn = (ServerTreeNode) selection; serverPanel.setServerId(stn.getServerId()); int threshold = c.getDefaultThreshold(stn.getServerId()); serverPanel.setDefaultThreshold((threshold < 0 ? "" : Integer.toString(threshold))); serverPanel.setDMQList(stn.getDeadMessageQueues(), c.getDefaultDMQ(stn.getServerId())); ((CardLayout) editPanel.getLayout()).show(editPanel, "server"); try { if (stn.getDestinationRoot().getChildCount() == 0) { // Means that the destinations may not have been initialized c.updateDestinations(stn.getServerId(), stn.getDestinationRoot()); } if (stn.getUserRoot().getChildCount() == 0) { // Means that the users may not have been initialized c.updateUsers(stn.getServerId(), stn.getUserRoot()); } } catch (AdminException exc) { if (Log.logger.isLoggable(BasicLevel.WARN)) Log.logger.log(BasicLevel.WARN, "", exc); } catch (ConnectException ce) { if (Log.logger.isLoggable(BasicLevel.WARN)) Log.logger.log(BasicLevel.WARN, "", ce); } } else if (selection instanceof UserTreeNode) { UserTreeNode utn = (UserTreeNode) selection; userPanel.setUser(utn.getUser()); int threshold = c.getUserThreshold(utn.getUser()); userPanel.setThreshold((threshold < 0 ? "" : Integer.toString(threshold))); userPanel.setDMQList(utn.getParentServerTreeNode().getDeadMessageQueues(), c.getUserDMQ(utn.getUser())); ((CardLayout) editPanel.getLayout()).show(editPanel, "user"); } else if (selection instanceof DestinationTreeNode) { DestinationTreeNode dtn = (DestinationTreeNode) selection; destPanel.setDestination(dtn.getDestination()); int threshold = -1; try { Queue q = (Queue) dtn.getDestination(); threshold = c.getQueueThreshold(q); destPanel.setThresholdActive(true); destPanel.setPendingMessages(c.getPendingMessages(q)); destPanel.setPendingRequests(c.getPendingRequests(q)); } catch (ClassCastException cce) { destPanel.setThresholdActive(false); destPanel.setPendingMessages(-1); destPanel.setPendingRequests(-1); } finally { destPanel.setThreshold((threshold < 0 ? "" : Integer.toString(threshold))); } destPanel.setDMQList(dtn.getParentServerTreeNode().getDeadMessageQueues(), c.getDestinationDMQ(dtn.getDestination())); destPanel.setFreeReading(c.isFreelyReadable(dtn.getDestination())); destPanel.setFreeWriting(c.isFreelyWritable(dtn.getDestination())); java.util.List users = dtn.getParentServerTreeNode().getUsers(); destPanel.setReadingACL(users, c.getAuthorizedReaders(dtn.getDestination())); destPanel.setWritingACL(users, c.getAuthorizedWriters(dtn.getDestination()));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -