jdk/src/share/classes/sun/tools/jconsole/VMPanel.java
author egahlin
Fri, 25 May 2012 12:24:57 +0200
changeset 12851 3334e1c781d0
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7017818: NLS: JConsoleResources.java cannot be handled by translation team Reviewed-by: mchung, mfang
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     2
 * Copyright (c) 2004, 2008, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
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;
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.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    38
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.jconsole.JConsolePlugin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.jconsole.JConsoleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import static sun.tools.jconsole.ProxyClient.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class VMPanel extends JTabbedPane implements PropertyChangeListener {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    46
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private ProxyClient proxyClient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private Timer timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private int updateInterval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private String hostName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private String userName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private String password;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private String url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private VMInternalFrame vmIF = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static ArrayList<TabInfo> tabInfos = new ArrayList<TabInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private boolean wasConnected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // The everConnected flag keeps track of whether the window can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // closed if the user clicks Cancel after a failed connection attempt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private boolean everConnected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // The initialUpdate flag is used to enable/disable tabs each time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // a connect or reconnect takes place. This flag avoids having to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // enable/disable tabs on each update call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private boolean initialUpdate = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // Each VMPanel has its own instance of the JConsolePlugin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // A map of JConsolePlugin to the previous SwingWorker
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    72
    private Map<JConsolePlugin, SwingWorker<?, ?>> plugins = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private boolean pluginTabsAdded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    // Update these only on the EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private JOptionPane optionPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private JProgressBar progressBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private long time0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        tabInfos.add(new TabInfo(OverviewTab.class, OverviewTab.getTabName(), true));
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    82
        tabInfos.add(new TabInfo(MemoryTab.class, MemoryTab.getTabName(), true));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    83
        tabInfos.add(new TabInfo(ThreadTab.class, ThreadTab.getTabName(), true));
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    84
        tabInfos.add(new TabInfo(ClassTab.class, ClassTab.getTabName(), true));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        tabInfos.add(new TabInfo(SummaryTab.class, SummaryTab.getTabName(), true));
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    86
        tabInfos.add(new TabInfo(MBeansTab.class, MBeansTab.getTabName(), true));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static TabInfo[] getTabInfos() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return tabInfos.toArray(new TabInfo[tabInfos.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    VMPanel(ProxyClient proxyClient, int updateInterval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        this.proxyClient = proxyClient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this.updateInterval = updateInterval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this.hostName = proxyClient.getHostName();
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    97
        this.port = proxyClient.getPort();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.userName = proxyClient.getUserName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.password = proxyClient.getPassword();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.url = proxyClient.getUrl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        for (TabInfo tabInfo : tabInfos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (tabInfo.tabVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                addTab(tabInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   108
        plugins = new LinkedHashMap<JConsolePlugin, SwingWorker<?, ?>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        for (JConsolePlugin p : JConsole.getPlugins()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            p.setContext(proxyClient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            plugins.put(p, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        Utilities.updateTransparency(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        ToolTipManager.sharedInstance().registerComponent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // Start listening to connection state events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        proxyClient.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        addMouseListener(new MouseAdapter() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   123
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            public void mouseClicked(MouseEvent e) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   125
                if (connectedIconBounds != null && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0 && connectedIconBounds.contains(e.getPoint())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    if (isConnected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        wasConnected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static Icon connectedIcon16 =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   140
            new ImageIcon(VMPanel.class.getResource("resources/connected16.png"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static Icon connectedIcon24 =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   142
            new ImageIcon(VMPanel.class.getResource("resources/connected24.png"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static Icon disconnectedIcon16 =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   144
            new ImageIcon(VMPanel.class.getResource("resources/disconnected16.png"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static Icon disconnectedIcon24 =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   146
            new ImageIcon(VMPanel.class.getResource("resources/disconnected24.png"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private Rectangle connectedIconBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    // Override to increase right inset for tab area,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    // in order to reserve space for the connect toggle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public void setUI(TabbedPaneUI ui) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   152
        Insets insets = (Insets) UIManager.getLookAndFeelDefaults().get("TabbedPane.tabAreaInsets");
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   153
        insets = (Insets) insets.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        insets.right += connectedIcon24.getIconWidth() + 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        UIManager.put("TabbedPane.tabAreaInsets", insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    // Override to paint the connect toggle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Icon icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        Component c0 = getComponent(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (c0 != null && c0.getY() > 24) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            icon = isConnected() ? connectedIcon24 : disconnectedIcon24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            icon = isConnected() ? connectedIcon16 : disconnectedIcon16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        int x = getWidth() - insets.right - icon.getIconWidth() - 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        int y = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (c0 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            y = (c0.getY() - icon.getIconHeight()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        icon.paintIcon(this, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        connectedIconBounds = new Rectangle(x, y, icon.getIconWidth(), icon.getIconHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public String getToolTipText(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (connectedIconBounds.contains(event.getPoint())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (isConnected()) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   183
                return Messages.CONNECTED_PUNCTUATION_CLICK_TO_DISCONNECT_;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            } else {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   185
                return Messages.DISCONNECTED_PUNCTUATION_CLICK_TO_CONNECT_;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return super.getToolTipText(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private synchronized void addTab(TabInfo tabInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        Tab tab = instantiate(tabInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (tab != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            addTab(tabInfo.name, tab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            tabInfo.tabVisible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private synchronized void insertTab(TabInfo tabInfo, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        Tab tab = instantiate(tabInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (tab != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            insertTab(tabInfo.name, null, tab, null, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            tabInfo.tabVisible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public synchronized void removeTabAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        super.removeTabAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    private Tab instantiate(TabInfo tabInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        try {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   216
            Constructor<?> con = tabInfo.tabClass.getConstructor(VMPanel.class);
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   217
            return (Tab) con.newInstance(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            System.err.println(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    boolean isConnected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return proxyClient.isConnected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public int getUpdateInterval() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return updateInterval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * WARNING NEVER CALL THIS METHOD TO MAKE JMX REQUEST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * IF  assertThread == false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * DISPATCHER THREAD IS NOT ASSERTED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * IT IS USED TO MAKE SOME LOCAL MANIPULATIONS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    ProxyClient getProxyClient(boolean assertThread) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   239
        if (assertThread) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return getProxyClient();
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   241
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            return proxyClient;
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   243
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public ProxyClient getProxyClient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        String threadClass = Thread.currentThread().getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (threadClass.equals("java.awt.EventDispatchThread")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            String msg = "Calling VMPanel.getProxyClient() from the Event Dispatch Thread!";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            new RuntimeException(msg).printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return proxyClient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public void cleanUp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        //proxyClient.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        for (Tab tab : getTabs()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            tab.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        for (JConsolePlugin p : plugins.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            p.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // Cancel pending update tasks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (timer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            timer.cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // Stop listening to connection state events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        proxyClient.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    // Call on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public void connect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (isConnected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            // create plugin tabs if not done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            createPluginTabs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            // Notify tabs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            fireConnectedChange(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            // Enable/disable tabs on initial update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            initialUpdate = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            // Start/Restart update timer on connect/reconnect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            startUpdateTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            new Thread("VMPanel.connect") {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   287
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    proxyClient.connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            }.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    // Call on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public void disconnect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        proxyClient.disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        updateFrameTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    // Called on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void propertyChange(PropertyChangeEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        String prop = ev.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (prop == CONNECTION_STATE_PROPERTY) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   306
            ConnectionState oldState = (ConnectionState) ev.getOldValue();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   307
            ConnectionState newState = (ConnectionState) ev.getNewValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            switch (newState) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   309
                case CONNECTING:
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   310
                    onConnecting();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   311
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   313
                case CONNECTED:
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   314
                    if (progressBar != null) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   315
                        progressBar.setIndeterminate(false);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   316
                        progressBar.setValue(100);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   317
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   318
                    closeOptionPane();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   319
                    updateFrameTitle();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   320
                    // create tabs if not done
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   321
                    createPluginTabs();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   322
                    repaint();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   323
                    // Notify tabs
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   324
                    fireConnectedChange(true);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   325
                    // Enable/disable tabs on initial update
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   326
                    initialUpdate = true;
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   327
                    // Start/Restart update timer on connect/reconnect
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   328
                    startUpdateTimer();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   329
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   331
                case DISCONNECTED:
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   332
                    if (progressBar != null) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   333
                        progressBar.setIndeterminate(false);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   334
                        progressBar.setValue(0);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   335
                        closeOptionPane();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   336
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   337
                    vmPanelDied();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   338
                    if (oldState == ConnectionState.CONNECTED) {
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   339
                        // Notify tabs
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   340
                        fireConnectedChange(false);
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   341
                    }
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   342
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    // Called on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    private void onConnecting() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        time0 = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   351
        SwingUtilities.getWindowAncestor(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        String connectionName = getConnectionName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        progressBar = new JProgressBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        progressBar.setIndeterminate(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        JPanel progressPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        progressPanel.add(progressBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        Object[] message = {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   360
            "<html><h3>" + Resources.format(Messages.CONNECTING_TO1, connectionName) + "</h3></html>",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            progressPanel,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   362
            "<html><b>" + Resources.format(Messages.CONNECTING_TO2, connectionName) + "</b></html>"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        optionPane =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   366
                SheetDialog.showOptionDialog(this,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   367
                message,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   368
                JOptionPane.DEFAULT_OPTION,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   369
                JOptionPane.INFORMATION_MESSAGE, null,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   370
                new String[]{Messages.CANCEL},
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   371
                0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    // Called on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    private void closeOptionPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (optionPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            new Thread("VMPanel.sleeper") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    long elapsed = System.currentTimeMillis() - time0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    if (elapsed < 2000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                            sleep(2000 - elapsed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                        } catch (InterruptedException ex) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   386
                        // Ignore
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    SwingUtilities.invokeLater(new Runnable() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   390
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                            optionPane.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                            progressBar = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    void updateFrameTitle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        VMInternalFrame vmIF = getFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (vmIF != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            String displayName = getDisplayName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            if (!proxyClient.isConnected()) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   406
                displayName = Resources.format(Messages.CONNECTION_NAME__DISCONNECTED_, displayName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            vmIF.setTitle(displayName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    private VMInternalFrame getFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if (vmIF == null) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   414
            vmIF = (VMInternalFrame) SwingUtilities.getAncestorOfClass(VMInternalFrame.class,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   415
                    this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return vmIF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    // TODO: this method is not needed when all JConsole tabs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    // are migrated to use the new JConsolePlugin API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    // A thread safe clone of all JConsole tabs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    synchronized List<Tab> getTabs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        ArrayList<Tab> list = new ArrayList<Tab>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int n = getTabCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            Component c = getComponentAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            if (c instanceof Tab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                list.add((Tab) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    private void startUpdateTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (timer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            timer.cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        TimerTask timerTask = new TimerTask() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   441
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                update();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        };
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   446
        String timerName = "Timer-" + getConnectionName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        timer = new Timer(timerName, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        timer.schedule(timerTask, 0, updateInterval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    // Call on EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    private void vmPanelDied() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        disconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        JOptionPane optionPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        String msgTitle, msgExplanation, buttonStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (wasConnected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            wasConnected = false;
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   460
            msgTitle = Messages.CONNECTION_LOST1;
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   461
            msgExplanation = Resources.format(Messages.CONNECTING_TO2, getConnectionName());
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   462
            buttonStr = Messages.RECONNECT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        } else {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   464
            msgTitle =Messages.CONNECTION_FAILED1;
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   465
            msgExplanation = Resources.format(Messages.CONNECTION_FAILED2, getConnectionName());
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   466
            buttonStr = Messages.CONNECT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        optionPane =
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   470
                SheetDialog.showOptionDialog(this,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   471
                "<html><h3>" + msgTitle + "</h3>" +
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   472
                "<b>" + msgExplanation + "</b>",
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   473
                JOptionPane.DEFAULT_OPTION,
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   474
                JOptionPane.WARNING_MESSAGE, null,
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   475
                new String[]{buttonStr, Messages.CANCEL},
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   476
                0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   479
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    Object value = event.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   484
                    if (value == Messages.RECONNECT || value == Messages.CONNECT) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        connect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    } else if (!everConnected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                            getFrame().setClosed(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                        } catch (PropertyVetoException ex) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   490
                        // Should not happen, but can be ignored.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    // Note: This method is called on a TimerTask thread. Any GUI manipulation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    // must be performed with invokeLater() or invokeAndWait().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    private Object lockObject = new Object();
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   501
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    private void update() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   503
        synchronized (lockObject) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            if (!isConnected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                if (wasConnected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    EventQueue.invokeLater(new Runnable() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   507
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                            vmPanelDied();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                wasConnected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                wasConnected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                everConnected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            proxyClient.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            List<Tab> tabs = getTabs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            final int n = tabs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                final int index = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    if (!proxyClient.isDead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        // Update tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                        tabs.get(index).update();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                        // Enable tab on initial update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                        if (initialUpdate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                            EventQueue.invokeLater(new Runnable() {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   533
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                    setEnabledAt(index, true);
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
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    // Disable tab on initial update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    if (initialUpdate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                        EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                                setEnabledAt(index, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            // plugin GUI update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            for (JConsolePlugin p : plugins.keySet()) {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   555
                SwingWorker<?, ?> sw = p.newSwingWorker();
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   556
                SwingWorker<?, ?> prevSW = plugins.get(p);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                // schedule SwingWorker to run only if the previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                // SwingWorker has finished its task and it hasn't started.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                if (prevSW == null || prevSW.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    if (sw == null || sw.getState() == SwingWorker.StateValue.PENDING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                        plugins.put(p, sw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                        if (sw != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                            sw.execute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   569
            // Set the first enabled tab in the tab's list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            // as the selected tab on initial update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            if (initialUpdate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                        // Select first enabled tab if current tab isn't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                        int index = getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                        if (index < 0 || !isEnabledAt(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                                if (isEnabledAt(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                    setSelectedIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                initialUpdate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    public String getHostName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return hostName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public int getPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    public String getUserName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return userName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    public String getUrl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    public String getPassword() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return password;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    public String getConnectionName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return proxyClient.connectionName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public String getDisplayName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        return proxyClient.getDisplayName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    static class TabInfo {
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
   621
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        Class<? extends Tab> tabClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        boolean tabVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        TabInfo(Class<? extends Tab> tabClass, String name, boolean tabVisible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            this.tabClass = tabClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            this.tabVisible = tabVisible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    private void createPluginTabs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        // add plugin tabs if not done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        if (!pluginTabsAdded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            for (JConsolePlugin p : plugins.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                Map<String, JPanel> tabs = p.getTabs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                for (Map.Entry<String, JPanel> e : tabs.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    addTab(e.getKey(), e.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            pluginTabsAdded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    private void fireConnectedChange(boolean connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        for (Tab tab : getTabs()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            tab.firePropertyChange(JConsoleContext.CONNECTION_STATE_PROPERTY, !connected, connected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
}