KickJava   Java API By Example, From Geeks To Geeks.

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


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 MessageTreeNode extends DefaultMutableTreeNode
31     implements AdminTreeNode {
32
33   private AdminController c;
34
35   private String JavaDoc msgId;
36   
37   public MessageTreeNode(AdminController c,
38                          String JavaDoc msgId) {
39     super(msgId);
40     this.c = c;
41     this.msgId = msgId;
42   }
43
44   /**
45    * Returns descriptive text about the node.
46    */

47   public String JavaDoc getDescription() {
48     return "";
49   }
50   
51   /**
52    * Gets the image icon for this node, or null to use
53    * the default.
54    */

55   public ImageIcon getImageIcon() {
56     return null;
57   }
58   
59   /**
60    * Refreshes the node.
61    * @param treeModel the model that the node is contained in.
62    */

63   public void refresh(DefaultTreeModel treeModel) {
64     
65   }
66
67   public JPopupMenu getContextMenu() {
68     JPopupMenu popup = new JPopupMenu("Message");
69     
70     DeleteMessageAction dma = new DeleteMessageAction();
71     if (! c.isAdminConnected())
72       dma.setEnabled(false);
73     popup.add(new JMenuItem(dma));
74     
75     return popup;
76   }
77
78   public final String JavaDoc getMessageId() {
79     return msgId;
80   }
81
82   public boolean getAllowsChildren() {
83     return false;
84   }
85
86   private class DeleteMessageAction extends AbstractAction {
87
88     public DeleteMessageAction() {
89       super("Delete", AdminToolConstants.trashIcon);
90     }
91
92     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
93       try {
94         Object JavaDoc[] options = { "OK", "CANCEL" };
95         int res = JOptionPane.showOptionDialog(
96           AdminTool.getInstance(),
97           "You are about to permanently remove this message " +
98           "from this subscription. Please click OK to proceed.",
99           "Warning", JOptionPane.DEFAULT_OPTION,
100           JOptionPane.WARNING_MESSAGE, null, options, options[0]);
101         if (res == 0)
102           c.deleteMessage(MessageTreeNode.this);
103       } catch (Exception JavaDoc x) {
104         x.printStackTrace();
105         JOptionPane.showMessageDialog(null, x.getMessage());
106       }
107     }
108   }
109 }
110
Popular Tags