1 48 49 50 package org.exolab.jms.tools.admin; 51 52 import java.awt.event.ActionEvent ; 53 import java.awt.event.ActionListener ; 54 import java.util.Enumeration ; 55 56 import javax.swing.JMenuItem ; 57 import javax.swing.JOptionPane ; 58 import javax.swing.JPopupMenu ; 59 import javax.swing.JTree ; 60 61 62 69 public class OpenJMSTopic extends OpenJMSObject { 70 71 78 public OpenJMSTopic(String topic, JTree tree) { 79 super(topic, tree); 80 } 81 82 protected void createCommands() { 84 _commands = new JPopupMenu (); 85 JMenuItem m = new JMenuItem ("Add Consumer"); 86 m.addActionListener(new ActionListener () { 87 88 public void actionPerformed(ActionEvent evt) { 89 addConsumer(); 90 } 91 } 92 ); 93 _commands.add(m); 94 95 m = new JMenuItem ("Delete Topic"); 96 m.addActionListener(new ActionListener () { 97 98 public void actionPerformed(ActionEvent evt) { 99 deleteTopic(); 100 } 101 } 102 ); 103 _commands.add(m); 104 } 105 106 111 static private void editTopic() { 112 OpenJMSTopic This = (OpenJMSTopic) getInstanceSelected(); 113 System.out.println("editTopic"); 114 } 115 116 124 public void update() { 125 if (!_isExplored) { 126 Enumeration e = AbstractAdminConnection.instance().getDurableConsumers( 127 _name); 128 129 if (e != null) { 130 while (e.hasMoreElements()) { 131 String consumer = (String ) e.nextElement(); 132 add(new OpenJMSConsumer(consumer, _tree)); 133 } 134 refresh(); 135 } 136 137 _isExplored = true; 138 } 139 } 140 141 148 static private void addConsumer() { 149 150 OpenJMSTopic This = (OpenJMSTopic) getInstanceSelected(); 151 CreateTopicDialog.instance().displayCreateConsumer(); 152 if (CreateTopicDialog.instance().isConfirmed()) { 153 boolean err = false; 154 String errMessage = null; 155 156 if (!This._isExplored) { 157 This.update(); 158 } 159 160 if (!AbstractAdminConnection.instance().durableConsumerExists( 164 CreateTopicDialog.instance().getName())) { 165 if (AbstractAdminConnection.instance().addDurableConsumer( 166 This._name, CreateTopicDialog.instance().getName())) { 167 This.add(new OpenJMSConsumer 168 (CreateTopicDialog.instance().getName(), _tree)); 169 This.refresh(); 170 } else { 171 err = true; 172 errMessage = "Failed to update database"; 173 } 174 } else { 175 err = true; 176 errMessage = "Consumer already exists"; 177 } 178 if (err) { 179 JOptionPane.showMessageDialog 180 (_tree, errMessage, "Create Consumer Error", 181 JOptionPane.ERROR_MESSAGE); 182 } 183 } 184 } 185 186 196 static private void deleteTopic() { 197 OpenJMSTopic This = (OpenJMSTopic) getInstanceSelected(); 198 QueryDialog.instance().display( 199 "Are you sure you want to delete \nselected Topic: " 200 + This._name); 201 if (org.exolab.jms.tools.admin.QueryDialog.instance().isConfirmed()) { 202 if (AbstractAdminConnection.instance().removeDestination( 203 This._name)) { 204 This.removeFromParent(); 205 This.refresh(); 206 } else { 207 JOptionPane.showMessageDialog 208 (_tree, "Failed to destroy Topic", 209 "Destroy Topic Error", JOptionPane.ERROR_MESSAGE); 210 } 211 } 212 } 213 } 214 | Popular Tags |