src/jdk.jconsole/share/classes/sun/tools/jconsole/inspector/XMBeanAttributes.java
author vlivanov
Thu, 18 Jan 2018 02:25:18 +0300
changeset 48596 860326263d1f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194963: SystemDictionary::link_method_handle_constant() can't link MethodHandle.invoke()/invokeExact() Reviewed-by: kvn, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12851
diff changeset
     2
 * Copyright (c) 2004, 2012, 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: 1233
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: 1233
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: 1233
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1233
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1233
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.inspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    28
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.EventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Dimension;
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    32
import java.awt.event.MouseAdapter;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    33
import java.awt.event.MouseEvent;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    34
import java.io.IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    38
import java.util.EventObject;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    39
import java.util.HashMap;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    40
import java.util.WeakHashMap;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    41
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    42
import java.util.concurrent.ExecutionException;
42315
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
    43
import java.lang.System.Logger;
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
    44
import java.lang.System.Logger.Level;
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    45
import javax.management.JMException;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    46
import javax.management.MBeanInfo;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    47
import javax.management.MBeanAttributeInfo;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    48
import javax.management.AttributeList;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    49
import javax.management.Attribute;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.management.openmbean.TabularData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    53
import javax.swing.JComponent;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    54
import javax.swing.JOptionPane;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    55
import javax.swing.JTable;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    56
import javax.swing.JTextField;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    57
import javax.swing.SwingWorker;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    58
import javax.swing.event.ChangeEvent;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    59
import javax.swing.event.TableModelEvent;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    60
import javax.swing.event.TableModelListener;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    61
import javax.swing.table.DefaultTableCellRenderer;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    62
import javax.swing.table.DefaultTableModel;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    63
import javax.swing.table.TableCellEditor;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    64
import javax.swing.table.TableCellRenderer;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    65
import javax.swing.table.TableColumn;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    66
import javax.swing.table.TableColumnModel;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    67
import javax.swing.table.TableModel;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    68
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import sun.tools.jconsole.MBeansTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import sun.tools.jconsole.JConsole;
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    71
import sun.tools.jconsole.Messages;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import sun.tools.jconsole.ProxyClient.SnapshotMBeanServerConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/*IMPORTANT :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  There is a deadlock issue there if we don't synchronize well loadAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  refresh attributes and empty table methods since a UI thread can call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  loadAttributes and at the same time a JMX notification can raise an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  emptyTable. Since there are synchronization in the JMX world it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  COMPULSORY to not call the JMX world in synchronized blocks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
public class XMBeanAttributes extends XTable {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    82
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    83
    final Logger LOGGER =
42315
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
    84
            System.getLogger(XMBeanAttributes.class.getPackage().getName());
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    85
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private final static String[] columnNames =
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    87
    {Messages.NAME,
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
    88
     Messages.VALUE};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private XMBean mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private MBeanInfo mbeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private MBeanAttributeInfo[] attributesInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private HashMap<String, Object> attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private HashMap<String, Object> unavailableAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private HashMap<String, Object> viewableAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private WeakHashMap<XMBean, HashMap<String, ZoomedCell>> viewersCache =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            new WeakHashMap<XMBean, HashMap<String, ZoomedCell>>();
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
    98
    private final TableModelListener attributesListener;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private MBeansTab mbeansTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private TableCellEditor valueCellEditor = new ValueCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private int rowMinHeight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private AttributesMouseListener mouseListener = new AttributesMouseListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static TableCellEditor editor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            new Utils.ReadOnlyTableCellEditor(new JTextField());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public XMBeanAttributes(MBeansTab mbeansTab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        this.mbeansTab = mbeansTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        ((DefaultTableModel)getModel()).setColumnIdentifiers(columnNames);
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   111
        attributesListener = new AttributesListener(this);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   112
        getModel().addTableModelListener(attributesListener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        getColumnModel().getColumn(NAME_COLUMN).setPreferredWidth(40);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        addMouseListener(mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        getTableHeader().setReorderingAllowed(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        setColumnEditors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        addKeyListener(new Utils.CopyKeyAdapter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   121
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public synchronized Component prepareRenderer(TableCellRenderer renderer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                                  int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        //In case we have a repaint thread that is in the process of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        //repainting an obsolete table, just ignore the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        //It can happen when MBean selection is switched at a very quick rate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if(row >= getRowCount())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return super.prepareRenderer(renderer, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    void updateRowHeight(Object obj, int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        ZoomedCell cell = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if(obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            if(cell.isInited())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                setRowHeight(row, cell.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                if(rowMinHeight != - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    setRowHeight(row, rowMinHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if(rowMinHeight != - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                setRowHeight(row, rowMinHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   147
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public synchronized TableCellRenderer getCellRenderer(int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        //In case we have a repaint thread that is in the process of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        //repainting an obsolete table, just ignore the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        //It can happen when MBean selection is switched at a very quick rate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (row >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (column == VALUE_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                Object obj = getModel().getValueAt(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                if (obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    if (cell.isInited()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                        DefaultTableCellRenderer renderer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                (DefaultTableCellRenderer) cell.getRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                        renderer.setToolTipText(getToolTip(row,column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                        return renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                super.getCellRenderer(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (!isCellError(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                if (!(isColumnEditable(column) && isWritable(row) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                      Utils.isEditableType(getClassName(row)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    renderer.setForeground(getDefaultColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private void setColumnEditors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        TableColumnModel tcm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        for (int i = 0; i < columnNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            TableColumn tc = tcm.getColumn(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (isColumnEditable(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                tc.setCellEditor(valueCellEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                tc.setCellEditor(editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
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
    public void cancelCellEditing() {
42315
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
   193
        if (LOGGER.isLoggable(Level.TRACE)) {
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
   194
            LOGGER.log(Level.TRACE, "Cancel Editing Row: "+getEditingRow());
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   195
        }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   196
        final TableCellEditor tableCellEditor = getCellEditor();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   197
        if (tableCellEditor != null) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   198
            tableCellEditor.cancelCellEditing();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public void stopCellEditing() {
42315
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
   203
        if (LOGGER.isLoggable(Level.TRACE)) {
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
   204
            LOGGER.log(Level.TRACE, "Stop Editing Row: "+getEditingRow());
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   205
        }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   206
        final TableCellEditor tableCellEditor = getCellEditor();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   207
        if (tableCellEditor != null) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   208
            tableCellEditor.stopCellEditing();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   212
    @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   213
    public final boolean editCellAt(final int row, final int column, EventObject e) {
42315
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
   214
        if (LOGGER.isLoggable(Level.TRACE)) {
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
   215
            LOGGER.log(Level.TRACE, "editCellAt(row="+row+", col="+column+
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   216
                    ", e="+e+")");
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   217
        }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   218
        if (JConsole.isDebug()) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   219
            System.err.println("edit: "+getValueName(row)+"="+getValue(row));
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   220
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        boolean retVal = super.editCellAt(row, column, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (retVal) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   223
            final TableCellEditor tableCellEditor =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    getColumnModel().getColumn(column).getCellEditor();
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   225
            if (tableCellEditor == valueCellEditor) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   226
                ((JComponent) tableCellEditor).requestFocus();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public boolean isCellEditable(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        // All the cells in non-editable columns are editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (!isColumnEditable(col)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        // Maximized zoomed cells are editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Object obj = getModel().getValueAt(row, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            return cell.isMaximized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public void setValueAt(Object value, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (!isCellError(row, column) && isColumnEditable(column) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            isWritable(row) && Utils.isEditableType(getClassName(row))) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   251
            if (JConsole.isDebug()) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   252
                System.err.println("validating [row="+row+", column="+column+
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   253
                        "]: "+getValueName(row)+"="+value);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   254
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            super.setValueAt(value, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    //Table methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public boolean isTableEditable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public void setTableValue(Object value, int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public boolean isColumnEditable(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (column < getColumnCount()) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   270
            return getColumnName(column).equals(Messages.VALUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public String getClassName(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return attributesInfo[index].getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public String getValueName(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return attributesInfo[index].getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public Object getValue(int row) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   299
        final Object val = ((DefaultTableModel) getModel())
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   300
                .getValueAt(row, VALUE_COLUMN);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   301
        return val;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    //tool tip only for editable column
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   305
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public String getToolTip(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (isCellError(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return (String) unavailableAttributes.get(getValueName(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (isColumnEditable(column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            Object value = getValue(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            String tip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                tip = value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                if(isAttributeViewable(row, VALUE_COLUMN))
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   316
                    tip = Messages.DOUBLE_CLICK_TO_EXPAND_FORWARD_SLASH_COLLAPSE+
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        ". " + tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if(column == NAME_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                return attributesInfo[index].getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public synchronized boolean isWritable(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            return (attributesInfo[index].isWritable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Override JTable method in order to make any call to this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * atomic with TableModel elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   346
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public synchronized int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return super.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public synchronized boolean isReadable(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            return (attributesInfo[index].isReadable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public synchronized boolean isCellError(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return (isColumnEditable(col) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                (unavailableAttributes.containsKey(getValueName(row))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public synchronized boolean isAttributeViewable(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        boolean isViewable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if(col == VALUE_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            Object obj = getModel().getValueAt(row, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            if(obj instanceof ZoomedCell)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                isViewable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return isViewable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   377
    // Call this in EDT
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   378
    public void loadAttributes(final XMBean mbean, final MBeanInfo mbeanInfo) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   379
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   380
        final SwingWorker<Runnable,Void> load =
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   381
                new SwingWorker<Runnable,Void>() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   382
            @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   383
            protected Runnable doInBackground() throws Exception {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   384
                return doLoadAttributes(mbean,mbeanInfo);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   385
            }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   386
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   387
            @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   388
            protected void done() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   389
                try {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   390
                    final Runnable updateUI = get();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   391
                    if (updateUI != null) updateUI.run();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   392
                } catch (RuntimeException x) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   393
                    throw x;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   394
                } catch (ExecutionException x) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   395
                    if(JConsole.isDebug()) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   396
                       System.err.println(
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   397
                               "Exception raised while loading attributes: "
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   398
                               +x.getCause());
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   399
                       x.printStackTrace();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   400
                    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   401
                } catch (InterruptedException x) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   402
                    if(JConsole.isDebug()) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   403
                       System.err.println(
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   404
                            "Interrupted while loading attributes: "+x);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   405
                       x.printStackTrace();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   406
                    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   407
                }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   408
            }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   409
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   410
        };
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   411
        mbeansTab.workerAdd(load);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   412
    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   413
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   414
    // Don't call this in EDT, but execute returned Runnable inside
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   415
    // EDT - typically in the done() method of a SwingWorker
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   416
    // This method can return null.
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   417
    private Runnable doLoadAttributes(final XMBean mbean, MBeanInfo infoOrNull)
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   418
        throws JMException, IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        // To avoid deadlock with events coming from the JMX side,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        // we retrieve all JMX stuff in a non synchronized block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   422
        if(mbean == null) return null;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   423
        final MBeanInfo curMBeanInfo =
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   424
                (infoOrNull==null)?mbean.getMBeanInfo():infoOrNull;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   426
        final MBeanAttributeInfo[] attrsInfo = curMBeanInfo.getAttributes();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   427
        final HashMap<String, Object> attrs =
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   428
            new HashMap<String, Object>(attrsInfo.length);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   429
        final HashMap<String, Object> unavailableAttrs =
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   430
            new HashMap<String, Object>(attrsInfo.length);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   431
        final HashMap<String, Object> viewableAttrs =
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   432
            new HashMap<String, Object>(attrsInfo.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        AttributeList list = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        try {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   436
            list = mbean.getAttributes(attrsInfo);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   437
        }catch(Exception e) {
697
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   438
            if (JConsole.isDebug()) {
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   439
                System.err.println("Error calling getAttributes() on MBean \"" +
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   440
                                   mbean.getObjectName() + "\". JConsole will " +
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   441
                                   "try to get them individually calling " +
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   442
                                   "getAttribute() instead. Exception:");
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   443
                e.printStackTrace(System.err);
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   444
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            list = new AttributeList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            //Can't load all attributes, do it one after each other.
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   447
            for(int i = 0; i < attrsInfo.length; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                String name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                try {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   450
                    name = attrsInfo[i].getName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    Object value =
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   452
                        mbean.getMBeanServerConnection().
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   453
                        getAttribute(mbean.getObjectName(), name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    list.add(new Attribute(name, value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                }catch(Exception ex) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   456
                    if(attrsInfo[i].isReadable()) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   457
                        unavailableAttrs.put(name,
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   458
                                Utils.getActualException(ex).toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            int att_length = list.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            for (int i=0;i<att_length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                Attribute attribute = (Attribute) list.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                if(isViewable(attribute)) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   468
                    viewableAttrs.put(attribute.getName(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                           attribute.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                else
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   472
                    attrs.put(attribute.getName(),attribute.getValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            // if not all attributes are accessible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            // check them one after the other.
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   477
            if (att_length < attrsInfo.length) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   478
                for (int i=0;i<attrsInfo.length;i++) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   479
                    MBeanAttributeInfo attributeInfo = attrsInfo[i];
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   480
                    if (!attrs.containsKey(attributeInfo.getName()) &&
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   481
                        !viewableAttrs.containsKey(attributeInfo.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                                                        getName()) &&
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   483
                        !unavailableAttrs.containsKey(attributeInfo.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                                                           getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        if (attributeInfo.isReadable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                            // getAttributes didn't help resolving the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                            // exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                            // We must call it again to understand what
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                            // went wrong.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                Object v =
697
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   492
                                    mbean.getMBeanServerConnection().getAttribute(
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   493
                                    mbean.getObjectName(), attributeInfo.getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                //What happens if now it is ok?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                // Be pragmatic, add it to readable...
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   496
                                attrs.put(attributeInfo.getName(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                               v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                            }catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                                //Put the exception that will be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                // in tooltip
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   501
                                unavailableAttrs.put(attributeInfo.getName(),
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   502
                                        Utils.getActualException(e).toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            //sets all attributes unavailable except the writable ones
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   511
            for (int i=0;i<attrsInfo.length;i++) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   512
                MBeanAttributeInfo attributeInfo = attrsInfo[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                if (attributeInfo.isReadable()) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   514
                    unavailableAttrs.put(attributeInfo.getName(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                                              Utils.getActualException(e).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                              toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        //end of retrieval
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        //one update at a time
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   523
        return new Runnable() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   524
            public void run() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   525
                synchronized (XMBeanAttributes.this) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   526
                    XMBeanAttributes.this.mbean = mbean;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   527
                    XMBeanAttributes.this.mbeanInfo = curMBeanInfo;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   528
                    XMBeanAttributes.this.attributesInfo = attrsInfo;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   529
                    XMBeanAttributes.this.attributes = attrs;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   530
                    XMBeanAttributes.this.unavailableAttributes = unavailableAttrs;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   531
                    XMBeanAttributes.this.viewableAttributes = viewableAttrs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    DefaultTableModel tableModel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                            (DefaultTableModel) getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                    // add attribute information
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   537
                    emptyTable(tableModel);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    addTableData(tableModel,
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   540
                            mbean,
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   541
                            attrsInfo,
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   542
                            attrs,
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   543
                            unavailableAttrs,
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   544
                            viewableAttrs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    // update the model with the new data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    tableModel.newDataAvailable(new TableModelEvent(tableModel));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    // re-register for change events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    tableModel.addTableModelListener(attributesListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                }
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   551
            }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   552
        };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    void collapse(String attributeName, final Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        final int row = getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        Object obj = getModel().getValueAt(row, VALUE_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if(obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            cell.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            setRowHeight(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                         cell.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            editCellAt(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                       VALUE_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    ZoomedCell updateZoomedCell(int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        Object obj = getModel().getValueAt(row, VALUE_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        ZoomedCell cell = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        if(obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            if(!cell.isInited()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                Object elem = cell.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                String attributeName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    (String) getModel().getValueAt(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                                   NAME_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                Component comp = mbeansTab.getDataViewer().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                        createAttributeViewer(elem, mbean, attributeName, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                if(comp != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    if(rowMinHeight == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                        rowMinHeight = getRowHeight(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    cell.init(super.getCellRenderer(row, col),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                              comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                              rowMinHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   592
                    XDataViewer.registerForMouseEvent(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                            comp, mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    return cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            cell.switchState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            setRowHeight(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                         cell.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            if(!cell.isMaximized()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                //Back to simple editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                editCellAt(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                           VALUE_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        return cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   615
    // This is called by XSheet when the "refresh" button is pressed.
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   616
    // In this case we will commit any pending attribute values by
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   617
    // calling 'stopCellEditing'.
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   618
    //
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   619
    public void refreshAttributes() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   620
         refreshAttributes(true);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   621
    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   622
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   623
    // refreshAttributes(false) is called by tableChanged().
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   624
    // in this case we must not call stopCellEditing, because it's already
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   625
    // been called - e.g.
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   626
    // lostFocus/mousePressed -> stopCellEditing -> setValueAt -> tableChanged
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   627
    //                        -> refreshAttributes(false)
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   628
    //
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   629
    // Can be called in EDT - as long as the implementation of
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   630
    // mbeansTab.getCachedMBeanServerConnection() and mbsc.flush() doesn't
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   631
    // change
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   632
    //
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   633
    private void refreshAttributes(final boolean stopCellEditing) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   634
         SwingWorker<Void,Void> sw = new SwingWorker<Void,Void>() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   635
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   636
            @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   637
            protected Void doInBackground() throws Exception {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   638
                SnapshotMBeanServerConnection mbsc =
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   639
                mbeansTab.getSnapshotMBeanServerConnection();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   640
                mbsc.flush();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   641
                return null;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   642
            }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   643
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   644
            @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   645
            protected void done() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   646
                try {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   647
                    get();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   648
                    if (stopCellEditing) stopCellEditing();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   649
                    loadAttributes(mbean, mbeanInfo);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   650
                } catch (Exception x) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   651
                    if (JConsole.isDebug()) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   652
                        x.printStackTrace();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   653
                    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   654
                }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   655
            }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   656
         };
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   657
         mbeansTab.workerAdd(sw);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     }
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   659
    // We need to call stop editing here - otherwise edits are lost
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   660
    // when resizing the table.
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   661
    //
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   662
    @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   663
    public void columnMarginChanged(ChangeEvent e) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   664
        if (isEditing()) stopCellEditing();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   665
        super.columnMarginChanged(e);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   666
    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   667
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   668
    // We need to call stop editing here - otherwise the edited value
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   669
    // is transferred to the wrong row...
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   670
    //
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   671
    @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   672
    void sortRequested(int column) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   673
        if (isEditing()) stopCellEditing();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   674
        super.sortRequested(column);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   675
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   678
    @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   679
    public synchronized void emptyTable() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   680
         emptyTable((DefaultTableModel)getModel());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   683
    // Call this in synchronized block.
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   684
    private void emptyTable(DefaultTableModel model) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   685
         model.removeTableModelListener(attributesListener);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   686
         super.emptyTable();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   687
    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   688
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    private boolean isViewable(Attribute attribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        Object data = attribute.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        return XDataViewer.isViewableValue(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    synchronized void removeAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            attributes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        if (unavailableAttributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            unavailableAttributes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        if (viewableAttributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            viewableAttributes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        mbean = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    private ZoomedCell getZoomedCell(XMBean mbean, String attribute, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        synchronized (viewersCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            HashMap<String, ZoomedCell> viewers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if (viewersCache.containsKey(mbean)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                viewers = viewersCache.get(mbean);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                viewers = new HashMap<String, ZoomedCell>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            ZoomedCell cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            if (viewers.containsKey(attribute)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                cell = viewers.get(attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                cell.setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                if (cell.isMaximized() && cell.getType() != XDataViewer.NUMERIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                    // Plotters are the only viewers with auto update capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    // Other viewers need to be updated manually.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    Component comp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                        mbeansTab.getDataViewer().createAttributeViewer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                            value, mbean, attribute, XMBeanAttributes.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                    cell.init(cell.getMinRenderer(), comp, cell.getMinHeight());
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   727
                    XDataViewer.registerForMouseEvent(comp, mouseListener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                cell = new ZoomedCell(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                viewers.put(attribute, cell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            viewersCache.put(mbean, viewers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            return cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   738
    //will be called in a synchronized block
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    protected void addTableData(DefaultTableModel tableModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                XMBean mbean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                                MBeanAttributeInfo[] attributesInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                                HashMap<String, Object> attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                HashMap<String, Object> unavailableAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                                HashMap<String, Object> viewableAttributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        Object rowData[] = new Object[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        int col1Width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        int col2Width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        for (int i = 0; i < attributesInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            rowData[0] = (attributesInfo[i].getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            if (unavailableAttributes.containsKey(rowData[0])) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
   752
                rowData[1] = Messages.UNAVAILABLE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            } else if (viewableAttributes.containsKey(rowData[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                rowData[1] = viewableAttributes.get(rowData[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                if (!attributesInfo[i].isWritable() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                    !Utils.isEditableType(attributesInfo[i].getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                    rowData[1] = getZoomedCell(mbean, (String) rowData[0], rowData[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                rowData[1] = attributes.get(rowData[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            tableModel.addRow(rowData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            //Update column width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            String str = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            if(rowData[0] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                str = rowData[0].toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                if(str.length() > col1Width)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    col1Width = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            if(rowData[1] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                str = rowData[1].toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                if(str.length() > col2Width)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    col2Width = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        updateColumnWidth(col1Width, col2Width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    private void updateColumnWidth(int col1Width, int col2Width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        TableColumnModel colModel = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        //Get the column at index pColumn, and set its preferred width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        col1Width = col1Width * 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        col2Width = col2Width * 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if(col1Width + col2Width <
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
           (int) getPreferredScrollableViewportSize().getWidth())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            col2Width = (int) getPreferredScrollableViewportSize().getWidth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                - col1Width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        colModel.getColumn(NAME_COLUMN).setPreferredWidth(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    class AttributesMouseListener extends MouseAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   798
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            if(e.getButton() == MouseEvent.BUTTON1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                if(e.getClickCount() >= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                    int row = XMBeanAttributes.this.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                    int col = XMBeanAttributes.this.getSelectedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    if(col != VALUE_COLUMN) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                    if(col == -1 || row == -1) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                    XMBeanAttributes.this.updateZoomedCell(row, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    class ValueCellEditor extends XTextFieldEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        // implements javax.swing.table.TableCellEditor
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   816
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        public Component getTableCellEditorComponent(JTable table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                                                     Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                                                     boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                                                     int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                                                     int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            Object val = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            if(column == VALUE_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                Object obj = getModel().getValueAt(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                                                   column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                if(obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                    ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    if(cell.getRenderer() instanceof MaximizedCellRenderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                        MaximizedCellRenderer zr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                            (MaximizedCellRenderer) cell.getRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                        return zr.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    Component comp = super.getTableCellEditorComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                            table, val, isSelected, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    if (isCellError(row, column) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                        !isWritable(row) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                        !Utils.isEditableType(getClassName(row))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                        textField.setEditable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                    return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            return super.getTableCellEditorComponent(table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                                                     val,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                                                     isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                                                     row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                                                     column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        public boolean stopCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            int editingRow = getEditingRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            int editingColumn = getEditingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            if (editingColumn == VALUE_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                Object obj = getModel().getValueAt(editingRow, editingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                if (obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                    ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    if (cell.isMaximized()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                        this.cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            return super.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    class MaximizedCellRenderer extends  DefaultTableCellRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        MaximizedCellRenderer(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            this.comp = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            Dimension d = comp.getPreferredSize();
1233
3b08cf0cab53 6748745: JConsole: plotters don't resize well when the window is resized
dfuchs
parents: 1017
diff changeset
   873
            if (d.getHeight() > 220) {
3b08cf0cab53 6748745: JConsole: plotters don't resize well when the window is resized
dfuchs
parents: 1017
diff changeset
   874
                comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   877
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        public Component getTableCellRendererComponent(JTable table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                                                       Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                                                       boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                                                       boolean hasFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                                                       int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                                       int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        public Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    class ZoomedCell {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        TableCellRenderer minRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        MaximizedCellRenderer maxRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        int minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        boolean minimized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        boolean init = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        ZoomedCell(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            type = XDataViewer.getViewerType(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        boolean isInited() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            return init;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        void init(TableCellRenderer minRenderer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                  Component maxComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                  int minHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            this.minRenderer = minRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            this.maxRenderer = new MaximizedCellRenderer(maxComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            this.minHeight = minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            init = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            init = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            minimized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        void switchState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            minimized = !minimized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        boolean isMaximized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            return !minimized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        void minimize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            minimized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        void maximize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            minimized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            if(minimized) return minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                return (int) maxRenderer.getComponent().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                    getPreferredSize().getHeight() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        int getMinHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            return minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   960
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            if(value == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            if(value.getClass().isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                String name =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    Utils.getArrayClassName(value.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                int length = Array.getLength(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                return name + "[" + length +"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            if(value instanceof CompositeData ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
               value instanceof TabularData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                return value.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            return value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        TableCellRenderer getRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            if(minimized) return minRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            else return maxRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        TableCellRenderer getMinRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            return minRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    class AttributesListener implements  TableModelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        private Component component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        public AttributesListener(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            this.component = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
   997
        // Call this in EDT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        public void tableChanged(final TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            // only post changes to the draggable column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            if (isColumnEditable(e.getColumn())) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1001
                final TableModel model = (TableModel)e.getSource();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1002
                Object tableValue = model.getValueAt(e.getFirstRow(),
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1003
                                                 e.getColumn());
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1004
42315
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
  1005
                if (LOGGER.isLoggable(Level.TRACE)) {
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
  1006
                    LOGGER.log(Level.TRACE,
503b68f63f1e 8170401: JConsole might use System.Logger
dfuchs
parents: 25859
diff changeset
  1007
                        "tableChanged: firstRow="+e.getFirstRow()+
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1008
                        ", lastRow="+e.getLastRow()+", column="+e.getColumn()+
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1009
                        ", value="+tableValue);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1010
                }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1011
                // if it's a String, try construct new value
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1012
                // using the defined type.
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1013
                if (tableValue instanceof String) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1014
                    try {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1015
                        tableValue =
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1016
                            Utils.createObjectFromString(getClassName(e.getFirstRow()), // type
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1017
                            (String)tableValue);// value
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1018
                    } catch (Throwable ex) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1019
                        popupAndLog(ex,"tableChanged",
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
  1020
                                    Messages.PROBLEM_SETTING_ATTRIBUTE);
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1021
                    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1022
                }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1023
                final String attributeName = getValueName(e.getFirstRow());
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1024
                final Attribute attribute =
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1025
                      new Attribute(attributeName,tableValue);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1026
                setAttribute(attribute, "tableChanged");
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1027
            }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1028
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1030
        // Call this in EDT
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1031
        private void setAttribute(final Attribute attribute, final String method) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1032
            final SwingWorker<Void,Void> setAttribute =
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1033
                    new SwingWorker<Void,Void>() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1034
                @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1035
                protected Void doInBackground() throws Exception {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1036
                    try {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1037
                        if (JConsole.isDebug()) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1038
                            System.err.println("setAttribute("+
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1039
                                    attribute.getName()+
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1040
                                "="+attribute.getValue()+")");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                        }
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1042
                        mbean.setAttribute(attribute);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1043
                    } catch (Throwable ex) {
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
  1044
                        popupAndLog(ex,method,Messages.PROBLEM_SETTING_ATTRIBUTE);
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1045
                    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1046
                    return null;
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1047
                }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1048
                @Override
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1049
                protected void done() {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1050
                    try {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1051
                        get();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1052
                    } catch (Exception x) {
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1053
                        if (JConsole.isDebug())
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1054
                            x.printStackTrace();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1055
                    }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1056
                    refreshAttributes(false);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1057
                }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1058
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1059
            };
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1060
            mbeansTab.workerAdd(setAttribute);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1061
        }
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1062
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1063
        // Call this outside EDT
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
  1064
        private void popupAndLog(Throwable ex, String method, String title) {
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1065
            ex = Utils.getActualException(ex);
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1066
            if (JConsole.isDebug()) ex.printStackTrace();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1067
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1068
            String message = (ex.getMessage() != null) ? ex.getMessage()
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1069
                    : ex.toString();
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1070
            EventQueue.invokeLater(
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1071
                    new ThreadDialog(component, message+"\n",
12851
3334e1c781d0 7017818: NLS: JConsoleResources.java cannot be handled by translation team
egahlin
parents: 5506
diff changeset
  1072
                                     title,
1017
8d24d37ceed8 6733294: MBeans tab - UI issues with writable attributes
dfuchs
parents: 715
diff changeset
  1073
                                     JOptionPane.ERROR_MESSAGE));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
}