1 package com.ubermq.jms.ui.admin; 2 3 import com.ubermq.jms.server.admin.*; 4 import java.awt.*; 5 import java.util.*; 6 import javax.swing.*; 7 import javax.swing.tree.*; 8 9 class ConnectionTreeNode 10 extends DefaultMutableTreeNode 11 implements AdminTreeNode 12 { 13 private ConnectionAdmin conn; 14 15 private static final String CONNECTION_PROBLEMS = "Connection unavailable."; 16 17 ConnectionTreeNode(ConnectionAdmin conn) 18 throws java.rmi.RemoteException 19 { 20 super(conn.getName(), false); 21 this.conn = conn; 22 } 23 24 ConnectionAdmin getAdmin() 25 { 26 return conn; 27 } 28 29 public void refresh(DefaultTreeModel dtm) 30 { 31 } 32 33 public String getDescription() 34 { 35 try 36 { 37 StringBuffer sb = new StringBuffer (); 38 sb.append("<h2>Connection "); 39 sb.append(conn.getName()); 40 sb.append("</h2><p>"); 41 42 sb.append("<i>Registered Subscriptions</i><br>"); 43 Iterator iter = conn.getSubscriptions().iterator(); 44 while (iter.hasNext()) 45 { 46 Object element = iter.next(); 47 sb.append("<tt>"); 48 sb.append(element); 49 sb.append("</tt><br>"); 50 } 51 52 return sb.toString(); 53 } 54 catch (java.rmi.RemoteException e) { 55 return CONNECTION_PROBLEMS; 56 } 57 } 58 59 public JPopupMenu getContextMenu() 60 { 61 JPopupMenu popup = new JPopupMenu("Connection"); 63 popup.add(new JMenuItem(new CloseConnectionAction())); 64 popup.addSeparator(); 65 popup.add(new JMenuItem(new EnableConnectionAction())); 66 popup.add(new JMenuItem(new DisableConnectionAction())); 67 return popup; 68 } 69 70 73 public ImageIcon getImageIcon() 74 { 75 try 76 { 77 return conn.isActive() ? AdminViewer.socketIcon : AdminViewer.deleteIcon; 78 } 79 catch (java.rmi.RemoteException e) { 80 return AdminViewer.deleteIcon; 81 } 82 } 83 84 private class CloseConnectionAction 85 extends AbstractAction 86 { 87 public CloseConnectionAction() {super("Close Connection", AdminViewer.stopIcon);} 88 public void actionPerformed(java.awt.event.ActionEvent e) 89 { 90 try 91 { 92 conn.close(); 93 } 94 catch (java.rmi.RemoteException x) { 95 JOptionPane.showMessageDialog(null, x.getMessage()); 96 } 97 } 98 } 99 100 private class EnableConnectionAction 101 extends AbstractAction 102 { 103 public EnableConnectionAction() {super("Enable", AdminViewer.okIcon);} 104 public void actionPerformed(java.awt.event.ActionEvent e) 105 { 106 try 107 { 108 conn.start(); 109 } 110 catch (java.rmi.RemoteException x) { 111 JOptionPane.showMessageDialog(null, x.getMessage()); 112 } 113 } 114 115 public boolean isEnabled() 116 { 117 try 118 { 119 boolean f = !conn.isActive(); 120 return f; 121 } 122 catch (java.rmi.RemoteException e) { 123 return false; 124 } 125 } 126 } 127 128 private class DisableConnectionAction 129 extends AbstractAction 130 { 131 public DisableConnectionAction() {super("Disable", AdminViewer.deleteIcon);} 132 public void actionPerformed(java.awt.event.ActionEvent e) 133 { 134 try 135 { 136 conn.stop(); 137 } 138 catch (java.rmi.RemoteException x) { 139 JOptionPane.showMessageDialog(null, x.getMessage()); 140 } 141 } 142 143 public boolean isEnabled() 144 { 145 try 146 { 147 return conn.isActive(); 148 } 149 catch (java.rmi.RemoteException e) { 150 return false; 151 } 152 } 153 } 154 155 } 156 | Popular Tags |