KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > tools > admin > SubscriptionTreeNode


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  *
19  * Initial developer(s): ScalAgent DT
20  * Contributor(s):
21  */

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 JavaDoc 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   /**
56    * Returns descriptive text about the node.
57    */

58   public String JavaDoc getDescription() {
59     return "";
60   }
61   
62   /**
63    * Returns a context menu for the node, or null if
64    * no context menu should be created.
65    */

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   /**
78    * Gets the image icon for this node, or null to use
79    * the default.
80    */

81   public ImageIcon getImageIcon() {
82     return null;
83   }
84   
85   /**
86    * Refreshes the node.
87    * @param treeModel the model that the node is contained in.
88    */

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 JavaDoc e) {
105       try {
106         Object JavaDoc[] 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 JavaDoc x) {
116         x.printStackTrace();
117         JOptionPane.showMessageDialog(null, x.getMessage());
118       }
119     }
120   }
121 }
122
Popular Tags