jdk/src/share/classes/sun/tools/jconsole/inspector/XSheet.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 55 5ecee29e98d8
child 1017 8d24d37ceed8
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 55
diff changeset
     2
 * Copyright 2004-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole.inspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.tree.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.tools.jconsole.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.tools.jconsole.inspector.XNodeInfo.Type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import static sun.tools.jconsole.Resources.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import static sun.tools.jconsole.Utilities.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class XSheet extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        implements ActionListener, NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private JPanel mainPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private JPanel southPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // Node being currently displayed
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    48
    private volatile DefaultMutableTreeNode currentNode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // MBean being currently displayed
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    50
    private volatile XMBean mbean;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // XMBeanAttributes container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private XMBeanAttributes mbeanAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // XMBeanOperations container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private XMBeanOperations mbeanOperations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // XMBeanNotifications container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private XMBeanNotifications mbeanNotifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // XMBeanInfo container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private XMBeanInfo mbeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // Refresh JButton (mbean attributes case)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private JButton refreshButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // Subscribe/Unsubscribe/Clear JButton (mbean notifications case)
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    62
    private JButton clearButton,  subscribeButton,  unsubscribeButton;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // Reference to MBeans tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private MBeansTab mbeansTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public XSheet(MBeansTab mbeansTab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this.mbeansTab = mbeansTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        setupScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        XDataViewer.dispose(mbeansTab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        mbeanNotifications.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private void setupScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        setLayout(new BorderLayout());
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    79
        setBorder(BorderFactory.createLineBorder(Color.GRAY));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // add main panel to XSheet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        mainPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        mainPanel.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        add(mainPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // add south panel to XSheet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        southPanel = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        add(southPanel, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // create the refresh button
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        String refreshButtonKey = "MBeansTab.refreshAttributesButton";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        refreshButton = new JButton(getText(refreshButtonKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        refreshButton.setMnemonic(getMnemonicInt(refreshButtonKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        refreshButton.setToolTipText(getText(refreshButtonKey + ".toolTip"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        refreshButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // create the clear button
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        String clearButtonKey = "MBeansTab.clearNotificationsButton";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        clearButton = new JButton(getText(clearButtonKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        clearButton.setMnemonic(getMnemonicInt(clearButtonKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        clearButton.setToolTipText(getText(clearButtonKey + ".toolTip"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        clearButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // create the subscribe button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        String subscribeButtonKey = "MBeansTab.subscribeNotificationsButton";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        subscribeButton = new JButton(getText(subscribeButtonKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        subscribeButton.setMnemonic(getMnemonicInt(subscribeButtonKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        subscribeButton.setToolTipText(getText(subscribeButtonKey + ".toolTip"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        subscribeButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // create the unsubscribe button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        String unsubscribeButtonKey = "MBeansTab.unsubscribeNotificationsButton";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        unsubscribeButton = new JButton(getText(unsubscribeButtonKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        unsubscribeButton.setMnemonic(getMnemonicInt(unsubscribeButtonKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        unsubscribeButton.setToolTipText(getText(unsubscribeButtonKey + ".toolTip"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        unsubscribeButton.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // create XMBeanAttributes container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        mbeanAttributes = new XMBeanAttributes(mbeansTab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // create XMBeanOperations container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        mbeanOperations = new XMBeanOperations(mbeansTab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        mbeanOperations.addOperationsListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // create XMBeanNotifications container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        mbeanNotifications = new XMBeanNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        mbeanNotifications.addNotificationsListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // create XMBeanInfo container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        mbeanInfo = new XMBeanInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   123
    private boolean isSelectedNode(DefaultMutableTreeNode n, DefaultMutableTreeNode cn) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   124
        return (cn == n);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   125
    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   126
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
    private void showErrorDialog(Object message, String title) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   129
        new ThreadDialog(this, message, title, JOptionPane.ERROR_MESSAGE).run();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   132
    public boolean isMBeanNode(DefaultMutableTreeNode node) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   133
        Object userObject = node.getUserObject();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   134
        if (userObject instanceof XNodeInfo) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   135
            XNodeInfo uo = (XNodeInfo) userObject;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   136
            return uo.getType().equals(Type.MBEAN);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   137
        }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   138
        return false;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   139
    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   140
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   141
    // Call on EDT
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   142
    public synchronized void displayNode(DefaultMutableTreeNode node) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        clear();
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   144
        displayEmptyNode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (node == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   148
        currentNode = node;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        Object userObject = node.getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (userObject instanceof XNodeInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            XNodeInfo uo = (XNodeInfo) userObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            switch (uo.getType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                case MBEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    displayMBeanNode(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                case NONMBEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    displayEmptyNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                case ATTRIBUTES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    displayMBeanAttributesNode(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                case OPERATIONS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    displayMBeanOperationsNode(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                case NOTIFICATIONS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    displayMBeanNotificationsNode(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                case ATTRIBUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                case OPERATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                case NOTIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    displayMetadataNode(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    displayEmptyNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            displayEmptyNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   182
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    private void displayMBeanNode(final DefaultMutableTreeNode node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        final XNodeInfo uo = (XNodeInfo) node.getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (!uo.getType().equals(Type.MBEAN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   188
        mbean = (XMBean) uo.getData();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   189
        SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   190
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   191
            public MBeanInfo doInBackground() throws InstanceNotFoundException,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   192
                    IntrospectionException, ReflectionException, IOException {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   193
                return mbean.getMBeanInfo();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   194
            }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   195
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   196
            protected void done() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                try {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   198
                    MBeanInfo mbi = get();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   199
                    if (mbi != null) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   200
                        if (!isSelectedNode(node, currentNode)) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   201
                            return;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   202
                        }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   203
                        mbeanInfo.addMBeanInfo(mbean, mbi);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                        mainPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                        mainPanel.add(mbeanInfo, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        southPanel.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        southPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                        validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   212
                } catch (Exception e) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   213
                    Throwable t = Utils.getActualException(e);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   214
                    if (JConsole.isDebug()) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   215
                        System.err.println("Couldn't get MBeanInfo for MBean [" +
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   216
                                mbean.getObjectName() + "]");
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   217
                        t.printStackTrace();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   218
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   219
                    showErrorDialog(t.toString(),
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   220
                            Resources.getText("Problem displaying MBean"));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   221
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   223
        };
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   224
        sw.execute();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    // Call on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private void displayMetadataNode(final DefaultMutableTreeNode node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        final XNodeInfo uo = (XNodeInfo) node.getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        final XMBeanInfo mbi = mbeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        switch (uo.getType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            case ATTRIBUTE:
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   233
                SwingWorker<MBeanAttributeInfo, Void> sw =
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   234
                        new SwingWorker<MBeanAttributeInfo, Void>() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   235
                            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   236
                            public MBeanAttributeInfo doInBackground() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   237
                                Object attrData = uo.getData();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   238
                                mbean = (XMBean) ((Object[]) attrData)[0];
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   239
                                MBeanAttributeInfo mbai =
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   240
                                        (MBeanAttributeInfo) ((Object[]) attrData)[1];
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   241
                                mbeanAttributes.loadAttributes(mbean, new MBeanInfo(
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   242
                                        null, null, new MBeanAttributeInfo[]{mbai},
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   243
                                        null, null, null));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   244
                                return mbai;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   246
                            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   247
                            protected void done() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   248
                                try {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   249
                                    MBeanAttributeInfo mbai = get();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   250
                                    if (!isSelectedNode(node, currentNode)) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   251
                                        return;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   252
                                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   253
                                    invalidate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   254
                                    mainPanel.removeAll();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   255
                                    JPanel attributePanel =
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   256
                                            new JPanel(new BorderLayout());
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   257
                                    JPanel attributeBorderPanel =
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   258
                                            new JPanel(new BorderLayout());
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   259
                                    attributeBorderPanel.setBorder(
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   260
                                            BorderFactory.createTitledBorder(
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   261
                                            Resources.getText("Attribute value")));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   262
                                    JPanel attributeValuePanel =
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   263
                                            new JPanel(new BorderLayout());
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   264
                                    attributeValuePanel.setBorder(
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   265
                                            LineBorder.createGrayLineBorder());
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   266
                                    attributeValuePanel.add(mbeanAttributes.getTableHeader(),
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   267
                                            BorderLayout.PAGE_START);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   268
                                    attributeValuePanel.add(mbeanAttributes,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   269
                                            BorderLayout.CENTER);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   270
                                    attributeBorderPanel.add(attributeValuePanel,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   271
                                            BorderLayout.CENTER);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   272
                                    JPanel refreshButtonPanel = new JPanel();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   273
                                    refreshButtonPanel.add(refreshButton);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   274
                                    attributeBorderPanel.add(refreshButtonPanel,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   275
                                            BorderLayout.SOUTH);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   276
                                    refreshButton.setEnabled(true);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   277
                                    attributePanel.add(attributeBorderPanel,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   278
                                            BorderLayout.NORTH);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   279
                                    mbi.addMBeanAttributeInfo(mbai);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   280
                                    attributePanel.add(mbi, BorderLayout.CENTER);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   281
                                    mainPanel.add(attributePanel,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   282
                                            BorderLayout.CENTER);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   283
                                    southPanel.setVisible(false);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   284
                                    southPanel.removeAll();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   285
                                    validate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   286
                                    repaint();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   287
                                } catch (Exception e) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   288
                                    Throwable t = Utils.getActualException(e);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   289
                                    if (JConsole.isDebug()) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   290
                                        System.err.println("Problem displaying MBean " +
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   291
                                                "attribute for MBean [" +
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   292
                                                mbean.getObjectName() + "]");
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   293
                                        t.printStackTrace();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   294
                                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   295
                                    showErrorDialog(t.toString(),
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   296
                                            Resources.getText("Problem displaying MBean"));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   297
                                }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   298
                            }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   299
                        };
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   300
                sw.execute();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            case OPERATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                Object operData = uo.getData();
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   304
                mbean = (XMBean) ((Object[]) operData)[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                MBeanOperationInfo mboi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        (MBeanOperationInfo) ((Object[]) operData)[1];
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   307
                mbeanOperations.loadOperations(mbean,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   308
                        new MBeanInfo(null, null, null, null,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   309
                        new MBeanOperationInfo[]{mboi}, null));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                mainPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                JPanel operationPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                JPanel operationBorderPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                operationBorderPanel.setBorder(BorderFactory.createTitledBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        Resources.getText("Operation invocation")));
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   316
                operationBorderPanel.add(new JScrollPane(mbeanOperations));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                operationPanel.add(operationBorderPanel, BorderLayout.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                mbi.addMBeanOperationInfo(mboi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                operationPanel.add(mbi, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                mainPanel.add(operationPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                southPanel.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                southPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            case NOTIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                Object notifData = uo.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                mainPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                mbi.addMBeanNotificationInfo((MBeanNotificationInfo) notifData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                mainPanel.add(mbi, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                southPanel.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                southPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   340
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    private void displayMBeanAttributesNode(final DefaultMutableTreeNode node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        final XNodeInfo uo = (XNodeInfo) node.getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (!uo.getType().equals(Type.ATTRIBUTES)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   346
        mbean = (XMBean) uo.getData();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   347
        SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   348
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   349
            public Void doInBackground() throws InstanceNotFoundException,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   350
                    IntrospectionException, ReflectionException, IOException {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   351
                mbeanAttributes.loadAttributes(mbean, mbean.getMBeanInfo());
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   352
                return null;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   353
            }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   354
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   355
            protected void done() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                try {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   357
                    get();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   358
                    if (!isSelectedNode(node, currentNode)) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   359
                        return;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   360
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   361
                    invalidate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   362
                    mainPanel.removeAll();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   363
                    JPanel borderPanel = new JPanel(new BorderLayout());
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   364
                    borderPanel.setBorder(BorderFactory.createTitledBorder(
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   365
                            Resources.getText("Attribute values")));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   366
                    borderPanel.add(new JScrollPane(mbeanAttributes));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   367
                    mainPanel.add(borderPanel, BorderLayout.CENTER);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   368
                    // add the refresh button to the south panel
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   369
                    southPanel.removeAll();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   370
                    southPanel.add(refreshButton, BorderLayout.SOUTH);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   371
                    southPanel.setVisible(true);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   372
                    refreshButton.setEnabled(true);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   373
                    validate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   374
                    repaint();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   375
                } catch (Exception e) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   376
                    Throwable t = Utils.getActualException(e);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   377
                    if (JConsole.isDebug()) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   378
                        System.err.println("Problem displaying MBean " +
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   379
                                "attributes for MBean [" +
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   380
                                mbean.getObjectName() + "]");
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   381
                        t.printStackTrace();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   382
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   383
                    showErrorDialog(t.toString(),
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   384
                            Resources.getText("Problem displaying MBean"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   387
        };
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   388
        sw.execute();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   391
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    private void displayMBeanOperationsNode(final DefaultMutableTreeNode node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        final XNodeInfo uo = (XNodeInfo) node.getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (!uo.getType().equals(Type.OPERATIONS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   397
        mbean = (XMBean) uo.getData();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   398
        SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   399
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   400
            public MBeanInfo doInBackground() throws InstanceNotFoundException,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   401
                    IntrospectionException, ReflectionException, IOException {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   402
                return mbean.getMBeanInfo();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   403
            }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   404
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   405
            protected void done() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                try {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   407
                    MBeanInfo mbi = get();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   408
                    if (mbi != null) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   409
                        if (!isSelectedNode(node, currentNode)) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   410
                            return;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   411
                        }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   412
                        mbeanOperations.loadOperations(mbean, mbi);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        mainPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                        JPanel borderPanel = new JPanel(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        borderPanel.setBorder(BorderFactory.createTitledBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                                Resources.getText("Operation invocation")));
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   418
                        borderPanel.add(new JScrollPane(mbeanOperations));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                        mainPanel.add(borderPanel, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        southPanel.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                        southPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   425
                } catch (Exception e) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   426
                    Throwable t = Utils.getActualException(e);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   427
                    if (JConsole.isDebug()) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   428
                        System.err.println("Problem displaying MBean " +
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   429
                                "operations for MBean [" +
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   430
                                mbean.getObjectName() + "]");
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   431
                        t.printStackTrace();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   432
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   433
                    showErrorDialog(t.toString(),
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   434
                            Resources.getText("Problem displaying MBean"));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   435
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   437
        };
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   438
        sw.execute();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   441
    // Call on EDT
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   442
    private void displayMBeanNotificationsNode(DefaultMutableTreeNode node) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        final XNodeInfo uo = (XNodeInfo) node.getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (!uo.getType().equals(Type.NOTIFICATIONS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   447
        mbean = (XMBean) uo.getData();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   448
        mbeanNotifications.loadNotifications(mbean);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   449
        updateNotifications();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   450
        invalidate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   451
        mainPanel.removeAll();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   452
        JPanel borderPanel = new JPanel(new BorderLayout());
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   453
        borderPanel.setBorder(BorderFactory.createTitledBorder(
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   454
                Resources.getText("Notification buffer")));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   455
        borderPanel.add(new JScrollPane(mbeanNotifications));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   456
        mainPanel.add(borderPanel, BorderLayout.CENTER);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   457
        // add the subscribe/unsubscribe/clear buttons to the south panel
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   458
        southPanel.removeAll();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   459
        southPanel.add(subscribeButton, BorderLayout.WEST);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   460
        southPanel.add(unsubscribeButton, BorderLayout.CENTER);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   461
        southPanel.add(clearButton, BorderLayout.EAST);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   462
        southPanel.setVisible(true);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   463
        subscribeButton.setEnabled(true);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   464
        unsubscribeButton.setEnabled(true);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   465
        clearButton.setEnabled(true);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   466
        validate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   467
        repaint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    // Call on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    private void displayEmptyNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        mainPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        southPanel.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * Subscribe button action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   482
    private void registerListener() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   483
        new SwingWorker<Void, Void>() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   484
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   485
            public Void doInBackground()
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   486
                    throws InstanceNotFoundException, IOException {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   487
                mbeanNotifications.registerListener(currentNode);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   488
                return null;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   489
            }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   490
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   491
            protected void done() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   492
                try {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   493
                    get();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   494
                    updateNotifications();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   495
                    validate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   496
                } catch (Exception e) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   497
                    Throwable t = Utils.getActualException(e);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   498
                    if (JConsole.isDebug()) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   499
                        System.err.println("Problem adding listener");
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   500
                        t.printStackTrace();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   501
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   502
                    showErrorDialog(t.getMessage(),
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   503
                            Resources.getText("Problem adding listener"));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   504
                }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   505
            }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   506
        }.execute();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Unsubscribe button action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    private void unregisterListener() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   513
        new SwingWorker<Boolean, Void>() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   514
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   515
            public Boolean doInBackground() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   516
                return mbeanNotifications.unregisterListener(currentNode);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   517
            }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   518
            @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   519
            protected void done() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   520
                try {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   521
                    if (get()) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   522
                        updateNotifications();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   523
                        validate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   524
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   525
                } catch (Exception e) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   526
                    Throwable t = Utils.getActualException(e);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   527
                    if (JConsole.isDebug()) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   528
                        System.err.println("Problem removing listener");
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   529
                        t.printStackTrace();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   530
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   531
                    showErrorDialog(t.getMessage(),
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   532
                            Resources.getText("Problem removing listener"));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   533
                }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   534
            }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   535
        }.execute();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * Refresh button action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    private void refreshAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        mbeanAttributes.refreshAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   545
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    private void updateNotifications() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   547
        if (mbeanNotifications.isListenerRegistered(mbean)) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   548
            long received = mbeanNotifications.getReceivedNotifications(mbean);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   549
            updateReceivedNotifications(currentNode, received, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            clearNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * Update notification node label in MBean tree: "Notifications[received]".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   558
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    private void updateReceivedNotifications(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            DefaultMutableTreeNode emitter, long received, boolean bold) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        String text = Resources.getText("Notifications") + "[" + received + "]";
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   562
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) mbeansTab.getTree().getLastSelectedPathComponent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (bold && emitter != selectedNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            text = "<html><b>" + text + "</b></html>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        updateNotificationsNodeLabel(emitter, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * Update notification node label in MBean tree: "Notifications".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   572
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    private void clearNotifications() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   574
        updateNotificationsNodeLabel(currentNode,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                Resources.getText("Notifications"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Update notification node label in MBean tree: "Notifications[0]".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     */
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   581
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    private void clearNotifications0() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   583
        updateNotificationsNodeLabel(currentNode,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                Resources.getText("Notifications") + "[0]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Update the label of the supplied MBean tree node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     */
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   590
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    private void updateNotificationsNodeLabel(
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   592
            DefaultMutableTreeNode node, String label) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   593
        synchronized (mbeansTab.getTree()) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   594
            invalidate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   595
            XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   596
            XNodeInfo newUserObject = new XNodeInfo(
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   597
                    oldUserObject.getType(), oldUserObject.getData(),
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   598
                    label, oldUserObject.getToolTipText());
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   599
            node.setUserObject(newUserObject);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   600
            DefaultTreeModel model =
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   601
                    (DefaultTreeModel) mbeansTab.getTree().getModel();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   602
            model.nodeChanged(node);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   603
            validate();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   604
            repaint();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   605
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * Clear button action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    // Call on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    private void clearCurrentNotifications() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        mbeanNotifications.clearCurrentNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        if (mbeanNotifications.isListenerRegistered(mbean)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            // Update notifs in MBean tree "Notifications[0]".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            // Notification buffer has been cleared with a listener been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            // registered so add "[0]" at the end of the node label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            clearNotifications0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            // Update notifs in MBean tree "Notifications".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            // Notification buffer has been cleared without a listener been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            // registered so don't add "[0]" at the end of the node label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            clearNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   631
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    private void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        mbeanAttributes.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        mbeanAttributes.emptyTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        mbeanAttributes.removeAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        mbeanOperations.removeOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        mbeanNotifications.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        mbeanNotifications.emptyTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        mbeanNotifications.disableNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        mbean = null;
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   641
        currentNode = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * Notification listener: handles asynchronous reception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * of MBean operation results and MBean notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     */
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   648
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    public void handleNotification(Notification e, Object handback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        // Operation result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        if (e.getType().equals(XOperations.OPERATION_INVOCATION_EVENT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            final Object message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            if (handback == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                JTextArea textArea = new JTextArea("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                textArea.setEditable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                textArea.setEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                textArea.setRows(textArea.getLineCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                message = textArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                Component comp = mbeansTab.getDataViewer().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                        createOperationViewer(handback, mbean);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                if (comp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                    JTextArea textArea = new JTextArea(handback.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                    textArea.setEditable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                    textArea.setEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    textArea.setRows(textArea.getLineCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    JScrollPane scrollPane = new JScrollPane(textArea);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                    Dimension d = scrollPane.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    if (d.getWidth() > 400 || d.getHeight() > 250) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                        scrollPane.setPreferredSize(new Dimension(400, 250));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    message = scrollPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    if (!(comp instanceof JScrollPane)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                        comp = new JScrollPane(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    Dimension d = comp.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    if (d.getWidth() > 400 || d.getHeight() > 250) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                        comp.setPreferredSize(new Dimension(400, 250));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    message = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   684
            new ThreadDialog(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    (Component) e.getSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    Resources.getText("Operation return value"),
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   688
                    JOptionPane.INFORMATION_MESSAGE).run();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   689
        } // Got notification
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        else if (e.getType().equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                XMBeanNotifications.NOTIFICATION_RECEIVED_EVENT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            DefaultMutableTreeNode emitter = (DefaultMutableTreeNode) handback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            Long received = (Long) e.getUserData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            updateReceivedNotifications(emitter, received.longValue(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Action listener: handles actions in panel buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     */
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   701
    // Call on EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (e.getSource() instanceof JButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            JButton button = (JButton) e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            // Refresh button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            if (button == refreshButton) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   707
                new SwingWorker<Void, Void>() {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   708
                    @Override
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   709
                    public Void doInBackground() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                        refreshAttributes();
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   711
                        return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    }
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   713
                }.execute();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            // Clear button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            if (button == clearButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                clearCurrentNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            // Subscribe button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            if (button == subscribeButton) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   723
                registerListener();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            // Unsubscribe button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            if (button == unsubscribeButton) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   728
                unregisterListener();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
}