History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/tools/jconsole/inspector/XOperations.java (1 of 18352 files). Show all

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t