author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 55 | 5ecee29e98d8 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.tools.jconsole.inspector; |
|
27 |
||
28 |
import javax.swing.*; |
|
29 |
import javax.swing.event.*; |
|
30 |
import javax.swing.table.*; |
|
31 |
import javax.swing.tree.*; |
|
32 |
import java.awt.Font; |
|
33 |
||
34 |
import java.text.SimpleDateFormat; |
|
35 |
||
36 |
import java.awt.Component; |
|
37 |
import java.awt.EventQueue; |
|
38 |
import java.awt.event.*; |
|
39 |
import java.awt.Dimension; |
|
40 |
import java.util.*; |
|
41 |
import java.io.*; |
|
42 |
import java.lang.reflect.Array; |
|
43 |
||
44 |
import javax.management.*; |
|
45 |
import javax.management.openmbean.CompositeData; |
|
46 |
import javax.management.openmbean.TabularData; |
|
47 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
48 |
import sun.tools.jconsole.JConsole; |
2 | 49 |
import sun.tools.jconsole.Resources; |
50 |
||
51 |
@SuppressWarnings("serial") |
|
52 |
public class XMBeanNotifications extends JTable implements NotificationListener { |
|
53 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
54 |
private final static String[] columnNames = { |
2 | 55 |
Resources.getText("TimeStamp"), |
56 |
Resources.getText("Type"), |
|
57 |
Resources.getText("UserData"), |
|
58 |
Resources.getText("SeqNum"), |
|
59 |
Resources.getText("Message"), |
|
60 |
Resources.getText("Event"), |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
61 |
Resources.getText("Source") |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
62 |
}; |
2 | 63 |
private HashMap<ObjectName, XMBeanNotificationsListener> listeners = |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
64 |
new HashMap<ObjectName, XMBeanNotificationsListener>(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
65 |
private volatile boolean subscribed; |
2 | 66 |
private XMBeanNotificationsListener currentListener; |
67 |
public final static String NOTIFICATION_RECEIVED_EVENT = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
68 |
"jconsole.xnotification.received"; |
2 | 69 |
private List<NotificationListener> notificationListenersList; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
70 |
private volatile boolean enabled; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
71 |
private Font normalFont, boldFont; |
2 | 72 |
private int rowMinHeight = -1; |
73 |
private TableCellEditor userDataEditor = new UserDataCellEditor(); |
|
74 |
private NotifMouseListener mouseListener = new NotifMouseListener(); |
|
75 |
private SimpleDateFormat timeFormater = new SimpleDateFormat("HH:mm:ss:SSS"); |
|
76 |
private static TableCellEditor editor = |
|
77 |
new Utils.ReadOnlyTableCellEditor(new JTextField()); |
|
78 |
||
79 |
public XMBeanNotifications() { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
80 |
super(new TableSorter(columnNames, 0)); |
2 | 81 |
setColumnSelectionAllowed(false); |
82 |
setRowSelectionAllowed(false); |
|
83 |
getTableHeader().setReorderingAllowed(false); |
|
84 |
ArrayList<NotificationListener> l = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
85 |
new ArrayList<NotificationListener>(1); |
2 | 86 |
notificationListenersList = Collections.synchronizedList(l); |
87 |
||
88 |
addMouseListener(mouseListener); |
|
89 |
||
90 |
TableColumnModel colModel = getColumnModel(); |
|
91 |
colModel.getColumn(0).setPreferredWidth(45); |
|
92 |
colModel.getColumn(1).setPreferredWidth(50); |
|
93 |
colModel.getColumn(2).setPreferredWidth(50); |
|
94 |
colModel.getColumn(3).setPreferredWidth(40); |
|
95 |
colModel.getColumn(4).setPreferredWidth(50); |
|
96 |
colModel.getColumn(5).setPreferredWidth(50); |
|
97 |
setColumnEditors(); |
|
98 |
addKeyListener(new Utils.CopyKeyAdapter()); |
|
99 |
} |
|
100 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
101 |
// Call on EDT |
2 | 102 |
public void cancelCellEditing() { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
103 |
TableCellEditor tce = getCellEditor(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
104 |
if (tce != null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
105 |
tce.cancelCellEditing(); |
2 | 106 |
} |
107 |
} |
|
108 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
109 |
// Call on EDT |
2 | 110 |
public void stopCellEditing() { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
111 |
TableCellEditor tce = getCellEditor(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
112 |
if (tce != null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
113 |
tce.stopCellEditing(); |
2 | 114 |
} |
115 |
} |
|
116 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
117 |
// Call on EDT |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
118 |
@Override |
2 | 119 |
public boolean isCellEditable(int row, int col) { |
120 |
UserDataCell cell = getUserDataCell(row, col); |
|
121 |
if (cell != null) { |
|
122 |
return cell.isMaximized(); |
|
123 |
} |
|
124 |
return true; |
|
125 |
} |
|
126 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
127 |
// Call on EDT |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
128 |
@Override |
2 | 129 |
public void setValueAt(Object value, int row, int column) { |
130 |
} |
|
131 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
132 |
// Call on EDT |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
133 |
@Override |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
134 |
public synchronized Component prepareRenderer( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
135 |
TableCellRenderer renderer, int row, int column) { |
2 | 136 |
//In case we have a repaint thread that is in the process of |
137 |
//repainting an obsolete table, just ignore the call. |
|
138 |
//It can happen when MBean selection is switched at a very quick rate |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
139 |
if (row >= getRowCount()) { |
2 | 140 |
return null; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
141 |
} |
2 | 142 |
|
143 |
Component comp = super.prepareRenderer(renderer, row, column); |
|
144 |
||
145 |
if (normalFont == null) { |
|
146 |
normalFont = comp.getFont(); |
|
147 |
boldFont = normalFont.deriveFont(Font.BOLD); |
|
148 |
} |
|
149 |
UserDataCell cell = getUserDataCell(row, 2); |
|
150 |
if (column == 2 && cell != null) { |
|
151 |
comp.setFont(boldFont); |
|
152 |
int size = cell.getHeight(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
153 |
if (size > 0) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
154 |
if (getRowHeight(row) != size) { |
2 | 155 |
setRowHeight(row, size); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
156 |
} |
2 | 157 |
} |
158 |
} else { |
|
159 |
comp.setFont(normalFont); |
|
160 |
} |
|
161 |
||
162 |
return comp; |
|
163 |
} |
|
164 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
165 |
// Call on EDT |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
166 |
@Override |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
167 |
public synchronized TableCellRenderer getCellRenderer(int row, int column) { |
2 | 168 |
//In case we have a repaint thread that is in the process of |
169 |
//repainting an obsolete table, just ignore the call. |
|
170 |
//It can happen when MBean selection is switched at a very quick rate |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
171 |
if (row >= getRowCount()) { |
2 | 172 |
return null; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
173 |
} |
2 | 174 |
|
175 |
DefaultTableCellRenderer renderer; |
|
176 |
String toolTip = null; |
|
177 |
UserDataCell cell = getUserDataCell(row, column); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
178 |
if (cell != null && cell.isInited()) { |
2 | 179 |
renderer = (DefaultTableCellRenderer) cell.getRenderer(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
180 |
} else { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
181 |
renderer = |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
182 |
(DefaultTableCellRenderer) super.getCellRenderer(row, column); |
2 | 183 |
} |
184 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
185 |
if (cell != null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
186 |
toolTip = Resources.getText("Double click to expand/collapse") + |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
187 |
". " + cell.toString(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
188 |
} else { |
2 | 189 |
Object val = |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
190 |
((DefaultTableModel) getModel()).getValueAt(row, column); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
191 |
if (val != null) { |
2 | 192 |
toolTip = val.toString(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
193 |
} |
2 | 194 |
} |
195 |
||
196 |
renderer.setToolTipText(toolTip); |
|
197 |
||
198 |
return renderer; |
|
199 |
} |
|
200 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
201 |
// Call on EDT |
2 | 202 |
private UserDataCell getUserDataCell(int row, int column) { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
203 |
Object obj = ((DefaultTableModel) getModel()).getValueAt(row, column); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
204 |
if (obj instanceof UserDataCell) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
205 |
return (UserDataCell) obj; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
206 |
} |
2 | 207 |
return null; |
208 |
} |
|
209 |
||
210 |
synchronized void dispose() { |
|
211 |
listeners.clear(); |
|
212 |
} |
|
213 |
||
214 |
public long getReceivedNotifications(XMBean mbean) { |
|
215 |
XMBeanNotificationsListener listener = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
216 |
listeners.get(mbean.getObjectName()); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
217 |
if (listener == null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
218 |
return 0; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
219 |
} else { |
2 | 220 |
return listener.getReceivedNotifications(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
221 |
} |
2 | 222 |
} |
223 |
||
224 |
public synchronized boolean clearCurrentNotifications() { |
|
225 |
emptyTable(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
226 |
if (currentListener != null) { |
2 | 227 |
currentListener.clear(); |
228 |
return true; |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
229 |
} else { |
2 | 230 |
return false; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
231 |
} |
2 | 232 |
} |
233 |
||
234 |
public synchronized boolean unregisterListener(DefaultMutableTreeNode node) { |
|
235 |
XMBean mbean = (XMBean) ((XNodeInfo) node.getUserObject()).getData(); |
|
236 |
return unregister(mbean.getObjectName()); |
|
237 |
} |
|
238 |
||
239 |
public synchronized void registerListener(DefaultMutableTreeNode node) |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
240 |
throws InstanceNotFoundException, IOException { |
2 | 241 |
XMBean mbean = (XMBean) ((XNodeInfo) node.getUserObject()).getData(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
242 |
if (!subscribed) { |
2 | 243 |
try { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
244 |
mbean.getMBeanServerConnection().addNotificationListener( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
245 |
MBeanServerDelegate.DELEGATE_NAME, this, null, null); |
2 | 246 |
subscribed = true; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
247 |
} catch (Exception e) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
248 |
if (JConsole.isDebug()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
249 |
System.err.println("Error adding listener for delegate:"); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
250 |
e.printStackTrace(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
251 |
} |
2 | 252 |
} |
253 |
} |
|
254 |
XMBeanNotificationsListener listener = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
255 |
listeners.get(mbean.getObjectName()); |
2 | 256 |
if (listener == null) { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
257 |
listener = new XMBeanNotificationsListener( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
258 |
this, mbean, node, columnNames); |
2 | 259 |
listeners.put(mbean.getObjectName(), listener); |
260 |
} else { |
|
261 |
if (!listener.isRegistered()) { |
|
262 |
emptyTable(); |
|
263 |
listener.register(node); |
|
264 |
} |
|
265 |
} |
|
266 |
enabled = true; |
|
267 |
currentListener = listener; |
|
268 |
} |
|
269 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
270 |
public synchronized void handleNotification( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
271 |
Notification notif, Object handback) { |
2 | 272 |
try { |
273 |
if (notif instanceof MBeanServerNotification) { |
|
274 |
ObjectName mbean = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
275 |
((MBeanServerNotification) notif).getMBeanName(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
276 |
if (notif.getType().indexOf("JMX.mbean.unregistered") >= 0) { |
2 | 277 |
unregister(mbean); |
278 |
} |
|
279 |
} |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
280 |
} catch (Exception e) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
281 |
if (JConsole.isDebug()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
282 |
System.err.println("Error unregistering notification:"); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
283 |
e.printStackTrace(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
284 |
} |
2 | 285 |
} |
286 |
} |
|
287 |
||
288 |
public synchronized void disableNotifications() { |
|
289 |
emptyTable(); |
|
290 |
currentListener = null; |
|
291 |
enabled = false; |
|
292 |
} |
|
293 |
||
294 |
private synchronized boolean unregister(ObjectName mbean) { |
|
295 |
XMBeanNotificationsListener listener = listeners.get(mbean); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
296 |
if (listener != null && listener.isRegistered()) { |
2 | 297 |
listener.unregister(); |
298 |
return true; |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
299 |
} else { |
2 | 300 |
return false; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
301 |
} |
2 | 302 |
} |
303 |
||
304 |
public void addNotificationsListener(NotificationListener nl) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
305 |
notificationListenersList.add(nl); |
2 | 306 |
} |
307 |
||
308 |
public void removeNotificationsListener(NotificationListener nl) { |
|
309 |
notificationListenersList.remove(nl); |
|
310 |
} |
|
311 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
312 |
// Call on EDT |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
313 |
void fireNotificationReceived( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
314 |
XMBeanNotificationsListener listener, XMBean mbean, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
315 |
DefaultMutableTreeNode node, Object[] rowData, long received) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
316 |
if (enabled) { |
2 | 317 |
DefaultTableModel tableModel = (DefaultTableModel) getModel(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
318 |
if (listener == currentListener) { |
2 | 319 |
tableModel.insertRow(0, rowData); |
320 |
repaint(); |
|
321 |
} |
|
322 |
} |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
323 |
Notification notif = |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
324 |
new Notification(NOTIFICATION_RECEIVED_EVENT, this, 0); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
325 |
notif.setUserData(received); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
326 |
for (NotificationListener nl : notificationListenersList) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
327 |
nl.handleNotification(notif, node); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
328 |
} |
2 | 329 |
} |
330 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
331 |
// Call on EDT |
2 | 332 |
private void updateModel(List<Object[]> data) { |
333 |
emptyTable(); |
|
334 |
DefaultTableModel tableModel = (DefaultTableModel) getModel(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
335 |
for (Object[] rowData : data) { |
2 | 336 |
tableModel.addRow(rowData); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
337 |
} |
2 | 338 |
} |
339 |
||
340 |
public synchronized boolean isListenerRegistered(XMBean mbean) { |
|
341 |
XMBeanNotificationsListener listener = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
342 |
listeners.get(mbean.getObjectName()); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
343 |
if (listener == null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
344 |
return false; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
345 |
} |
2 | 346 |
return listener.isRegistered(); |
347 |
} |
|
348 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
349 |
// Call on EDT |
2 | 350 |
public synchronized void loadNotifications(XMBean mbean) { |
351 |
XMBeanNotificationsListener listener = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
352 |
listeners.get(mbean.getObjectName()); |
2 | 353 |
emptyTable(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
354 |
if (listener != null) { |
2 | 355 |
enabled = true; |
356 |
List<Object[]> data = listener.getData(); |
|
357 |
updateModel(data); |
|
358 |
currentListener = listener; |
|
359 |
validate(); |
|
360 |
repaint(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
361 |
} else { |
2 | 362 |
enabled = false; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
363 |
} |
2 | 364 |
} |
365 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
366 |
// Call on EDT |
2 | 367 |
private void setColumnEditors() { |
368 |
TableColumnModel tcm = getColumnModel(); |
|
369 |
for (int i = 0; i < columnNames.length; i++) { |
|
370 |
TableColumn tc = tcm.getColumn(i); |
|
371 |
if (i == 2) { |
|
372 |
tc.setCellEditor(userDataEditor); |
|
373 |
} else { |
|
374 |
tc.setCellEditor(editor); |
|
375 |
} |
|
376 |
} |
|
377 |
} |
|
378 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
379 |
// Call on EDT |
2 | 380 |
public boolean isTableEditable() { |
381 |
return true; |
|
382 |
} |
|
383 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
384 |
// Call on EDT |
2 | 385 |
public synchronized void emptyTable() { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
386 |
DefaultTableModel model = (DefaultTableModel) getModel(); |
2 | 387 |
//invalidate(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
388 |
while (model.getRowCount() > 0) { |
2 | 389 |
model.removeRow(0); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
390 |
} |
2 | 391 |
validate(); |
392 |
} |
|
393 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
394 |
// Call on EDT |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
395 |
synchronized void updateUserDataCell(int row, int col) { |
2 | 396 |
Object obj = getModel().getValueAt(row, 2); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
397 |
if (obj instanceof UserDataCell) { |
2 | 398 |
UserDataCell cell = (UserDataCell) obj; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
399 |
if (!cell.isInited()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
400 |
if (rowMinHeight == -1) { |
2 | 401 |
rowMinHeight = getRowHeight(row); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
402 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
403 |
cell.init(super.getCellRenderer(row, col), rowMinHeight); |
2 | 404 |
} |
405 |
||
406 |
cell.switchState(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
407 |
setRowHeight(row, cell.getHeight()); |
2 | 408 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
409 |
if (!cell.isMaximized()) { |
2 | 410 |
cancelCellEditing(); |
411 |
//Back to simple editor. |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
412 |
editCellAt(row, 2); |
2 | 413 |
} |
414 |
||
415 |
invalidate(); |
|
416 |
repaint(); |
|
417 |
} |
|
418 |
} |
|
419 |
||
420 |
class UserDataCellRenderer extends DefaultTableCellRenderer { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
421 |
|
2 | 422 |
Component comp; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
423 |
|
2 | 424 |
UserDataCellRenderer(Component comp) { |
425 |
this.comp = comp; |
|
426 |
Dimension d = comp.getPreferredSize(); |
|
427 |
if (d.getHeight() > 200) { |
|
428 |
comp.setPreferredSize(new Dimension((int) d.getWidth(), 200)); |
|
429 |
} |
|
430 |
} |
|
431 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
432 |
@Override |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
433 |
public Component getTableCellRendererComponent( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
434 |
JTable table, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
435 |
Object value, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
436 |
boolean isSelected, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
437 |
boolean hasFocus, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
438 |
int row, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
439 |
int column) { |
2 | 440 |
return comp; |
441 |
} |
|
442 |
||
443 |
public Component getComponent() { |
|
444 |
return comp; |
|
445 |
} |
|
446 |
} |
|
447 |
||
448 |
class UserDataCell { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
449 |
|
2 | 450 |
TableCellRenderer minRenderer; |
451 |
UserDataCellRenderer maxRenderer; |
|
452 |
int minHeight; |
|
453 |
boolean minimized = true; |
|
454 |
boolean init = false; |
|
455 |
Object userData; |
|
456 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
457 |
UserDataCell(Object userData, Component max) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
458 |
this.userData = userData; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
459 |
this.maxRenderer = new UserDataCellRenderer(max); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
460 |
|
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
461 |
} |
2 | 462 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
463 |
@Override |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
464 |
public String toString() { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
465 |
if (userData == null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
466 |
return null; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
467 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
468 |
if (userData.getClass().isArray()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
469 |
String name = |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
470 |
Utils.getArrayClassName(userData.getClass().getName()); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
471 |
int length = Array.getLength(userData); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
472 |
return name + "[" + length + "]"; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
473 |
} |
2 | 474 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
475 |
if (userData instanceof CompositeData || |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
476 |
userData instanceof TabularData) { |
2 | 477 |
return userData.getClass().getName(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
478 |
} |
2 | 479 |
|
480 |
return userData.toString(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
481 |
} |
2 | 482 |
|
483 |
boolean isInited() { |
|
484 |
return init; |
|
485 |
} |
|
486 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
487 |
void init(TableCellRenderer minRenderer, int minHeight) { |
2 | 488 |
this.minRenderer = minRenderer; |
489 |
this.minHeight = minHeight; |
|
490 |
init = true; |
|
491 |
} |
|
492 |
||
493 |
void switchState() { |
|
494 |
minimized = !minimized; |
|
495 |
} |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
496 |
|
2 | 497 |
boolean isMaximized() { |
498 |
return !minimized; |
|
499 |
} |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
500 |
|
2 | 501 |
void minimize() { |
502 |
minimized = true; |
|
503 |
} |
|
504 |
||
505 |
void maximize() { |
|
506 |
minimized = false; |
|
507 |
} |
|
508 |
||
509 |
int getHeight() { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
510 |
if (minimized) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
511 |
return minHeight; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
512 |
} else { |
2 | 513 |
return (int) maxRenderer.getComponent(). |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
514 |
getPreferredSize().getHeight(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
515 |
} |
2 | 516 |
} |
517 |
||
518 |
TableCellRenderer getRenderer() { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
519 |
if (minimized) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
520 |
return minRenderer; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
521 |
} else { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
522 |
return maxRenderer; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
523 |
} |
2 | 524 |
} |
525 |
} |
|
526 |
||
527 |
class NotifMouseListener extends MouseAdapter { |
|
528 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
529 |
@Override |
2 | 530 |
public void mousePressed(MouseEvent e) { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
531 |
if (e.getButton() == MouseEvent.BUTTON1) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
532 |
if (e.getClickCount() >= 2) { |
2 | 533 |
int row = XMBeanNotifications.this.getSelectedRow(); |
534 |
int col = XMBeanNotifications.this.getSelectedColumn(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
535 |
if (col != 2) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
536 |
return; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
537 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
538 |
if (col == -1 || row == -1) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
539 |
return; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
540 |
} |
2 | 541 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
542 |
XMBeanNotifications.this.updateUserDataCell(row, col); |
2 | 543 |
} |
544 |
} |
|
545 |
} |
|
546 |
} |
|
547 |
||
548 |
class UserDataCellEditor extends XTextFieldEditor { |
|
549 |
// implements javax.swing.table.TableCellEditor |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
550 |
@Override |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
551 |
public Component getTableCellEditorComponent( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
552 |
JTable table, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
553 |
Object value, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
554 |
boolean isSelected, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
555 |
int row, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
556 |
int column) { |
2 | 557 |
Object val = value; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
558 |
if (column == 2) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
559 |
Object obj = getModel().getValueAt(row, column); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
560 |
if (obj instanceof UserDataCell) { |
2 | 561 |
UserDataCell cell = (UserDataCell) obj; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
562 |
if (cell.getRenderer() instanceof UserDataCellRenderer) { |
2 | 563 |
UserDataCellRenderer zr = |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
564 |
(UserDataCellRenderer) cell.getRenderer(); |
2 | 565 |
return zr.getComponent(); |
566 |
} |
|
567 |
} else { |
|
568 |
Component comp = super.getTableCellEditorComponent( |
|
569 |
table, val, isSelected, row, column); |
|
570 |
textField.setEditable(false); |
|
571 |
return comp; |
|
572 |
} |
|
573 |
} |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
574 |
return super.getTableCellEditorComponent( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
575 |
table, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
576 |
val, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
577 |
isSelected, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
578 |
row, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
579 |
column); |
2 | 580 |
} |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
581 |
|
2 | 582 |
@Override |
583 |
public boolean stopCellEditing() { |
|
584 |
int editingRow = getEditingRow(); |
|
585 |
int editingColumn = getEditingColumn(); |
|
586 |
if (editingColumn == 2) { |
|
587 |
Object obj = getModel().getValueAt(editingRow, editingColumn); |
|
588 |
if (obj instanceof UserDataCell) { |
|
589 |
UserDataCell cell = (UserDataCell) obj; |
|
590 |
if (cell.isMaximized()) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
591 |
cancelCellEditing(); |
2 | 592 |
return true; |
593 |
} |
|
594 |
} |
|
595 |
} |
|
596 |
return super.stopCellEditing(); |
|
597 |
} |
|
598 |
} |
|
599 |
||
600 |
class XMBeanNotificationsListener implements NotificationListener { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
601 |
|
2 | 602 |
private String[] columnNames; |
603 |
private XMBean xmbean; |
|
604 |
private DefaultMutableTreeNode node; |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
605 |
private volatile long received; |
2 | 606 |
private XMBeanNotifications notifications; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
607 |
private volatile boolean unregistered; |
2 | 608 |
private ArrayList<Object[]> data = new ArrayList<Object[]>(); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
609 |
|
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
610 |
public XMBeanNotificationsListener( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
611 |
XMBeanNotifications notifications, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
612 |
XMBean xmbean, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
613 |
DefaultMutableTreeNode node, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
614 |
String[] columnNames) { |
2 | 615 |
this.notifications = notifications; |
616 |
this.xmbean = xmbean; |
|
617 |
this.node = node; |
|
618 |
this.columnNames = columnNames; |
|
619 |
register(node); |
|
620 |
} |
|
621 |
||
622 |
public synchronized List<Object[]> getData() { |
|
623 |
return data; |
|
624 |
} |
|
625 |
||
626 |
public synchronized void clear() { |
|
627 |
data.clear(); |
|
628 |
received = 0; |
|
629 |
} |
|
630 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
631 |
public synchronized boolean isRegistered() { |
2 | 632 |
return !unregistered; |
633 |
} |
|
634 |
||
635 |
public synchronized void unregister() { |
|
636 |
try { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
637 |
xmbean.getMBeanServerConnection().removeNotificationListener( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
638 |
xmbean.getObjectName(), this, null, null); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
639 |
} catch (Exception e) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
640 |
if (JConsole.isDebug()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
641 |
System.err.println("Error removing listener:"); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
642 |
e.printStackTrace(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
643 |
} |
2 | 644 |
} |
645 |
unregistered = true; |
|
646 |
} |
|
647 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
648 |
public synchronized long getReceivedNotifications() { |
2 | 649 |
return received; |
650 |
} |
|
651 |
||
652 |
public synchronized void register(DefaultMutableTreeNode node) { |
|
653 |
clear(); |
|
654 |
this.node = node; |
|
655 |
try { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
656 |
xmbean.getMBeanServerConnection().addNotificationListener( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
657 |
xmbean.getObjectName(), this, null, null); |
2 | 658 |
unregistered = false; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
659 |
} catch (Exception e) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
660 |
if (JConsole.isDebug()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
661 |
System.err.println("Error adding listener:"); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
662 |
e.printStackTrace(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
663 |
} |
2 | 664 |
} |
665 |
} |
|
666 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
667 |
public synchronized void handleNotification( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
668 |
final Notification n, Object hb) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
669 |
EventQueue.invokeLater(new Runnable() { |
2 | 670 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
671 |
public void run() { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
672 |
synchronized (XMBeanNotificationsListener.this) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
673 |
try { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
674 |
if (unregistered) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
675 |
return; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
676 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
677 |
Date receivedDate = new Date(n.getTimeStamp()); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
678 |
String time = timeFormater.format(receivedDate); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
679 |
|
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
680 |
Object userData = n.getUserData(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
681 |
Component comp = null; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
682 |
UserDataCell cell = null; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
683 |
if ((comp = XDataViewer.createNotificationViewer(userData)) != null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
684 |
XDataViewer.registerForMouseEvent(comp, mouseListener); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
685 |
cell = new UserDataCell(userData, comp); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
686 |
} |
2 | 687 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
688 |
Object[] rowData = { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
689 |
time, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
690 |
n.getType(), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
691 |
(cell == null ? userData : cell), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
692 |
n.getSequenceNumber(), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
693 |
n.getMessage(), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
694 |
n, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
695 |
n.getSource() |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
696 |
}; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
697 |
received++; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
698 |
data.add(0, rowData); |
2 | 699 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
700 |
notifications.fireNotificationReceived( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
701 |
XMBeanNotificationsListener.this, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
702 |
xmbean, node, rowData, received); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
703 |
} catch (Exception e) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
704 |
if (JConsole.isDebug()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
705 |
System.err.println("Error handling notification:"); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
706 |
e.printStackTrace(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
707 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
708 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
709 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
710 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
711 |
}); |
2 | 712 |
} |
713 |
} |
|
714 |
} |