KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > tools > admin > OpenJMSObject


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2001,2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: OpenJMSObject.java,v 1.1 2004/11/26 01:51:15 tanderson Exp $ *
44  */

45 package org.exolab.jms.tools.admin;
46
47 import java.awt.Rectangle JavaDoc;
48 import java.text.SimpleDateFormat JavaDoc;
49
50 import javax.swing.JPopupMenu JavaDoc;
51 import javax.swing.JTree JavaDoc;
52 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
53 import javax.swing.tree.DefaultTreeModel JavaDoc;
54
55
56 /**
57  * This is the base class for all nodes.
58  *
59  * @version $Revision: 1.1 $ $Date: 2004/11/26 01:51:15 $
60  * @author <a HREF="mailto:mourikis@exolab.org">Jim Mourikis</a>
61  * @see OpenJMSConsumer
62  * @see AdminMgr
63  */

64 public abstract class OpenJMSObject extends DefaultMutableTreeNode JavaDoc
65     implements OpenJMSNode {
66
67     // The name
68
protected String JavaDoc _name;
69
70     // Does this queue topic have any registered consumers
71
protected boolean _isLeaf;
72
73     // Whether this node has been opened and explored already.
74
protected boolean _isExplored = false;
75
76     // The popup menu for destination
77
protected JPopupMenu JavaDoc _commands = null;
78
79     // A flag indicating if the menu has been created yet.
80
protected boolean _commandsCreated = false;
81
82     // A date time formatter.
83
static protected SimpleDateFormat JavaDoc _dateFormat;
84
85     // A reference to the tree this node belongs to.
86
static protected JTree JavaDoc _tree = null;
87
88
89     /**
90      * The constructor gets its unique name for this object and a
91      * reference to its parent tree.
92      *
93      * <P>If this is the first call, the menu for all objects
94      * is created.
95      *
96      * @param name This object name.
97      * @param tree The parent tree this object belongs to.
98      *
99      */

100     public OpenJMSObject(String JavaDoc destinationName, JTree JavaDoc tree) {
101         _name = destinationName;
102         _isLeaf = false;
103         if (!_commandsCreated) {
104             _tree = tree;
105             createCommands();
106             _commandsCreated = true;
107             _dateFormat = new SimpleDateFormat JavaDoc("dd/MM/yyyy HH:mm:ss");
108             _dateFormat.setLenient(false);
109         }
110     }
111
112
113     /**
114      * Create the menu for all objects and set up the Action events for
115      * each menu item. Since menus are shared, the callbacks called are
116      * static. Once a menu is slected, the slected node can be determined
117      * from the parent object.
118      *
119      */

120     abstract protected void createCommands();
121
122     /**
123      * Children are allowed for all objects
124      *
125      * @return boolean Always returns true.
126      */

127     public boolean getAllowsChildren() {
128         return true;
129     }
130
131     /**
132      * Objects are leaves iff they have nothing registered against
133      * them.
134      *
135      * @return boolean true if no objects are registered.
136      */

137     public boolean isLeaf() {
138         return _isLeaf;
139     }
140
141     /**
142      * This node has been right clicked. The locations of this node is given
143      * by the loc object. Use this location to popup the object message
144      * menu.
145      *
146      * @param The location of this Consumer node.
147      */

148     public void displayCommands(Rectangle JavaDoc loc) {
149         double x;
150         double y;
151
152         x = loc.getX();
153         y = loc.getY();
154         y += loc.getHeight();
155
156         _commands.show(_tree, (int) x, (int) y);
157     }
158
159     /**
160      * The unique name of this object.
161      *
162      * @return String the object name.
163      */

164     public String JavaDoc toString() {
165         return _name;
166     }
167
168     /**
169      * This node has changed. Inform the parent tree that it needs to be
170      * re-drawn.
171      */

172     protected void refresh() {
173         DefaultTreeModel JavaDoc model = (DefaultTreeModel JavaDoc) _tree.getModel();
174         model.nodeStructureChanged((DefaultMutableTreeNode JavaDoc) this);
175     }
176
177     /**
178      * Get the particular instance of the object that has been selected.
179      *
180      * @return the instance selected.
181      */

182     static protected OpenJMSObject getInstanceSelected() {
183         Object JavaDoc loc = _tree.getLastSelectedPathComponent();
184         return (OpenJMSObject) loc;
185     }
186 }
187
Popular Tags