jdk/src/share/classes/sun/tools/jconsole/inspector/XMBeanAttributes.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 697 fb86c99b92a2
child 1017 8d24d37ceed8
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 697
diff changeset
     2
 * Copyright 2004-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole.inspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.table.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.tree.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.GridLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.FlowLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.EventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.openmbean.CompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.openmbean.TabularData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.tools.jconsole.Resources;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.tools.jconsole.MBeansTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.tools.jconsole.Plotter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.tools.jconsole.JConsole;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.tools.jconsole.ProxyClient.SnapshotMBeanServerConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/*IMPORTANT :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  There is a deadlock issue there if we don't synchronize well loadAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  refresh attributes and empty table methods since a UI thread can call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  loadAttributes and at the same time a JMX notification can raise an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  emptyTable. Since there are synchronization in the JMX world it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  COMPULSORY to not call the JMX world in synchronized blocks */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class XMBeanAttributes extends XTable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private final static String[] columnNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    {Resources.getText("Name"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     Resources.getText("Value")};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private boolean editable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private XMBean mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private MBeanInfo mbeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private MBeanAttributeInfo[] attributesInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private HashMap<String, Object> attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private HashMap<String, Object> unavailableAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private HashMap<String, Object> viewableAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private WeakHashMap<XMBean, HashMap<String, ZoomedCell>> viewersCache =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            new WeakHashMap<XMBean, HashMap<String, ZoomedCell>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private TableModelListener attributesListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private MBeansTab mbeansTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private XTable table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private TableCellEditor valueCellEditor = new ValueCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private int rowMinHeight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private AttributesMouseListener mouseListener = new AttributesMouseListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static TableCellEditor editor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            new Utils.ReadOnlyTableCellEditor(new JTextField());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public XMBeanAttributes(MBeansTab mbeansTab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        this.mbeansTab = mbeansTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        ((DefaultTableModel)getModel()).setColumnIdentifiers(columnNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        getModel().addTableModelListener(attributesListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                         new AttributesListener(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        getColumnModel().getColumn(NAME_COLUMN).setPreferredWidth(40);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        addMouseListener(mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        getTableHeader().setReorderingAllowed(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        setColumnEditors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        addKeyListener(new Utils.CopyKeyAdapter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public synchronized Component prepareRenderer(TableCellRenderer renderer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                                  int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        //In case we have a repaint thread that is in the process of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        //repainting an obsolete table, just ignore the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        //It can happen when MBean selection is switched at a very quick rate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if(row >= getRowCount())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            return super.prepareRenderer(renderer, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    void updateRowHeight(Object obj, int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        ZoomedCell cell = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if(obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            if(cell.isInited())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                setRowHeight(row, cell.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                if(rowMinHeight != - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    setRowHeight(row, rowMinHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if(rowMinHeight != - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                setRowHeight(row, rowMinHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public synchronized TableCellRenderer getCellRenderer(int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        //In case we have a repaint thread that is in the process of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        //repainting an obsolete table, just ignore the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        //It can happen when MBean selection is switched at a very quick rate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (row >= getRowCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            if (column == VALUE_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                Object obj = getModel().getValueAt(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                if (obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    if (cell.isInited()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        DefaultTableCellRenderer renderer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                (DefaultTableCellRenderer) cell.getRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        renderer.setToolTipText(getToolTip(row,column));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        return renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                super.getCellRenderer(row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            if (!isCellError(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                if (!(isColumnEditable(column) && isWritable(row) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                      Utils.isEditableType(getClassName(row)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    renderer.setForeground(getDefaultColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return renderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private void setColumnEditors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        TableColumnModel tcm = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        for (int i = 0; i < columnNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            TableColumn tc = tcm.getColumn(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            if (isColumnEditable(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                tc.setCellEditor(valueCellEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                tc.setCellEditor(editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public void cancelCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            editor.cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public void stopCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        TableCellEditor editor = getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (editor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            editor.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public final boolean editCellAt(int row, int column, EventObject e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        boolean retVal = super.editCellAt(row, column, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (retVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            TableCellEditor editor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    getColumnModel().getColumn(column).getCellEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            if (editor == valueCellEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                ((JComponent) editor).requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return retVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public boolean isCellEditable(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // All the cells in non-editable columns are editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (!isColumnEditable(col)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        // Maximized zoomed cells are editable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        Object obj = getModel().getValueAt(row, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return cell.isMaximized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public void setValueAt(Object value, int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (!isCellError(row, column) && isColumnEditable(column) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            isWritable(row) && Utils.isEditableType(getClassName(row))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            super.setValueAt(value, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    //Table methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public boolean isTableEditable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public void setTableValue(Object value, int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public boolean isColumnEditable(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (column < getColumnCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return getColumnName(column).equals(Resources.getText("Value"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public String getClassName(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return attributesInfo[index].getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public String getValueName(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return attributesInfo[index].getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            return null;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public Object getValue(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return ((DefaultTableModel) getModel()).getValueAt(row, VALUE_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    //tool tip only for editable column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public String getToolTip(int row, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (isCellError(row, column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return (String) unavailableAttributes.get(getValueName(row));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (isColumnEditable(column)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            Object value = getValue(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            String tip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                tip = value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                if(isAttributeViewable(row, VALUE_COLUMN))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    tip = Resources.getText("Double click to expand/collapse")+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                        ". " + tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return tip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if(column == NAME_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                return attributesInfo[index].getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public synchronized boolean isWritable(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            return (attributesInfo[index].isWritable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Override JTable method in order to make any call to this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * atomic with TableModel elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public synchronized int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return super.getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public synchronized boolean isReadable(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        int index = convertRowToIndex(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return (attributesInfo[index].isReadable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public synchronized boolean isCellError(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return (isColumnEditable(col) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                (unavailableAttributes.containsKey(getValueName(row))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public synchronized boolean isAttributeViewable(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        boolean isViewable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if(col == VALUE_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            Object obj = getModel().getValueAt(row, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if(obj instanceof ZoomedCell)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                isViewable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return isViewable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public void loadAttributes(final XMBean mbean, MBeanInfo mbeanInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        // To avoid deadlock with events coming from the JMX side,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        // we retrieve all JMX stuff in a non synchronized block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if(mbean == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        final MBeanAttributeInfo[] attributesInfo = mbeanInfo.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        final HashMap<String, Object> attributes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            new HashMap<String, Object>(attributesInfo.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        final HashMap<String, Object> unavailableAttributes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            new HashMap<String, Object>(attributesInfo.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        final HashMap<String, Object> viewableAttributes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            new HashMap<String, Object>(attributesInfo.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        AttributeList list = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            list = mbean.getAttributes(attributesInfo);
697
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   352
        } catch (Exception e) {
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   353
            if (JConsole.isDebug()) {
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   354
                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
   355
                                   mbean.getObjectName() + "\". JConsole will " +
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   356
                                   "try to get them individually calling " +
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   357
                                   "getAttribute() instead. Exception:");
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   358
                e.printStackTrace(System.err);
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   359
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            list = new AttributeList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            //Can't load all attributes, do it one after each other.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            for(int i = 0; i < attributesInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                String name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    name = attributesInfo[i].getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    Object value =
697
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   367
                        mbean.getMBeanServerConnection().getAttribute(mbean.getObjectName(), name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    list.add(new Attribute(name, value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                }catch(Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    if(attributesInfo[i].isReadable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                        unavailableAttributes.put(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                                  Utils.getActualException(ex).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                                  toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            int att_length = list.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            for (int i=0;i<att_length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                Attribute attribute = (Attribute) list.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                if(isViewable(attribute)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    viewableAttributes.put(attribute.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                           attribute.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    attributes.put(attribute.getName(),attribute.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            // if not all attributes are accessible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            // check them one after the other.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (att_length < attributesInfo.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                for (int i=0;i<attributesInfo.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    MBeanAttributeInfo attributeInfo = attributesInfo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    if (!attributes.containsKey(attributeInfo.getName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                        !viewableAttributes.containsKey(attributeInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                                        getName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                        !unavailableAttributes.containsKey(attributeInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                                           getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                        if (attributeInfo.isReadable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                            // getAttributes didn't help resolving the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                            // exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                            // We must call it again to understand what
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                            // went wrong.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                Object v =
697
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   407
                                    mbean.getMBeanServerConnection().getAttribute(
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   408
                                    mbean.getObjectName(), attributeInfo.getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                //What happens if now it is ok?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                                // Be pragmatic, add it to readable...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                                attributes.put(attributeInfo.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                                               v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                            }catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                                //Put the exception that will be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                // in tooltip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                                unavailableAttributes.put(attributeInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                                                          getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                                                          Utils.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                                          getActualException(e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                                                          .toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            //sets all attributes unavailable except the writable ones
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            for (int i=0;i<attributesInfo.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                MBeanAttributeInfo attributeInfo = attributesInfo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                if (attributeInfo.isReadable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    unavailableAttributes.put(attributeInfo.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                              Utils.getActualException(e).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                              toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        //end of retrieval
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        //one update at a time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            this.mbean = mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            this.mbeanInfo = mbeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            this.attributesInfo = attributesInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            this.attributes = attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            this.unavailableAttributes = unavailableAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            this.viewableAttributes = viewableAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    DefaultTableModel tableModel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                            (DefaultTableModel) getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    // don't listen to these events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    tableModel.removeTableModelListener(attributesListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    // add attribute information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    emptyTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    addTableData(tableModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                 mbean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                 attributesInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                 attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                 unavailableAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                 viewableAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    // update the model with the new data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    tableModel.newDataAvailable(new TableModelEvent(tableModel));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    // re-register for change events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    tableModel.addTableModelListener(attributesListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    void collapse(String attributeName, final Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        final int row = getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        Object obj = getModel().getValueAt(row, VALUE_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if(obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            cell.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            setRowHeight(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                         cell.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            editCellAt(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                       VALUE_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    ZoomedCell updateZoomedCell(int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        Object obj = getModel().getValueAt(row, VALUE_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        ZoomedCell cell = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if(obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            if(!cell.isInited()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                Object elem = cell.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                String attributeName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    (String) getModel().getValueAt(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                                                   NAME_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                Component comp = mbeansTab.getDataViewer().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                        createAttributeViewer(elem, mbean, attributeName, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                if(comp != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    if(rowMinHeight == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                        rowMinHeight = getRowHeight(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    cell.init(super.getCellRenderer(row, col),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                              comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                              rowMinHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    mbeansTab.getDataViewer().registerForMouseEvent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                            comp, mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    return cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            cell.switchState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            setRowHeight(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                         cell.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            if(!cell.isMaximized()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                //Back to simple editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                editCellAt(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                           VALUE_COLUMN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     public void refreshAttributes() {
697
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   538
         SnapshotMBeanServerConnection mbsc = mbeansTab.getSnapshotMBeanServerConnection();
fb86c99b92a2 6711106: REGRESSION: Bad usage of SnapshotMBeanServerConnection in MBeans tab and JConsole plugins.
lmalvent
parents: 2
diff changeset
   539
         mbsc.flush();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         loadAttributes(mbean, mbeanInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     public void emptyTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
             ((DefaultTableModel) getModel()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                 removeTableModelListener(attributesListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
             super.emptyTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    private boolean isViewable(Attribute attribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        Object data = attribute.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        return XDataViewer.isViewableValue(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    synchronized void removeAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            attributes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (unavailableAttributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            unavailableAttributes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        if (viewableAttributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            viewableAttributes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        mbean = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    private ZoomedCell getZoomedCell(XMBean mbean, String attribute, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        synchronized (viewersCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            HashMap<String, ZoomedCell> viewers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            if (viewersCache.containsKey(mbean)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                viewers = viewersCache.get(mbean);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                viewers = new HashMap<String, ZoomedCell>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            ZoomedCell cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            if (viewers.containsKey(attribute)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                cell = viewers.get(attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                cell.setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                if (cell.isMaximized() && cell.getType() != XDataViewer.NUMERIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    // Plotters are the only viewers with auto update capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    // Other viewers need to be updated manually.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    Component comp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                        mbeansTab.getDataViewer().createAttributeViewer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                            value, mbean, attribute, XMBeanAttributes.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    cell.init(cell.getMinRenderer(), comp, cell.getMinHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    mbeansTab.getDataViewer().registerForMouseEvent(comp, mouseListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                cell = new ZoomedCell(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                viewers.put(attribute, cell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            viewersCache.put(mbean, viewers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            return cell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    //will be called in a synchronzed block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    protected void addTableData(DefaultTableModel tableModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                                XMBean mbean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                                MBeanAttributeInfo[] attributesInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                                HashMap<String, Object> attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                                HashMap<String, Object> unavailableAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                                HashMap<String, Object> viewableAttributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        Object rowData[] = new Object[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        int col1Width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        int col2Width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        for (int i = 0; i < attributesInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            rowData[0] = (attributesInfo[i].getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            if (unavailableAttributes.containsKey(rowData[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                rowData[1] = Resources.getText("Unavailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            } else if (viewableAttributes.containsKey(rowData[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                rowData[1] = viewableAttributes.get(rowData[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                if (!attributesInfo[i].isWritable() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    !Utils.isEditableType(attributesInfo[i].getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    rowData[1] = getZoomedCell(mbean, (String) rowData[0], rowData[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                rowData[1] = attributes.get(rowData[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            tableModel.addRow(rowData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            //Update column width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            String str = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            if(rowData[0] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                str = rowData[0].toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                if(str.length() > col1Width)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                    col1Width = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            if(rowData[1] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                str = rowData[1].toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                if(str.length() > col2Width)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                    col2Width = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        updateColumnWidth(col1Width, col2Width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    private void updateColumnWidth(int col1Width, int col2Width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        TableColumnModel colModel = getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        //Get the column at index pColumn, and set its preferred width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        col1Width = col1Width * 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        col2Width = col2Width * 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if(col1Width + col2Width <
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
           (int) getPreferredScrollableViewportSize().getWidth())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            col2Width = (int) getPreferredScrollableViewportSize().getWidth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                - col1Width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        colModel.getColumn(NAME_COLUMN).setPreferredWidth(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    class AttributesMouseListener extends MouseAdapter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            if(e.getButton() == MouseEvent.BUTTON1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                if(e.getClickCount() >= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    int row = XMBeanAttributes.this.getSelectedRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    int col = XMBeanAttributes.this.getSelectedColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                    if(col != VALUE_COLUMN) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    if(col == -1 || row == -1) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    XMBeanAttributes.this.updateZoomedCell(row, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    class ValueCellEditor extends XTextFieldEditor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        // implements javax.swing.table.TableCellEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        public Component getTableCellEditorComponent(JTable table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                                                     Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                                                     boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                                                     int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                                                     int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            Object val = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            if(column == VALUE_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                Object obj = getModel().getValueAt(row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                                   column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                if(obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    if(cell.getRenderer() instanceof MaximizedCellRenderer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                        MaximizedCellRenderer zr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                            (MaximizedCellRenderer) cell.getRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        return zr.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    Component comp = super.getTableCellEditorComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                            table, val, isSelected, row, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    if (isCellError(row, column) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                        !isWritable(row) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                        !Utils.isEditableType(getClassName(row))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                        textField.setEditable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            return super.getTableCellEditorComponent(table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                                                     val,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                                                     isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                                                     row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                                                     column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        public boolean stopCellEditing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            int editingRow = getEditingRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            int editingColumn = getEditingColumn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            if (editingColumn == VALUE_COLUMN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                Object obj = getModel().getValueAt(editingRow, editingColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                if (obj instanceof ZoomedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    ZoomedCell cell = (ZoomedCell) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                    if (cell.isMaximized()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                        this.cancelCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            return super.stopCellEditing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    class MaximizedCellRenderer extends  DefaultTableCellRenderer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        MaximizedCellRenderer(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            this.comp = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            Dimension d = comp.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            if (d.getHeight() > 200) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                comp.setPreferredSize(new Dimension((int) d.getWidth(), 200));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        public Component getTableCellRendererComponent(JTable table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                                       Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                                                       boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                                                       boolean hasFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                                       int row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                                                       int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        public Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    class ZoomedCell {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        TableCellRenderer minRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        MaximizedCellRenderer maxRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        int minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        boolean minimized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        boolean init = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        ZoomedCell(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            type = XDataViewer.getViewerType(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        boolean isInited() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            return init;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        void setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        void init(TableCellRenderer minRenderer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                  Component maxComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                  int minHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            this.minRenderer = minRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            this.maxRenderer = new MaximizedCellRenderer(maxComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            this.minHeight = minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            init = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            init = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            minimized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        void switchState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            minimized = !minimized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        boolean isMaximized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            return !minimized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        void minimize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            minimized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        void maximize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            minimized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            if(minimized) return minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                return (int) maxRenderer.getComponent().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    getPreferredSize().getHeight() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        int getMinHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            return minHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            if(value == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            if(value.getClass().isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                String name =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                    Utils.getArrayClassName(value.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                int length = Array.getLength(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                return name + "[" + length +"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            if(value instanceof CompositeData ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
               value instanceof TabularData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                return value.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            return value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        TableCellRenderer getRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            if(minimized) return minRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            else return maxRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        TableCellRenderer getMinRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            return minRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    class AttributesListener implements  TableModelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        private Component component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        public AttributesListener(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            this.component = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        public void tableChanged(final TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            final TableModel model = (TableModel)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            // only post changes to the draggable column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            if (isColumnEditable(e.getColumn())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                mbeansTab.workerAdd(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                                Object tableValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                                    model.getValueAt(e.getFirstRow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                                                     e.getColumn());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                                // if it's a String, try construct new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                                // using the defined type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                                if (tableValue instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                                    tableValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                                        Utils.createObjectFromString(getClassName(e.getFirstRow()), // type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                                                                     (String)tableValue);// value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                                String attributeName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                                    getValueName(e.getFirstRow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                                Attribute attribute =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                                    new Attribute(attributeName,tableValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                                mbean.setAttribute(attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                            catch (Throwable ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                                if (JConsole.isDebug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                                    ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                                ex = Utils.getActualException(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                String message = (ex.getMessage() != null) ? ex.getMessage() : ex.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                                EventQueue.invokeLater(new ThreadDialog(component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                                                                        message+"\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                                                                        Resources.getText("Problem setting attribute"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                                                                        JOptionPane.ERROR_MESSAGE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                            refreshAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
}