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 |
*/ |
|
55
5ecee29e98d8
6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents:
2
diff
changeset
|
25 |
|
2 | 26 |
package sun.tools.jconsole.inspector; |
27 |
||
28 |
// java import |
|
29 |
import java.awt.*; |
|
30 |
import java.awt.event.*; |
|
31 |
import java.awt.dnd.*; |
|
32 |
import java.lang.reflect.*; |
|
33 |
import java.io.*; |
|
34 |
// |
|
35 |
||
36 |
// swing import |
|
37 |
import javax.swing.border.*; |
|
38 |
import javax.swing.event.*; |
|
39 |
import javax.swing.*; |
|
40 |
// |
|
41 |
||
42 |
// jmx import |
|
43 |
import javax.management.*; |
|
44 |
// |
|
45 |
||
46 |
||
47 |
@SuppressWarnings("serial") |
|
48 |
public class OperationEntry extends JPanel { |
|
49 |
private MBeanOperationInfo operation; |
|
50 |
private JComboBox sigs; |
|
51 |
private Dimension preferredSize; |
|
52 |
private XTextField inputs[]; |
|
53 |
||
54 |
public OperationEntry (MBeanOperationInfo operation, |
|
55 |
boolean isCallable, |
|
56 |
JButton button, |
|
57 |
XOperations xoperations) { |
|
58 |
super(new BorderLayout()); |
|
59 |
this.operation = operation; |
|
60 |
setLayout(new FlowLayout(FlowLayout.LEFT)); |
|
61 |
setPanel(isCallable, button, xoperations); |
|
62 |
} |
|
63 |
||
64 |
/** |
|
65 |
* This method chops off the throws exceptions, removes "java.lang". |
|
66 |
*/ |
|
67 |
private String preProcessSignature(String signature) { |
|
68 |
int index; |
|
69 |
if ((index=signature.indexOf(" throws"))>0) { |
|
70 |
signature = signature.substring(0,index); |
|
71 |
} |
|
72 |
while ((index = signature.indexOf("java.lang."))>0) { |
|
73 |
signature = signature.substring(0,index)+ |
|
74 |
signature.substring(index+10,signature.length()); |
|
75 |
} |
|
76 |
return signature; |
|
77 |
} |
|
78 |
||
79 |
private void setPanel(boolean isCallable, |
|
80 |
JButton button, |
|
81 |
XOperations xoperations) { |
|
82 |
try { |
|
83 |
String defaultVal; |
|
84 |
MBeanParameterInfo params[] = operation.getSignature(); |
|
85 |
add(new JLabel("(",JLabel.CENTER)); |
|
86 |
inputs = new XTextField[params.length]; |
|
87 |
for (int i = 0; i < params.length; i++) { |
|
88 |
if(params[i].getName() != null) { |
|
89 |
JLabel name = |
|
90 |
new JLabel(params[i].getName(), JLabel.CENTER); |
|
91 |
name.setToolTipText(params[i].getDescription()); |
|
92 |
add(name); |
|
93 |
} |
|
94 |
||
95 |
String defaultTextValue = |
|
96 |
Utils.getDefaultValue(params[i].getType()); |
|
97 |
int fieldWidth = defaultTextValue.length(); |
|
98 |
if (fieldWidth > 15) fieldWidth = 15; |
|
99 |
else |
|
100 |
if (fieldWidth < 10) fieldWidth = 10; |
|
101 |
||
102 |
add(inputs[i] = |
|
103 |
new XTextField(Utils.getReadableClassName(defaultTextValue), |
|
104 |
Utils.getClass(params[i].getType()), |
|
105 |
fieldWidth, |
|
106 |
isCallable, |
|
107 |
button, |
|
108 |
xoperations)); |
|
109 |
inputs[i].setHorizontalAlignment(SwingConstants.CENTER); |
|
110 |
||
111 |
if (i < params.length-1) |
|
112 |
add(new JLabel(",",JLabel.CENTER)); |
|
113 |
} |
|
114 |
add(new JLabel(")",JLabel.CENTER)); |
|
115 |
validate(); |
|
116 |
doLayout(); |
|
117 |
} |
|
118 |
catch (Exception e) { |
|
119 |
System.out.println("Error setting Operation panel :"+ |
|
120 |
e.getMessage()); |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
public String[] getSignature() { |
|
125 |
MBeanParameterInfo params[] = operation.getSignature(); |
|
126 |
String result[] = new String[params.length]; |
|
127 |
for (int i = 0; i < params.length; i++) { |
|
128 |
result[i] = params[i].getType(); |
|
129 |
} |
|
130 |
return result; |
|
131 |
} |
|
132 |
||
133 |
public Object[] getParameters() throws Exception { |
|
134 |
MBeanParameterInfo params[] = operation.getSignature(); |
|
135 |
String signature[] = new String[params.length]; |
|
136 |
for (int i = 0; i < params.length; i++) |
|
137 |
signature[i] = params[i].getType(); |
|
138 |
return Utils.getParameters(inputs,signature); |
|
139 |
} |
|
140 |
||
141 |
public String getReturnType() { |
|
142 |
return operation.getReturnType(); |
|
143 |
} |
|
144 |
} |