1 48 49 50 package org.exolab.jms.tools.admin; 51 52 import java.awt.Rectangle ; 53 import java.awt.event.ActionEvent ; 54 import java.awt.event.ActionListener ; 55 import java.util.Enumeration ; 56 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 import org.exolab.jms.client.JmsDestination; 65 import org.exolab.jms.client.JmsQueue; 66 import org.exolab.jms.client.JmsTopic; 67 68 69 79 public class OpenJMSServer extends DefaultMutableTreeNode { 80 81 private String serverName_; 83 84 static private JTree tree_ = null; 86 87 static private boolean commandsCreated_ = false; 89 90 static private JPopupMenu commands_ = null; 92 93 101 public OpenJMSServer(String serverName, JTree tree) { 102 serverName_ = serverName; 103 104 if (!commandsCreated_) { 105 tree_ = tree; 106 107 112 createCommands(); 113 commandsCreated_ = true; 114 } 115 } 116 117 124 protected void createCommands() { 125 commands_ = new JPopupMenu (); 126 JMenuItem m = new JMenuItem ("Add Queue"); 127 m.addActionListener(new ActionListener () { 128 129 public void actionPerformed(ActionEvent evt) { 130 addQueue(); 131 } 132 } 133 ); 134 commands_.add(m); 135 136 m = new JMenuItem ("Add Topic"); 137 m.addActionListener(new ActionListener () { 138 139 public void actionPerformed(ActionEvent evt) { 140 addTopic(); 141 } 142 } 143 ); 144 commands_.add(m); 145 146 m = new JMenuItem ("Add User"); 147 m.addActionListener(new ActionListener () { 148 149 public void actionPerformed(ActionEvent evt) { 150 addUser(); 151 } 152 } 153 ); 154 commands_.add(m); 155 156 m = new JMenuItem ("Purge Messages"); 157 m.addActionListener(new ActionListener () { 158 159 public void actionPerformed(ActionEvent evt) { 160 purgeMessages(); 161 } 162 } 163 ); 164 commands_.add(m); 165 } 166 167 174 static public DefaultTreeModel createServerList(JTree tree) { 175 OpenJMSServer server = new OpenJMSServer("OpenJMSServer", tree); 178 return new DefaultTreeModel (server); 179 } 180 181 186 public void displayConnections() { 187 Enumeration e = AbstractAdminConnection.instance().getAllDestinations(); 188 if (e != null) { 189 while (e.hasMoreElements()) { 190 JmsDestination destination = (JmsDestination) e.nextElement(); 191 if (destination instanceof JmsQueue) { 192 add(new OpenJMSQueue(destination.getName(), tree_)); 193 } else if (destination instanceof JmsTopic) { 194 add(new OpenJMSTopic(destination.getName(), tree_)); 195 } 196 } 197 } 198 e = AbstractAdminConnection.instance().getAllUsers(); 200 if (e != null) { 201 while (e.hasMoreElements()) { 202 add(new OpenJMSUser(e.nextElement().toString(), tree_)); 203 } 204 } 205 refresh(); 206 } 207 208 214 public boolean getAllowsChildren() { 215 return true; 216 } 217 218 226 public void displayCommands(Rectangle loc) { 227 double x; 228 double y; 229 230 x = loc.getX(); 231 y = loc.getY(); 232 y += loc.getHeight(); 233 234 commands_.show(tree_, (int) x, (int) y); 235 } 236 237 243 public String toString() { 244 return serverName_; 245 } 246 247 252 public void refresh() { 253 DefaultTreeModel model = (DefaultTreeModel ) tree_.getModel(); 254 model.nodeStructureChanged((DefaultMutableTreeNode ) this); 255 } 256 257 263 static private OpenJMSServer getInstanceSelected() { 264 Object loc = tree_.getLastSelectedPathComponent(); 265 return (OpenJMSServer) loc; 266 } 267 268 274 static private void addQueue() { 275 OpenJMSServer This = getInstanceSelected(); 276 CreateQueueDialog.instance().displayCreateQueue(); 277 278 if (CreateQueueDialog.instance().isConfirmed()) { 279 if (AbstractAdminConnection.instance().addDestination( 280 CreateQueueDialog.instance().getName(), true)) { 281 282 This.add(new OpenJMSQueue( 283 CreateQueueDialog.instance().getName(), tree_)); 284 This.refresh(); 285 } else { 286 JOptionPane.showMessageDialog 287 (tree_, "Queue already exists", "Create Error", 288 JOptionPane.ERROR_MESSAGE); 289 } 290 } 291 } 292 293 299 static private void addUser() { 300 OpenJMSServer This = getInstanceSelected(); 301 CreateUserDialog.instance().displayCreateUser(); 302 303 if (CreateUserDialog.instance().isConfirmed()) { 304 if (AbstractAdminConnection.instance().addUser( 305 CreateUserDialog.instance().getName(), 306 CreateUserDialog.instance().getPassword())) { 307 308 This.add(new OpenJMSUser( 309 CreateUserDialog.instance().getName(), tree_)); 310 This.refresh(); 311 } else { 312 JOptionPane.showMessageDialog 313 (tree_, "User already exists", "Create Error", 314 JOptionPane.ERROR_MESSAGE); 315 } 316 } 317 } 318 319 325 static private void addTopic() { 326 OpenJMSServer This = getInstanceSelected(); 327 CreateTopicDialog.instance().displayCreateTopic(); 328 329 if (CreateTopicDialog.instance().isConfirmed()) { 330 if (AbstractAdminConnection.instance().addDestination( 331 CreateTopicDialog.instance().getName(), false)) { 332 333 This.add(new OpenJMSTopic( 334 CreateTopicDialog.instance().getName(), tree_)); 335 This.refresh(); 336 } else { 337 JOptionPane.showMessageDialog 338 (tree_, "Topic already exists", "Create Error", 339 JOptionPane.ERROR_MESSAGE); 340 } 341 } 342 } 343 344 347 static private void purgeMessages() { 348 QueryDialog.instance().display 349 ("Are you sure you want to purge all\n processed messages."); 350 if (org.exolab.jms.tools.admin.QueryDialog.instance().isConfirmed()) { 351 int count = AbstractAdminConnection.instance().purgeMessages(); 352 JOptionPane.showMessageDialog 353 (tree_, count + " messages were purged.", "Info", 354 JOptionPane.ERROR_MESSAGE); 355 } else { 356 JOptionPane.showMessageDialog 357 (tree_, "Purge Messages Aborted.", "Purge Error", 358 JOptionPane.ERROR_MESSAGE); 359 } 360 } 361 } | Popular Tags |