1 48 49 package org.exolab.jms.tools.admin; 50 51 import java.awt.Rectangle ; 52 import java.awt.event.ActionEvent ; 53 import java.awt.event.ActionListener ; 54 55 import javax.swing.JMenuItem ; 56 import javax.swing.JOptionPane ; 57 import javax.swing.JPopupMenu ; 58 import javax.swing.JTree ; 59 import javax.swing.tree.DefaultMutableTreeNode ; 60 import javax.swing.tree.DefaultTreeModel ; 61 62 63 76 public class OpenJMSConsumer extends DefaultMutableTreeNode 77 implements OpenJMSNode { 78 79 private String consumerName_; 81 82 static private JTree tree_ = null; 84 85 static private boolean commandsCreated_ = false; 87 88 static private JPopupMenu commands_ = null; 90 91 102 public OpenJMSConsumer(String consumerName, JTree tree) { 103 consumerName_ = consumerName; 104 if (!commandsCreated_) { 105 tree_ = tree; 106 createCommands(); 107 commandsCreated_ = true; 108 } 109 } 110 111 118 protected void createCommands() { 119 commands_ = new JPopupMenu (); 120 121 JMenuItem m = new JMenuItem ("De-Activate Consumer"); 122 m.addActionListener(new ActionListener () { 123 124 public void actionPerformed(ActionEvent evt) { 125 unregisterConsumer(); 126 } 127 } 128 ); 129 commands_.add(m); 130 131 m = new JMenuItem ("Delete Consumer"); 132 m.addActionListener(new ActionListener () { 133 134 public void actionPerformed(ActionEvent evt) { 135 deleteConsumer(); 136 } 137 } 138 ); 139 commands_.add(m); 140 } 141 142 143 149 public boolean getAllowsChildren() { 150 return false; 151 } 152 153 154 160 public boolean isLeaf() { 161 return true; 162 } 163 164 165 170 public void update() { 171 } 173 174 182 public void displayCommands(Rectangle loc) { 183 double x; 184 double y; 185 186 x = loc.getX(); 187 y = loc.getY(); 188 y += loc.getHeight(); 189 190 commands_.show(tree_, (int) x, (int) y); 191 } 192 193 194 200 public String toString() { 201 return consumerName_; 202 } 203 204 209 private void refresh() { 210 DefaultTreeModel model = (DefaultTreeModel ) tree_.getModel(); 211 model.nodeStructureChanged((DefaultMutableTreeNode ) this); 212 } 213 214 220 static private OpenJMSConsumer getInstanceSelected() { 221 Object loc = tree_.getLastSelectedPathComponent(); 222 return (OpenJMSConsumer) loc; 223 } 224 225 226 231 static private void editConsumer() { 232 OpenJMSConsumer This = getInstanceSelected(); 233 System.out.println("editConsumer"); 234 } 235 236 243 static private void deleteConsumer() { 244 OpenJMSConsumer This = getInstanceSelected(); 245 QueryDialog.instance().display 246 ("Are you sure you want to delete \nselected Consumer: " 247 + This.consumerName_); 248 if (org.exolab.jms.tools.admin.QueryDialog.instance().isConfirmed()) { 249 OpenJMSTopic topic = (OpenJMSTopic) This.parent; 250 251 if (AbstractAdminConnection.instance().removeDurableConsumer(This.consumerName_)) { 252 This.removeFromParent(); 253 This.refresh(); 254 } else { 255 JOptionPane.showMessageDialog 256 (tree_, "Failed to remove Consumer", 257 "Remove Consumer Error", JOptionPane.ERROR_MESSAGE); 258 } 259 } 260 } 261 262 263 270 static private void unregisterConsumer() { 271 OpenJMSConsumer This = getInstanceSelected(); 272 org.exolab.jms.tools.admin.QueryDialog.instance().display 273 ("Are you sure you want to De-Activate \nselected Consumer: " 274 + This.consumerName_); 275 if (org.exolab.jms.tools.admin.QueryDialog.instance().isConfirmed()) { 276 OpenJMSTopic topic = (OpenJMSTopic) This.parent; 277 278 if (!AbstractAdminConnection.instance().unregisterConsumer(This.consumerName_)) { 279 JOptionPane.showMessageDialog 280 (tree_, "Consumer is not currently active", 281 "De-Activate Consumer Error", JOptionPane.ERROR_MESSAGE); 282 } 283 } 284 } 285 286 } | Popular Tags |