1 22 package org.objectweb.joram.client.tools.admin; 23 24 import java.util.*; 25 import javax.swing.*; 26 import javax.swing.tree.*; 27 28 import org.objectweb.joram.client.jms.admin.*; 29 30 class SubscriptionTreeNode extends DefaultMutableTreeNode 31 implements AdminTreeNode { 32 private AdminController c; 33 34 private Subscription sub; 35 36 public SubscriptionTreeNode(AdminController c, 37 Subscription sub) { 38 this.c = c; 39 this.sub = sub; 40 setNodeTitle(); 41 } 42 43 private void setNodeTitle() { 44 String title = 45 sub.getName() + " (" + 46 sub.getTopicId() + ", " + 47 sub.getMessageCount(); 48 if (sub.isDurable()) { 49 title = title + ", durable"; 50 } 51 title = title + ')'; 52 setUserObject(title); 53 } 54 55 58 public String getDescription() { 59 return ""; 60 } 61 62 66 public JPopupMenu getContextMenu() { 67 JPopupMenu popup = new JPopupMenu("Subscription"); 68 69 ClearSubscriptionAction csa = new ClearSubscriptionAction(); 70 if (! c.isAdminConnected()) 71 csa.setEnabled(false); 72 popup.add(new JMenuItem(csa)); 73 74 return popup; 75 } 76 77 81 public ImageIcon getImageIcon() { 82 return null; 83 } 84 85 89 public void refresh(DefaultTreeModel treeModel) { 90 91 } 92 93 public final Subscription getSubscription() { 94 return sub; 95 } 96 97 98 private class ClearSubscriptionAction extends AbstractAction { 99 100 public ClearSubscriptionAction() { 101 super("Clear", AdminToolConstants.trashIcon); 102 } 103 104 public void actionPerformed(java.awt.event.ActionEvent e) { 105 try { 106 Object [] options = { "OK", "CANCEL" }; 107 int res = JOptionPane.showOptionDialog( 108 AdminTool.getInstance(), 109 "You are about to permanently remove all the messages " + 110 "from this subscription. Please click OK to proceed.", 111 "Warning", JOptionPane.DEFAULT_OPTION, 112 JOptionPane.WARNING_MESSAGE, null, options, options[0]); 113 if (res == 0) 114 c.clearSubscription(SubscriptionTreeNode.this); 115 } catch (Exception x) { 116 x.printStackTrace(); 117 JOptionPane.showMessageDialog(null, x.getMessage()); 118 } 119 } 120 } 121 } 122 | Popular Tags |