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
26 package sun.tools.jconsole;
27
28 import java.awt.*;
29 import java.awt.event.*;
30 import java.util.List;
31 import java.util.TreeSet;
32 import java.util.Comparator;
33
34 import javax.swing.*;
35 import javax.swing.Timer;
36 import javax.swing.border.*;
37 import javax.swing.event.*;
38
39 import javax.management.MBeanServerConnection;
40 import javax.management.ObjectName;
41 import javax.management.InstanceAlreadyExistsException;
42 import javax.management.InstanceNotFoundException;
43
44 import static sun.tools.jconsole.Resources.*;
45 import static sun.tools.jconsole.Utilities.*;
46
47 @SuppressWarnings("serial")
48 public class CreateMBeanDialog extends InternalDialog
49 implements ActionListener {
50 JConsole jConsole;
51 JComboBox connections;
52 JButton createMBeanButton, unregisterMBeanButton, cancelButton;
53
54 private static final String HOTSPOT_MBEAN =
55 "sun.management.HotspotInternal";
56 private static final String HOTSPOT_MBEAN_OBJECTNAME =
57 "sun.management:type=HotspotInternal";
58 public CreateMBeanDialog(JConsole jConsole) {
59 super(jConsole, "JConsole: Hotspot MBeans", true);
60
61 this.jConsole = jConsole;
62 setAccessibleDescription(this,
63 getText("Hotspot MBeans.dialog.accessibleDescription"));
64 Container cp = getContentPane();
65 ((JComponent)cp).setBorder(new EmptyBorder(10, 10, 4, 10));
66
67 JPanel centerPanel = new JPanel(new VariableGridLayout(0,
68 1,
69 4,
70 4,
71 false,
72 true));
73 cp.add(centerPanel, BorderLayout.CENTER);
74 connections = new JComboBox();
75 updateConnections();
76
77 centerPanel.add(new LabeledComponent(Resources.
78 getText("Manage Hotspot MBeans "+
79 "in: "),
80 connections));
81
82 JPanel bottomPanel = new JPanel(new BorderLayout());
83 cp.add(bottomPanel, BorderLayout.SOUTH);
84
85 JPanel buttonPanel = new JPanel();
86 bottomPanel.add(buttonPanel, BorderLayout.NORTH);
87 buttonPanel.add(createMBeanButton =
88 new JButton(Resources.getText("Create")));
89 buttonPanel.add(unregisterMBeanButton =
90 new JButton(Resources.getText("Unregister")));
91 buttonPanel.add(cancelButton =
92 new JButton(Resources.getText("Cancel")));
93
94 statusBar = new JLabel(" ", JLabel.CENTER);
95 bottomPanel.add(statusBar, BorderLayout.SOUTH);
96
97 createMBeanButton.addActionListener(this);
98 unregisterMBeanButton.addActionListener(this);
99 cancelButton.addActionListener(this);
100
101 LabeledComponent.layout(centerPanel);
102 pack();
103 setLocationRelativeTo(jConsole);
104 }
105
106 private void updateConnections() {
107 List<VMInternalFrame> frames = jConsole.getInternalFrames();
108 TreeSet<ProxyClient> data =
109 new TreeSet<ProxyClient>(new Comparator<ProxyClient>() {
110 public int compare(ProxyClient o1, ProxyClient o2) {
111 // TODO: Need to understand how this method being used?
112 return o1.connectionName().compareTo(o2.connectionName());
127 } else {
128 for (VMInternalFrame f : frames) {
129 ProxyClient client = f.getVMPanel().getProxyClient(false);
130 if (client != null && client.hasPlatformMXBeans()) {
131 data.add(client);
132 }
133 }
134 }
135 connections.invalidate();
136 connections.setModel(new DefaultComboBoxModel(data.toArray()));
137 connections.validate();
138 }
139
140 public void actionPerformed(final ActionEvent ev) {
141 setVisible(false);
142 statusBar.setText("");
143 if (ev.getSource() != cancelButton) {
144 new Thread("CreateMBeanDialog.actionPerformed") {
145 public void run() {
146 try {
147 StringBuffer buff = null;
148 Object c = connections.getSelectedItem();
149 if(c == null) return;
150 if(ev.getSource() == createMBeanButton) {
151 MBeanServerConnection connection =
152 ((ProxyClient) c).
153 getMBeanServerConnection();
154 connection.createMBean(HOTSPOT_MBEAN, null);
155 } else {
156 if(ev.getSource() == unregisterMBeanButton) {
157 MBeanServerConnection connection =
158 ((ProxyClient) c).
159 getMBeanServerConnection();
160 connection.unregisterMBean(new
161 ObjectName(HOTSPOT_MBEAN_OBJECTNAME));
162 }
163 }
164 return;
165 } catch(InstanceAlreadyExistsException e) {
166 statusBar.setText(Resources.
167 getText("Error: MBeans already "
168 + "exist"));
169 } catch(InstanceNotFoundException e) {
170 statusBar.setText(Resources.
171 getText("Error: MBeans do not "
172 + "exist"));
173 } catch(Exception e) {
174 statusBar.setText(e.toString());
175 }
176 setVisible(true);
177 }
178 }.start();
179 }
180 }
181
182 public void setVisible(boolean b) {
183 boolean wasVisible = isVisible();
184
185 if(b) {
186 setLocationRelativeTo(jConsole);
187 invalidate();
188 updateConnections();
189 validate();
190 repaint();
191 }
192
|
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
26 package sun.tools.jconsole;
27
28 import java.awt.*;
29 import java.awt.event.*;
30 import java.util.List;
31 import java.util.TreeSet;
32 import java.util.Comparator;
33
34 import javax.swing.*;
35 import javax.swing.border.*;
36
37 import javax.management.MBeanServerConnection;
38 import javax.management.ObjectName;
39 import javax.management.InstanceAlreadyExistsException;
40 import javax.management.InstanceNotFoundException;
41
42
43 import static sun.tools.jconsole.Utilities.*;
44
45 @SuppressWarnings("serial")
46 public class CreateMBeanDialog extends InternalDialog
47 implements ActionListener {
48 JConsole jConsole;
49 JComboBox connections;
50 JButton createMBeanButton, unregisterMBeanButton, cancelButton;
51
52 private static final String HOTSPOT_MBEAN =
53 "sun.management.HotspotInternal";
54 private static final String HOTSPOT_MBEAN_OBJECTNAME =
55 "sun.management:type=HotspotInternal";
56 public CreateMBeanDialog(JConsole jConsole) {
57 super(jConsole, "JConsole: Hotspot MBeans", true);
58
59 this.jConsole = jConsole;
60 setAccessibleDescription(this,
61 Messages.HOTSPOT_MBEANS_DIALOG_ACCESSIBLE_DESCRIPTION);
62 Container cp = getContentPane();
63 ((JComponent)cp).setBorder(new EmptyBorder(10, 10, 4, 10));
64
65 JPanel centerPanel = new JPanel(new VariableGridLayout(0,
66 1,
67 4,
68 4,
69 false,
70 true));
71 cp.add(centerPanel, BorderLayout.CENTER);
72 connections = new JComboBox();
73 updateConnections();
74
75 centerPanel.add(new LabeledComponent(Resources.format(Messages.MANAGE_HOTSPOT_MBEANS_IN_COLON_),
76 connections));
77
78 JPanel bottomPanel = new JPanel(new BorderLayout());
79 cp.add(bottomPanel, BorderLayout.SOUTH);
80
81 JPanel buttonPanel = new JPanel();
82 bottomPanel.add(buttonPanel, BorderLayout.NORTH);
83 buttonPanel.add(createMBeanButton =
84 new JButton(Messages.CREATE));
85 buttonPanel.add(unregisterMBeanButton =
86 new JButton(Messages.UNREGISTER));
87 buttonPanel.add(cancelButton =
88 new JButton(Messages.CANCEL));
89
90 statusBar = new JLabel(" ", JLabel.CENTER);
91 bottomPanel.add(statusBar, BorderLayout.SOUTH);
92
93 createMBeanButton.addActionListener(this);
94 unregisterMBeanButton.addActionListener(this);
95 cancelButton.addActionListener(this);
96
97 LabeledComponent.layout(centerPanel);
98 pack();
99 setLocationRelativeTo(jConsole);
100 }
101
102 private void updateConnections() {
103 List<VMInternalFrame> frames = jConsole.getInternalFrames();
104 TreeSet<ProxyClient> data =
105 new TreeSet<ProxyClient>(new Comparator<ProxyClient>() {
106 public int compare(ProxyClient o1, ProxyClient o2) {
107 // TODO: Need to understand how this method being used?
108 return o1.connectionName().compareTo(o2.connectionName());
123 } else {
124 for (VMInternalFrame f : frames) {
125 ProxyClient client = f.getVMPanel().getProxyClient(false);
126 if (client != null && client.hasPlatformMXBeans()) {
127 data.add(client);
128 }
129 }
130 }
131 connections.invalidate();
132 connections.setModel(new DefaultComboBoxModel(data.toArray()));
133 connections.validate();
134 }
135
136 public void actionPerformed(final ActionEvent ev) {
137 setVisible(false);
138 statusBar.setText("");
139 if (ev.getSource() != cancelButton) {
140 new Thread("CreateMBeanDialog.actionPerformed") {
141 public void run() {
142 try {
143 Object c = connections.getSelectedItem();
144 if(c == null) return;
145 if(ev.getSource() == createMBeanButton) {
146 MBeanServerConnection connection =
147 ((ProxyClient) c).
148 getMBeanServerConnection();
149 connection.createMBean(HOTSPOT_MBEAN, null);
150 } else {
151 if(ev.getSource() == unregisterMBeanButton) {
152 MBeanServerConnection connection =
153 ((ProxyClient) c).
154 getMBeanServerConnection();
155 connection.unregisterMBean(new
156 ObjectName(HOTSPOT_MBEAN_OBJECTNAME));
157 }
158 }
159 return;
160 } catch(InstanceAlreadyExistsException e) {
161 statusBar.setText(Messages.ERROR_COLON_MBEANS_ALREADY_EXIST);
162 } catch(InstanceNotFoundException e) {
163 statusBar.setText(Messages.ERROR_COLON_MBEANS_DO_NOT_EXIST);
164 } catch(Exception e) {
165 statusBar.setText(e.toString());
166 }
167 setVisible(true);
168 }
169 }.start();
170 }
171 }
172
173 public void setVisible(boolean b) {
174 boolean wasVisible = isVisible();
175
176 if(b) {
177 setLocationRelativeTo(jConsole);
178 invalidate();
179 updateConnections();
180 validate();
181 repaint();
182 }
183
|