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.BorderLayout; |
|
33 |
import java.awt.GridLayout; |
|
34 |
import java.awt.FlowLayout; |
|
35 |
import java.awt.Component; |
|
36 |
import java.awt.event.*; |
|
37 |
import java.util.*; |
|
38 |
import java.io.*; |
|
39 |
||
40 |
import javax.management.*; |
|
41 |
||
42 |
import sun.tools.jconsole.Resources; |
|
43 |
import sun.tools.jconsole.MBeansTab; |
|
44 |
import sun.tools.jconsole.JConsole; |
|
45 |
||
46 |
public abstract class XOperations extends JPanel implements ActionListener { |
|
47 |
||
48 |
public final static String OPERATION_INVOCATION_EVENT = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
49 |
"jam.xoperations.invoke.result"; |
2 | 50 |
private java.util.List<NotificationListener> notificationListenersList; |
51 |
private Hashtable<JButton, OperationEntry> operationEntryTable; |
|
52 |
private XMBean mbean; |
|
53 |
private MBeanInfo mbeanInfo; |
|
54 |
private MBeansTab mbeansTab; |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
55 |
|
2 | 56 |
public XOperations(MBeansTab mbeansTab) { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
57 |
super(new GridLayout(1, 1)); |
2 | 58 |
this.mbeansTab = mbeansTab; |
59 |
operationEntryTable = new Hashtable<JButton, OperationEntry>(); |
|
60 |
ArrayList<NotificationListener> l = |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
61 |
new ArrayList<NotificationListener>(1); |
2 | 62 |
notificationListenersList = |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
63 |
Collections.synchronizedList(l); |
2 | 64 |
} |
65 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
66 |
// Call on EDT |
2 | 67 |
public void removeOperations() { |
68 |
removeAll(); |
|
69 |
} |
|
70 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
71 |
// Call on EDT |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
72 |
public void loadOperations(XMBean mbean, MBeanInfo mbeanInfo) { |
2 | 73 |
this.mbean = mbean; |
74 |
this.mbeanInfo = mbeanInfo; |
|
75 |
// add operations information |
|
76 |
MBeanOperationInfo operations[] = mbeanInfo.getOperations(); |
|
77 |
invalidate(); |
|
78 |
||
79 |
// remove listeners, if any |
|
80 |
Component listeners[] = getComponents(); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
81 |
for (int i = 0; i < listeners.length; i++) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
82 |
if (listeners[i] instanceof JButton) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
83 |
((JButton) listeners[i]).removeActionListener(this); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
84 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
85 |
} |
2 | 86 |
|
87 |
removeAll(); |
|
88 |
setLayout(new BorderLayout()); |
|
89 |
||
90 |
JButton methodButton; |
|
91 |
JLabel methodLabel; |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
92 |
JPanel innerPanelLeft, innerPanelRight; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
93 |
JPanel outerPanelLeft, outerPanelRight; |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
94 |
outerPanelLeft = new JPanel(new GridLayout(operations.length, 1)); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
95 |
outerPanelRight = new JPanel(new GridLayout(operations.length, 1)); |
2 | 96 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
97 |
for (int i = 0; i < operations.length; i++) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
98 |
innerPanelLeft = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
2 | 99 |
innerPanelRight = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
100 |
String returnType = operations[i].getReturnType(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
101 |
if (returnType == null) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
102 |
methodLabel = new JLabel("null", JLabel.RIGHT); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
103 |
if (JConsole.isDebug()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
104 |
System.err.println( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
105 |
"WARNING: The operation's return type " + |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
106 |
"shouldn't be \"null\". Check how the " + |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
107 |
"MBeanOperationInfo for the \"" + |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
108 |
operations[i].getName() + "\" operation has " + |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
109 |
"been defined in the MBean's implementation code."); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
110 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
111 |
} else { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
112 |
methodLabel = new JLabel( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
113 |
Utils.getReadableClassName(returnType), JLabel.RIGHT); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
114 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
115 |
innerPanelLeft.add(methodLabel); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
116 |
if (methodLabel.getText().length() > 20) { |
2 | 117 |
methodLabel.setText(methodLabel.getText(). |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
118 |
substring(methodLabel.getText(). |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
119 |
lastIndexOf(".") + 1, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
120 |
methodLabel.getText().length())); |
2 | 121 |
} |
122 |
||
123 |
methodButton = new JButton(operations[i].getName()); |
|
124 |
methodButton.setToolTipText(operations[i].getDescription()); |
|
125 |
boolean callable = isCallable(operations[i].getSignature()); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
126 |
if (callable) { |
2 | 127 |
methodButton.addActionListener(this); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
128 |
} else { |
2 | 129 |
methodButton.setEnabled(false); |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
130 |
} |
2 | 131 |
|
132 |
MBeanParameterInfo[] signature = operations[i].getSignature(); |
|
133 |
OperationEntry paramEntry = new OperationEntry(operations[i], |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
134 |
callable, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
135 |
methodButton, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
136 |
this); |
2 | 137 |
operationEntryTable.put(methodButton, paramEntry); |
138 |
innerPanelRight.add(methodButton); |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
139 |
if (signature.length == 0) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
140 |
innerPanelRight.add(new JLabel("( )", JLabel.CENTER)); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
141 |
} else { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
142 |
innerPanelRight.add(paramEntry); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
143 |
} |
2 | 144 |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
145 |
outerPanelLeft.add(innerPanelLeft, BorderLayout.WEST); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
146 |
outerPanelRight.add(innerPanelRight, BorderLayout.CENTER); |
2 | 147 |
} |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
148 |
add(outerPanelLeft, BorderLayout.WEST); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
149 |
add(outerPanelRight, BorderLayout.CENTER); |
2 | 150 |
validate(); |
151 |
} |
|
152 |
||
153 |
private boolean isCallable(MBeanParameterInfo[] signature) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
154 |
for (int i = 0; i < signature.length; i++) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
155 |
if (!Utils.isEditableType(signature[i].getType())) { |
2 | 156 |
return false; |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
157 |
} |
2 | 158 |
} |
159 |
return true; |
|
160 |
} |
|
161 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
162 |
// Call on EDT |
2 | 163 |
public void actionPerformed(final ActionEvent e) { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
164 |
performInvokeRequest((JButton) e.getSource()); |
2 | 165 |
} |
166 |
||
167 |
void performInvokeRequest(final JButton button) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
168 |
final OperationEntry entryIf = operationEntryTable.get(button); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
169 |
new SwingWorker<Object, Void>() { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
170 |
@Override |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
171 |
public Object doInBackground() throws Exception { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
172 |
return mbean.invoke(button.getText(), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
173 |
entryIf.getParameters(), entryIf.getSignature()); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
174 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
175 |
@Override |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
176 |
protected void done() { |
2 | 177 |
try { |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
178 |
Object result = get(); |
2 | 179 |
// sends result notification to upper level if |
180 |
// there is a return value |
|
181 |
if (entryIf.getReturnType() != null && |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
182 |
!entryIf.getReturnType().equals(Void.TYPE.getName()) && |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
183 |
!entryIf.getReturnType().equals(Void.class.getName())) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
184 |
fireChangedNotification(OPERATION_INVOCATION_EVENT, button, result); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
185 |
} else { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
186 |
new ThreadDialog( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
187 |
button, |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
188 |
Resources.getText("Method successfully invoked"), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
189 |
Resources.getText("Info"), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
190 |
JOptionPane.INFORMATION_MESSAGE).run(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
191 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
192 |
} catch (Throwable t) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
193 |
t = Utils.getActualException(t); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
194 |
if (JConsole.isDebug()) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
195 |
t.printStackTrace(); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
196 |
} |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
197 |
new ThreadDialog( |
2 | 198 |
button, |
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
199 |
Resources.getText("Problem invoking") + " " + |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
200 |
button.getText() + " : " + t.toString(), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
201 |
Resources.getText("Error"), |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
202 |
JOptionPane.ERROR_MESSAGE).run(); |
2 | 203 |
} |
204 |
} |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
205 |
}.execute(); |
2 | 206 |
} |
207 |
||
208 |
public void addOperationsListener(NotificationListener nl) { |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
209 |
notificationListenersList.add(nl); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
210 |
} |
2 | 211 |
|
212 |
public void removeOperationsListener(NotificationListener nl) { |
|
213 |
notificationListenersList.remove(nl); |
|
214 |
} |
|
215 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
216 |
// Call on EDT |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
217 |
private void fireChangedNotification( |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
218 |
String type, Object source, Object handback) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
219 |
Notification n = new Notification(type, source, 0); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
220 |
for (NotificationListener nl : notificationListenersList) { |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
221 |
nl.handleNotification(n, handback); |
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
222 |
} |
2 | 223 |
} |
224 |
||
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
225 |
protected abstract MBeanOperationInfo[] updateOperations(MBeanOperationInfo[] operations); |
2 | 226 |
} |