< prev index next >

src/share/classes/sun/tools/jconsole/inspector/XSheet.java

Print this page
rev 1501 : 7017818: NLS: JConsoleResources.java cannot be handled by translation team
Reviewed-by: mchung, mfang


  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole.inspector;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.io.*;
  31 import java.util.Enumeration;
  32 import javax.management.*;
  33 import javax.swing.*;
  34 import javax.swing.border.*;
  35 import javax.swing.tree.*;
  36 import sun.tools.jconsole.*;
  37 import sun.tools.jconsole.inspector.XNodeInfo.Type;
  38 
  39 import static sun.tools.jconsole.Resources.*;
  40 import static sun.tools.jconsole.Utilities.*;
  41 
  42 @SuppressWarnings("serial")
  43 public class XSheet extends JPanel
  44         implements ActionListener, NotificationListener {
  45 
  46     private JPanel mainPanel;
  47     private JPanel southPanel;
  48 
  49     // Node being currently displayed
  50     private DefaultMutableTreeNode node;
  51 
  52     // MBean being currently displayed
  53     private XMBean mbean;
  54 
  55     // XMBeanAttributes container
  56     private XMBeanAttributes mbeanAttributes;
  57 
  58     // XMBeanOperations container
  59     private XMBeanOperations mbeanOperations;


  77         this.mbeansTab = mbeansTab;
  78         setupScreen();
  79     }
  80 
  81     public void dispose() {
  82         clear();
  83         XDataViewer.dispose(mbeansTab);
  84         mbeanNotifications.dispose();
  85     }
  86 
  87     private void setupScreen() {
  88         setLayout(new BorderLayout());
  89         // add main panel to XSheet
  90         mainPanel = new JPanel();
  91         mainPanel.setLayout(new BorderLayout());
  92         add(mainPanel, BorderLayout.CENTER);
  93         // add south panel to XSheet
  94         southPanel = new JPanel();
  95         add(southPanel, BorderLayout.SOUTH);
  96         // create the refresh button
  97         String refreshButtonKey = "MBeansTab.refreshAttributesButton";
  98         refreshButton = new JButton(getText(refreshButtonKey));
  99         refreshButton.setMnemonic(getMnemonicInt(refreshButtonKey));
 100         refreshButton.setToolTipText(getText(refreshButtonKey + ".toolTip"));
 101         refreshButton.addActionListener(this);
 102         // create the clear button
 103         String clearButtonKey = "MBeansTab.clearNotificationsButton";
 104         clearButton = new JButton(getText(clearButtonKey));
 105         clearButton.setMnemonic(getMnemonicInt(clearButtonKey));
 106         clearButton.setToolTipText(getText(clearButtonKey + ".toolTip"));
 107         clearButton.addActionListener(this);
 108         // create the subscribe button
 109         String subscribeButtonKey = "MBeansTab.subscribeNotificationsButton";
 110         subscribeButton = new JButton(getText(subscribeButtonKey));
 111         subscribeButton.setMnemonic(getMnemonicInt(subscribeButtonKey));
 112         subscribeButton.setToolTipText(getText(subscribeButtonKey + ".toolTip"));
 113         subscribeButton.addActionListener(this);
 114         // create the unsubscribe button
 115         String unsubscribeButtonKey = "MBeansTab.unsubscribeNotificationsButton";
 116         unsubscribeButton = new JButton(getText(unsubscribeButtonKey));
 117         unsubscribeButton.setMnemonic(getMnemonicInt(unsubscribeButtonKey));
 118         unsubscribeButton.setToolTipText(getText(unsubscribeButtonKey + ".toolTip"));
 119         unsubscribeButton.addActionListener(this);
 120         // create XMBeanAttributes container
 121         mbeanAttributes = new XMBeanAttributes(mbeansTab);
 122         // create XMBeanOperations container
 123         mbeanOperations = new XMBeanOperations(mbeansTab);
 124         mbeanOperations.addOperationsListener(this);
 125         // create XMBeanNotifications container
 126         mbeanNotifications = new XMBeanNotifications();
 127         mbeanNotifications.addNotificationsListener(this);
 128         // create XMBeanInfo container
 129         mbeanInfo = new XMBeanInfo();
 130     }
 131 
 132     public boolean isMBeanNode(DefaultMutableTreeNode node) {
 133         XNodeInfo uo = (XNodeInfo) node.getUserObject();
 134         return uo.getType().equals(Type.MBEAN);
 135     }
 136 
 137     public void displayNode(DefaultMutableTreeNode node) {
 138         clear();


 171         } else {
 172             displayEmptyNode();
 173         }
 174     }
 175 
 176     private void displayMBeanNode(final DefaultMutableTreeNode node) {
 177         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 178         if (!uo.getType().equals(Type.MBEAN)) {
 179             return;
 180         }
 181         mbeansTab.workerAdd(new Runnable() {
 182             public void run() {
 183                 try {
 184                     XSheet.this.node = node;
 185                     XSheet.this.mbean = (XMBean) uo.getData();
 186                     mbeanInfo.addMBeanInfo(mbean, mbean.getMBeanInfo());
 187                 } catch (Throwable ex) {
 188                     EventQueue.invokeLater(new ThreadDialog(
 189                             XSheet.this,
 190                             ex.getMessage(),
 191                             Resources.getText("Problem displaying MBean"),
 192                             JOptionPane.ERROR_MESSAGE));
 193                     return;
 194                 }
 195                 EventQueue.invokeLater(new Runnable() {
 196                     public void run() {
 197                         invalidate();
 198                         mainPanel.removeAll();
 199                         mainPanel.add(mbeanInfo, BorderLayout.CENTER);
 200                         southPanel.setVisible(false);
 201                         southPanel.removeAll();
 202                         validate();
 203                         repaint();
 204                     }
 205                 });
 206             }
 207         });
 208     }
 209 
 210     // Call on EDT
 211     private void displayMetadataNode(final DefaultMutableTreeNode node) {
 212         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 213         final XMBeanInfo mbi = mbeanInfo;
 214         switch (uo.getType()) {
 215             case ATTRIBUTE:
 216                 mbeansTab.workerAdd(new Runnable() {
 217                     public void run() {
 218                         Object attrData = uo.getData();
 219                         XSheet.this.mbean = (XMBean) ((Object[]) attrData)[0];
 220                         final MBeanAttributeInfo mbai =
 221                                 (MBeanAttributeInfo) ((Object[]) attrData)[1];
 222                         final XMBeanAttributes mba = mbeanAttributes;
 223                         try {
 224                             mba.loadAttributes(mbean, new MBeanInfo(
 225                                     null, null, new MBeanAttributeInfo[] {mbai},
 226                                     null, null, null));
 227                         } catch (Exception e) {
 228                             EventQueue.invokeLater(new ThreadDialog(
 229                                     XSheet.this,
 230                                     e.getMessage(),
 231                                     Resources.getText("Problem displaying MBean"),
 232                                     JOptionPane.ERROR_MESSAGE));
 233                             return;
 234                         }
 235                         EventQueue.invokeLater(new Runnable() {
 236                             public void run() {
 237                                 invalidate();
 238                                 mainPanel.removeAll();
 239                                 JPanel attributePanel =
 240                                         new JPanel(new BorderLayout());
 241                                 JPanel attributeBorderPanel =
 242                                         new JPanel(new BorderLayout());
 243                                 attributeBorderPanel.setBorder(
 244                                         BorderFactory.createTitledBorder(
 245                                         Resources.getText("Attribute value")));
 246                                 JPanel attributeValuePanel =
 247                                         new JPanel(new BorderLayout());
 248                                 attributeValuePanel.setBorder(
 249                                         LineBorder.createGrayLineBorder());
 250                                 attributeValuePanel.add(mba.getTableHeader(),
 251                                         BorderLayout.PAGE_START);
 252                                 attributeValuePanel.add(mba,
 253                                         BorderLayout.CENTER);
 254                                 attributeBorderPanel.add(attributeValuePanel,
 255                                         BorderLayout.CENTER);
 256                                 JPanel refreshButtonPanel = new JPanel();
 257                                 refreshButtonPanel.add(refreshButton);
 258                                 attributeBorderPanel.add(refreshButtonPanel,
 259                                         BorderLayout.SOUTH);
 260                                 refreshButton.setEnabled(true);
 261                                 attributePanel.add(attributeBorderPanel,
 262                                         BorderLayout.NORTH);
 263                                 mbi.addMBeanAttributeInfo(mbai);
 264                                 attributePanel.add(mbi, BorderLayout.CENTER);
 265                                 mainPanel.add(attributePanel,


 269                                 validate();
 270                                 repaint();
 271                             }
 272                         });
 273                     }
 274                 });
 275                 break;
 276             case OPERATION:
 277                 Object operData = uo.getData();
 278                 XSheet.this.mbean = (XMBean) ((Object[]) operData)[0];
 279                 MBeanOperationInfo mboi =
 280                         (MBeanOperationInfo) ((Object[]) operData)[1];
 281                 XMBeanOperations mbo = mbeanOperations;
 282                 try {
 283                     mbo.loadOperations(mbean, new MBeanInfo(null, null, null,
 284                             null, new MBeanOperationInfo[] {mboi}, null));
 285                 } catch (Exception e) {
 286                     EventQueue.invokeLater(new ThreadDialog(
 287                             XSheet.this,
 288                             e.getMessage(),
 289                             Resources.getText("Problem displaying MBean"),
 290                             JOptionPane.ERROR_MESSAGE));
 291                     return;
 292                 }
 293                 invalidate();
 294                 mainPanel.removeAll();
 295                 JPanel operationPanel = new JPanel(new BorderLayout());
 296                 JPanel operationBorderPanel = new JPanel(new BorderLayout());
 297                 operationBorderPanel.setBorder(BorderFactory.createTitledBorder(
 298                         Resources.getText("Operation invocation")));
 299                 operationBorderPanel.add(new JScrollPane(mbo));
 300                 operationPanel.add(operationBorderPanel, BorderLayout.NORTH);
 301                 mbi.addMBeanOperationInfo(mboi);
 302                 operationPanel.add(mbi, BorderLayout.CENTER);
 303                 mainPanel.add(operationPanel, BorderLayout.CENTER);
 304                 southPanel.setVisible(false);
 305                 southPanel.removeAll();
 306                 validate();
 307                 repaint();
 308                 break;
 309             case NOTIFICATION:
 310                 Object notifData = uo.getData();
 311                 invalidate();
 312                 mainPanel.removeAll();
 313                 mbi.addMBeanNotificationInfo((MBeanNotificationInfo) notifData);
 314                 mainPanel.add(mbi, BorderLayout.CENTER);
 315                 southPanel.setVisible(false);
 316                 southPanel.removeAll();
 317                 validate();
 318                 repaint();
 319                 break;
 320         }
 321     }
 322 
 323     private void displayMBeanAttributesNode(final DefaultMutableTreeNode node) {
 324         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 325         if (!uo.getType().equals(Type.ATTRIBUTES)) {
 326             return;
 327         }
 328         final XMBeanAttributes mba = mbeanAttributes;
 329         mbeansTab.workerAdd(new Runnable() {
 330             public void run() {
 331                 try {
 332                     XSheet.this.node = node;
 333                     XSheet.this.mbean = (XMBean) uo.getData();
 334                     mba.loadAttributes(mbean, mbean.getMBeanInfo());
 335                 } catch (Throwable ex) {
 336                     EventQueue.invokeLater(new ThreadDialog(
 337                             XSheet.this,
 338                             ex.getMessage(),
 339                             Resources.getText("Problem displaying MBean"),
 340                             JOptionPane.ERROR_MESSAGE));
 341                     return;
 342                 }
 343                 EventQueue.invokeLater(new Runnable() {
 344                     public void run() {
 345                         invalidate();
 346                         mainPanel.removeAll();
 347                         JPanel borderPanel = new JPanel(new BorderLayout());
 348                         borderPanel.setBorder(BorderFactory.createTitledBorder(
 349                                 Resources.getText("Attribute values")));
 350                         borderPanel.add(new JScrollPane(mba));
 351                         mainPanel.add(borderPanel, BorderLayout.CENTER);
 352                         // add the refresh button to the south panel
 353                         southPanel.removeAll();
 354                         southPanel.add(refreshButton, BorderLayout.SOUTH);
 355                         southPanel.setVisible(true);
 356                         refreshButton.setEnabled(true);
 357                         validate();
 358                         repaint();
 359                     }
 360                 });
 361             }
 362         });
 363     }
 364 
 365     private void displayMBeanOperationsNode(final DefaultMutableTreeNode node) {
 366         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 367         if (!uo.getType().equals(Type.OPERATIONS)) {
 368             return;
 369         }
 370         final XMBeanOperations mbo = mbeanOperations;
 371         mbeansTab.workerAdd(new Runnable() {
 372             public void run() {
 373                 try {
 374                     XSheet.this.node = node;
 375                     XSheet.this.mbean = (XMBean) uo.getData();
 376                     mbo.loadOperations(mbean, mbean.getMBeanInfo());
 377                 } catch (Throwable ex) {
 378                     EventQueue.invokeLater(new ThreadDialog(
 379                             XSheet.this,
 380                             ex.getMessage(),
 381                             Resources.getText("Problem displaying MBean"),
 382                             JOptionPane.ERROR_MESSAGE));
 383                     return;
 384                 }
 385                 EventQueue.invokeLater(new Runnable() {
 386                     public void run() {
 387                         invalidate();
 388                         mainPanel.removeAll();
 389                         JPanel borderPanel = new JPanel(new BorderLayout());
 390                         borderPanel.setBorder(BorderFactory.createTitledBorder(
 391                                 Resources.getText("Operation invocation")));
 392                         borderPanel.add(new JScrollPane(mbo));
 393                         mainPanel.add(borderPanel, BorderLayout.CENTER);
 394                         southPanel.setVisible(false);
 395                         southPanel.removeAll();
 396                         validate();
 397                         repaint();
 398                     }
 399                 });
 400             }
 401         });
 402     }
 403 
 404     private void displayMBeanNotificationsNode(
 405             final DefaultMutableTreeNode node) {
 406         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 407         if (!uo.getType().equals(Type.NOTIFICATIONS)) {
 408             return;
 409         }
 410         final XMBeanNotifications mbn = mbeanNotifications;
 411         mbeansTab.workerAdd(new Runnable() {
 412             public void run() {
 413                 try {
 414                     XSheet.this.node = node;
 415                     XSheet.this.mbean = (XMBean) uo.getData();
 416                     mbn.loadNotifications(mbean);
 417                     updateNotifications();
 418                 } catch (Throwable ex) {
 419                     EventQueue.invokeLater(new ThreadDialog(
 420                             XSheet.this,
 421                             ex.getMessage(),
 422                             Resources.getText("Problem displaying MBean"),
 423                             JOptionPane.ERROR_MESSAGE));
 424                     return;
 425                 }
 426                 EventQueue.invokeLater(new Runnable() {
 427                     public void run() {
 428                         invalidate();
 429                         mainPanel.removeAll();
 430                         JPanel borderPanel = new JPanel(new BorderLayout());
 431                         borderPanel.setBorder(BorderFactory.createTitledBorder(
 432                                 Resources.getText("Notification buffer")));
 433                         borderPanel.add(new JScrollPane(mbn));
 434                         mainPanel.add(borderPanel, BorderLayout.CENTER);
 435                         // add the subscribe/unsubscribe/clear buttons to
 436                         // the south panel
 437                         southPanel.removeAll();
 438                         southPanel.add(subscribeButton, BorderLayout.WEST);
 439                         southPanel.add(unsubscribeButton, BorderLayout.CENTER);
 440                         southPanel.add(clearButton, BorderLayout.EAST);
 441                         southPanel.setVisible(true);
 442                         subscribeButton.setEnabled(true);
 443                         unsubscribeButton.setEnabled(true);
 444                         clearButton.setEnabled(true);
 445                         validate();
 446                         repaint();
 447                     }
 448                 });
 449             }
 450         });
 451     }
 452 


 488 
 489     private void updateNotifications() {
 490         if (mbean.isBroadcaster()) {
 491             if (mbeanNotifications.isListenerRegistered(mbean)) {
 492                 long received =
 493                         mbeanNotifications.getReceivedNotifications(mbean);
 494                 updateReceivedNotifications(node, received, false);
 495             } else {
 496                 clearNotifications();
 497             }
 498         } else {
 499             clearNotifications();
 500         }
 501     }
 502 
 503     /**
 504      * Update notification node label in MBean tree: "Notifications[received]".
 505      */
 506     private void updateReceivedNotifications(
 507             DefaultMutableTreeNode emitter, long received, boolean bold) {
 508         String text = Resources.getText("Notifications") + "[" + received + "]";
 509         DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)
 510         mbeansTab.getTree().getLastSelectedPathComponent();
 511         if (bold && emitter != selectedNode) {
 512             text = "<html><b>" + text + "</b></html>";
 513         }
 514         updateNotificationsNodeLabel(emitter, text);
 515     }
 516 
 517     /**
 518      * Update notification node label in MBean tree: "Notifications".
 519      */
 520     private void clearNotifications() {
 521         updateNotificationsNodeLabel(node,
 522                 Resources.getText("Notifications"));
 523     }
 524 
 525     /**
 526      * Update notification node label in MBean tree: "Notifications[0]".
 527      */
 528     private void clearNotifications0() {
 529         updateNotificationsNodeLabel(node,
 530                 Resources.getText("Notifications") + "[0]");
 531     }
 532 
 533     /**
 534      * Update the label of the supplied MBean tree node.
 535      */
 536     private void updateNotificationsNodeLabel(
 537             final DefaultMutableTreeNode node, final String label) {
 538         EventQueue.invokeLater(new Runnable() {
 539             public void run() {
 540                 synchronized (mbeansTab.getTree()) {
 541                     invalidate();
 542                     XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject();
 543                     XNodeInfo newUserObject = new XNodeInfo(
 544                             oldUserObject.getType(), oldUserObject.getData(),
 545                             label, oldUserObject.getToolTipText());
 546                     node.setUserObject(newUserObject);
 547                     DefaultTreeModel model =
 548                             (DefaultTreeModel) mbeansTab.getTree().getModel();
 549                     model.nodeChanged(node);
 550                     validate();


 614                     JScrollPane scrollPane = new JScrollPane(textArea);
 615                     Dimension d = scrollPane.getPreferredSize();
 616                     if (d.getWidth() > 400 || d.getHeight() > 250) {
 617                         scrollPane.setPreferredSize(new Dimension(400, 250));
 618                     }
 619                     message = scrollPane;
 620                 } else {
 621                     if (!(comp instanceof JScrollPane)) {
 622                         comp = new JScrollPane(comp);
 623                     }
 624                     Dimension d = comp.getPreferredSize();
 625                     if (d.getWidth() > 400 || d.getHeight() > 250) {
 626                         comp.setPreferredSize(new Dimension(400, 250));
 627                     }
 628                     message = comp;
 629                 }
 630             }
 631             EventQueue.invokeLater(new ThreadDialog(
 632                     (Component) e.getSource(),
 633                     message,
 634                     Resources.getText("Operation return value"),
 635                     JOptionPane.INFORMATION_MESSAGE));
 636         }
 637         // Got notification
 638         else if (e.getType().equals(
 639                 XMBeanNotifications.NOTIFICATION_RECEIVED_EVENT)) {
 640             DefaultMutableTreeNode emitter = (DefaultMutableTreeNode) handback;
 641             Long received = (Long) e.getUserData();
 642             updateReceivedNotifications(emitter, received.longValue(), true);
 643         }
 644     }
 645 
 646     /**
 647      * Action listener: handles actions in panel buttons
 648      */
 649     public void actionPerformed(ActionEvent e) {
 650         if (e.getSource() instanceof JButton) {
 651             JButton button = (JButton) e.getSource();
 652             // Refresh button
 653             if (button == refreshButton) {
 654                 mbeansTab.workerAdd(new Runnable() {


 657                     }
 658                 });
 659                 return;
 660             }
 661             // Clear button
 662             if (button == clearButton) {
 663                 clearCurrentNotifications();
 664                 return;
 665             }
 666             // Subscribe button
 667             if (button == subscribeButton) {
 668                 mbeansTab.workerAdd(new Runnable() {
 669                     public void run() {
 670                         try {
 671                             registerListener();
 672                         } catch (Throwable ex) {
 673                             ex = Utils.getActualException(ex);
 674                             EventQueue.invokeLater(new ThreadDialog(
 675                                     XSheet.this,
 676                                     ex.getMessage(),
 677                                     Resources.getText("Problem adding listener"),
 678                                     JOptionPane.ERROR_MESSAGE));
 679                         }
 680                     }
 681                 });
 682                 return;
 683             }
 684             // Unsubscribe button
 685             if (button == unsubscribeButton) {
 686                 mbeansTab.workerAdd(new Runnable() {
 687                     public void run() {
 688                         try {
 689                             unregisterListener();
 690                         } catch (Throwable ex) {
 691                             ex = Utils.getActualException(ex);
 692                             EventQueue.invokeLater(new ThreadDialog(
 693                                     XSheet.this,
 694                                     ex.getMessage(),
 695                                     Resources.getText("Problem removing listener"),
 696                                     JOptionPane.ERROR_MESSAGE));
 697                         }
 698                     }
 699                 });
 700                 return;
 701             }
 702         }
 703     }
 704 }


  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole.inspector;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.io.*;
  31 import java.util.Enumeration;
  32 import javax.management.*;
  33 import javax.swing.*;
  34 import javax.swing.border.*;
  35 import javax.swing.tree.*;
  36 import sun.tools.jconsole.*;
  37 import sun.tools.jconsole.inspector.XNodeInfo.Type;
  38 

  39 import static sun.tools.jconsole.Utilities.*;
  40 
  41 @SuppressWarnings("serial")
  42 public class XSheet extends JPanel
  43         implements ActionListener, NotificationListener {
  44 
  45     private JPanel mainPanel;
  46     private JPanel southPanel;
  47 
  48     // Node being currently displayed
  49     private DefaultMutableTreeNode node;
  50 
  51     // MBean being currently displayed
  52     private XMBean mbean;
  53 
  54     // XMBeanAttributes container
  55     private XMBeanAttributes mbeanAttributes;
  56 
  57     // XMBeanOperations container
  58     private XMBeanOperations mbeanOperations;


  76         this.mbeansTab = mbeansTab;
  77         setupScreen();
  78     }
  79 
  80     public void dispose() {
  81         clear();
  82         XDataViewer.dispose(mbeansTab);
  83         mbeanNotifications.dispose();
  84     }
  85 
  86     private void setupScreen() {
  87         setLayout(new BorderLayout());
  88         // add main panel to XSheet
  89         mainPanel = new JPanel();
  90         mainPanel.setLayout(new BorderLayout());
  91         add(mainPanel, BorderLayout.CENTER);
  92         // add south panel to XSheet
  93         southPanel = new JPanel();
  94         add(southPanel, BorderLayout.SOUTH);
  95         // create the refresh button
  96         refreshButton = new JButton(Messages.MBEANS_TAB_REFRESH_ATTRIBUTES_BUTTON);
  97         refreshButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_REFRESH_ATTRIBUTES_BUTTON));
  98         refreshButton.setToolTipText(Messages.MBEANS_TAB_REFRESH_ATTRIBUTES_BUTTON_TOOLTIP);

  99         refreshButton.addActionListener(this);
 100         // create the clear button
 101         clearButton = new JButton(Messages.MBEANS_TAB_CLEAR_NOTIFICATIONS_BUTTON);
 102         clearButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_CLEAR_NOTIFICATIONS_BUTTON));
 103         clearButton.setToolTipText(Messages.MBEANS_TAB_CLEAR_NOTIFICATIONS_BUTTON_TOOLTIP);

 104         clearButton.addActionListener(this);
 105         // create the subscribe button
 106         subscribeButton = new JButton(Messages.MBEANS_TAB_SUBSCRIBE_NOTIFICATIONS_BUTTON);
 107         subscribeButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_SUBSCRIBE_NOTIFICATIONS_BUTTON));
 108         subscribeButton.setToolTipText(Messages.MBEANS_TAB_SUBSCRIBE_NOTIFICATIONS_BUTTON_TOOLTIP);

 109         subscribeButton.addActionListener(this);
 110         // create the unsubscribe button
 111         unsubscribeButton = new JButton(Messages.MBEANS_TAB_UNSUBSCRIBE_NOTIFICATIONS_BUTTON);
 112         unsubscribeButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_UNSUBSCRIBE_NOTIFICATIONS_BUTTON));
 113         unsubscribeButton.setToolTipText(Messages.MBEANS_TAB_UNSUBSCRIBE_NOTIFICATIONS_BUTTON_TOOLTIP);

 114         unsubscribeButton.addActionListener(this);
 115         // create XMBeanAttributes container
 116         mbeanAttributes = new XMBeanAttributes(mbeansTab);
 117         // create XMBeanOperations container
 118         mbeanOperations = new XMBeanOperations(mbeansTab);
 119         mbeanOperations.addOperationsListener(this);
 120         // create XMBeanNotifications container
 121         mbeanNotifications = new XMBeanNotifications();
 122         mbeanNotifications.addNotificationsListener(this);
 123         // create XMBeanInfo container
 124         mbeanInfo = new XMBeanInfo();
 125     }
 126 
 127     public boolean isMBeanNode(DefaultMutableTreeNode node) {
 128         XNodeInfo uo = (XNodeInfo) node.getUserObject();
 129         return uo.getType().equals(Type.MBEAN);
 130     }
 131 
 132     public void displayNode(DefaultMutableTreeNode node) {
 133         clear();


 166         } else {
 167             displayEmptyNode();
 168         }
 169     }
 170 
 171     private void displayMBeanNode(final DefaultMutableTreeNode node) {
 172         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 173         if (!uo.getType().equals(Type.MBEAN)) {
 174             return;
 175         }
 176         mbeansTab.workerAdd(new Runnable() {
 177             public void run() {
 178                 try {
 179                     XSheet.this.node = node;
 180                     XSheet.this.mbean = (XMBean) uo.getData();
 181                     mbeanInfo.addMBeanInfo(mbean, mbean.getMBeanInfo());
 182                 } catch (Throwable ex) {
 183                     EventQueue.invokeLater(new ThreadDialog(
 184                             XSheet.this,
 185                             ex.getMessage(),
 186                             Messages.PROBLEM_DISPLAYING_MBEAN,
 187                             JOptionPane.ERROR_MESSAGE));
 188                     return;
 189                 }
 190                 EventQueue.invokeLater(new Runnable() {
 191                     public void run() {
 192                         invalidate();
 193                         mainPanel.removeAll();
 194                         mainPanel.add(mbeanInfo, BorderLayout.CENTER);
 195                         southPanel.setVisible(false);
 196                         southPanel.removeAll();
 197                         validate();
 198                         repaint();
 199                     }
 200                 });
 201             }
 202         });
 203     }
 204 
 205     // Call on EDT
 206     private void displayMetadataNode(final DefaultMutableTreeNode node) {
 207         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 208         final XMBeanInfo mbi = mbeanInfo;
 209         switch (uo.getType()) {
 210             case ATTRIBUTE:
 211                 mbeansTab.workerAdd(new Runnable() {
 212                     public void run() {
 213                         Object attrData = uo.getData();
 214                         XSheet.this.mbean = (XMBean) ((Object[]) attrData)[0];
 215                         final MBeanAttributeInfo mbai =
 216                                 (MBeanAttributeInfo) ((Object[]) attrData)[1];
 217                         final XMBeanAttributes mba = mbeanAttributes;
 218                         try {
 219                             mba.loadAttributes(mbean, new MBeanInfo(
 220                                     null, null, new MBeanAttributeInfo[] {mbai},
 221                                     null, null, null));
 222                         } catch (Exception e) {
 223                             EventQueue.invokeLater(new ThreadDialog(
 224                                     XSheet.this,
 225                                     e.getMessage(),
 226                                     Messages.PROBLEM_DISPLAYING_MBEAN,
 227                                     JOptionPane.ERROR_MESSAGE));
 228                             return;
 229                         }
 230                         EventQueue.invokeLater(new Runnable() {
 231                             public void run() {
 232                                 invalidate();
 233                                 mainPanel.removeAll();
 234                                 JPanel attributePanel =
 235                                         new JPanel(new BorderLayout());
 236                                 JPanel attributeBorderPanel =
 237                                         new JPanel(new BorderLayout());
 238                                 attributeBorderPanel.setBorder(
 239                                         BorderFactory.createTitledBorder(
 240                                             Messages.ATTRIBUTE_VALUE));
 241                                 JPanel attributeValuePanel =
 242                                         new JPanel(new BorderLayout());
 243                                 attributeValuePanel.setBorder(
 244                                         LineBorder.createGrayLineBorder());
 245                                 attributeValuePanel.add(mba.getTableHeader(),
 246                                         BorderLayout.PAGE_START);
 247                                 attributeValuePanel.add(mba,
 248                                         BorderLayout.CENTER);
 249                                 attributeBorderPanel.add(attributeValuePanel,
 250                                         BorderLayout.CENTER);
 251                                 JPanel refreshButtonPanel = new JPanel();
 252                                 refreshButtonPanel.add(refreshButton);
 253                                 attributeBorderPanel.add(refreshButtonPanel,
 254                                         BorderLayout.SOUTH);
 255                                 refreshButton.setEnabled(true);
 256                                 attributePanel.add(attributeBorderPanel,
 257                                         BorderLayout.NORTH);
 258                                 mbi.addMBeanAttributeInfo(mbai);
 259                                 attributePanel.add(mbi, BorderLayout.CENTER);
 260                                 mainPanel.add(attributePanel,


 264                                 validate();
 265                                 repaint();
 266                             }
 267                         });
 268                     }
 269                 });
 270                 break;
 271             case OPERATION:
 272                 Object operData = uo.getData();
 273                 XSheet.this.mbean = (XMBean) ((Object[]) operData)[0];
 274                 MBeanOperationInfo mboi =
 275                         (MBeanOperationInfo) ((Object[]) operData)[1];
 276                 XMBeanOperations mbo = mbeanOperations;
 277                 try {
 278                     mbo.loadOperations(mbean, new MBeanInfo(null, null, null,
 279                             null, new MBeanOperationInfo[] {mboi}, null));
 280                 } catch (Exception e) {
 281                     EventQueue.invokeLater(new ThreadDialog(
 282                             XSheet.this,
 283                             e.getMessage(),
 284                             Messages.PROBLEM_DISPLAYING_MBEAN,
 285                             JOptionPane.ERROR_MESSAGE));
 286                     return;
 287                 }
 288                 invalidate();
 289                 mainPanel.removeAll();
 290                 JPanel operationPanel = new JPanel(new BorderLayout());
 291                 JPanel operationBorderPanel = new JPanel(new BorderLayout());
 292                 operationBorderPanel.setBorder(BorderFactory.createTitledBorder(
 293                         Messages.OPERATION_INVOCATION));
 294                 operationBorderPanel.add(new JScrollPane(mbo));
 295                 operationPanel.add(operationBorderPanel, BorderLayout.NORTH);
 296                 mbi.addMBeanOperationInfo(mboi);
 297                 operationPanel.add(mbi, BorderLayout.CENTER);
 298                 mainPanel.add(operationPanel, BorderLayout.CENTER);
 299                 southPanel.setVisible(false);
 300                 southPanel.removeAll();
 301                 validate();
 302                 repaint();
 303                 break;
 304             case NOTIFICATION:
 305                 Object notifData = uo.getData();
 306                 invalidate();
 307                 mainPanel.removeAll();
 308                 mbi.addMBeanNotificationInfo((MBeanNotificationInfo) notifData);
 309                 mainPanel.add(mbi, BorderLayout.CENTER);
 310                 southPanel.setVisible(false);
 311                 southPanel.removeAll();
 312                 validate();
 313                 repaint();
 314                 break;
 315         }
 316     }
 317 
 318     private void displayMBeanAttributesNode(final DefaultMutableTreeNode node) {
 319         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 320         if (!uo.getType().equals(Type.ATTRIBUTES)) {
 321             return;
 322         }
 323         final XMBeanAttributes mba = mbeanAttributes;
 324         mbeansTab.workerAdd(new Runnable() {
 325             public void run() {
 326                 try {
 327                     XSheet.this.node = node;
 328                     XSheet.this.mbean = (XMBean) uo.getData();
 329                     mba.loadAttributes(mbean, mbean.getMBeanInfo());
 330                 } catch (Throwable ex) {
 331                     EventQueue.invokeLater(new ThreadDialog(
 332                             XSheet.this,
 333                             ex.getMessage(),
 334                             Messages.PROBLEM_DISPLAYING_MBEAN,
 335                             JOptionPane.ERROR_MESSAGE));
 336                     return;
 337                 }
 338                 EventQueue.invokeLater(new Runnable() {
 339                     public void run() {
 340                         invalidate();
 341                         mainPanel.removeAll();
 342                         JPanel borderPanel = new JPanel(new BorderLayout());
 343                         borderPanel.setBorder(BorderFactory.createTitledBorder(
 344                                 Messages.ATTRIBUTE_VALUES));
 345                         borderPanel.add(new JScrollPane(mba));
 346                         mainPanel.add(borderPanel, BorderLayout.CENTER);
 347                         // add the refresh button to the south panel
 348                         southPanel.removeAll();
 349                         southPanel.add(refreshButton, BorderLayout.SOUTH);
 350                         southPanel.setVisible(true);
 351                         refreshButton.setEnabled(true);
 352                         validate();
 353                         repaint();
 354                     }
 355                 });
 356             }
 357         });
 358     }
 359 
 360     private void displayMBeanOperationsNode(final DefaultMutableTreeNode node) {
 361         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 362         if (!uo.getType().equals(Type.OPERATIONS)) {
 363             return;
 364         }
 365         final XMBeanOperations mbo = mbeanOperations;
 366         mbeansTab.workerAdd(new Runnable() {
 367             public void run() {
 368                 try {
 369                     XSheet.this.node = node;
 370                     XSheet.this.mbean = (XMBean) uo.getData();
 371                     mbo.loadOperations(mbean, mbean.getMBeanInfo());
 372                 } catch (Throwable ex) {
 373                     EventQueue.invokeLater(new ThreadDialog(
 374                             XSheet.this,
 375                             ex.getMessage(),
 376                             Messages.PROBLEM_DISPLAYING_MBEAN,
 377                             JOptionPane.ERROR_MESSAGE));
 378                     return;
 379                 }
 380                 EventQueue.invokeLater(new Runnable() {
 381                     public void run() {
 382                         invalidate();
 383                         mainPanel.removeAll();
 384                         JPanel borderPanel = new JPanel(new BorderLayout());
 385                         borderPanel.setBorder(BorderFactory.createTitledBorder(
 386                                 Messages.OPERATION_INVOCATION));
 387                         borderPanel.add(new JScrollPane(mbo));
 388                         mainPanel.add(borderPanel, BorderLayout.CENTER);
 389                         southPanel.setVisible(false);
 390                         southPanel.removeAll();
 391                         validate();
 392                         repaint();
 393                     }
 394                 });
 395             }
 396         });
 397     }
 398 
 399     private void displayMBeanNotificationsNode(
 400             final DefaultMutableTreeNode node) {
 401         final XNodeInfo uo = (XNodeInfo) node.getUserObject();
 402         if (!uo.getType().equals(Type.NOTIFICATIONS)) {
 403             return;
 404         }
 405         final XMBeanNotifications mbn = mbeanNotifications;
 406         mbeansTab.workerAdd(new Runnable() {
 407             public void run() {
 408                 try {
 409                     XSheet.this.node = node;
 410                     XSheet.this.mbean = (XMBean) uo.getData();
 411                     mbn.loadNotifications(mbean);
 412                     updateNotifications();
 413                 } catch (Throwable ex) {
 414                     EventQueue.invokeLater(new ThreadDialog(
 415                             XSheet.this,
 416                             ex.getMessage(),
 417                             Messages.PROBLEM_DISPLAYING_MBEAN,
 418                             JOptionPane.ERROR_MESSAGE));
 419                     return;
 420                 }
 421                 EventQueue.invokeLater(new Runnable() {
 422                     public void run() {
 423                         invalidate();
 424                         mainPanel.removeAll();
 425                         JPanel borderPanel = new JPanel(new BorderLayout());
 426                         borderPanel.setBorder(BorderFactory.createTitledBorder(
 427                                                Messages.NOTIFICATION_BUFFER));
 428                         borderPanel.add(new JScrollPane(mbn));
 429                         mainPanel.add(borderPanel, BorderLayout.CENTER);
 430                         // add the subscribe/unsubscribe/clear buttons to
 431                         // the south panel
 432                         southPanel.removeAll();
 433                         southPanel.add(subscribeButton, BorderLayout.WEST);
 434                         southPanel.add(unsubscribeButton, BorderLayout.CENTER);
 435                         southPanel.add(clearButton, BorderLayout.EAST);
 436                         southPanel.setVisible(true);
 437                         subscribeButton.setEnabled(true);
 438                         unsubscribeButton.setEnabled(true);
 439                         clearButton.setEnabled(true);
 440                         validate();
 441                         repaint();
 442                     }
 443                 });
 444             }
 445         });
 446     }
 447 


 483 
 484     private void updateNotifications() {
 485         if (mbean.isBroadcaster()) {
 486             if (mbeanNotifications.isListenerRegistered(mbean)) {
 487                 long received =
 488                         mbeanNotifications.getReceivedNotifications(mbean);
 489                 updateReceivedNotifications(node, received, false);
 490             } else {
 491                 clearNotifications();
 492             }
 493         } else {
 494             clearNotifications();
 495         }
 496     }
 497 
 498     /**
 499      * Update notification node label in MBean tree: "Notifications[received]".
 500      */
 501     private void updateReceivedNotifications(
 502             DefaultMutableTreeNode emitter, long received, boolean bold) {
 503         String text = Messages.NOTIFICATIONS + "[" + received + "]";
 504         DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)
 505         mbeansTab.getTree().getLastSelectedPathComponent();
 506         if (bold && emitter != selectedNode) {
 507             text = "<html><b>" + text + "</b></html>";
 508         }
 509         updateNotificationsNodeLabel(emitter, text);
 510     }
 511 
 512     /**
 513      * Update notification node label in MBean tree: "Notifications".
 514      */
 515     private void clearNotifications() {
 516         updateNotificationsNodeLabel(node,
 517                 Messages.NOTIFICATIONS);
 518     }
 519 
 520     /**
 521      * Update notification node label in MBean tree: "Notifications[0]".
 522      */
 523     private void clearNotifications0() {
 524         updateNotificationsNodeLabel(node,
 525                 Messages.NOTIFICATIONS + "[0]");
 526     }
 527 
 528     /**
 529      * Update the label of the supplied MBean tree node.
 530      */
 531     private void updateNotificationsNodeLabel(
 532             final DefaultMutableTreeNode node, final String label) {
 533         EventQueue.invokeLater(new Runnable() {
 534             public void run() {
 535                 synchronized (mbeansTab.getTree()) {
 536                     invalidate();
 537                     XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject();
 538                     XNodeInfo newUserObject = new XNodeInfo(
 539                             oldUserObject.getType(), oldUserObject.getData(),
 540                             label, oldUserObject.getToolTipText());
 541                     node.setUserObject(newUserObject);
 542                     DefaultTreeModel model =
 543                             (DefaultTreeModel) mbeansTab.getTree().getModel();
 544                     model.nodeChanged(node);
 545                     validate();


 609                     JScrollPane scrollPane = new JScrollPane(textArea);
 610                     Dimension d = scrollPane.getPreferredSize();
 611                     if (d.getWidth() > 400 || d.getHeight() > 250) {
 612                         scrollPane.setPreferredSize(new Dimension(400, 250));
 613                     }
 614                     message = scrollPane;
 615                 } else {
 616                     if (!(comp instanceof JScrollPane)) {
 617                         comp = new JScrollPane(comp);
 618                     }
 619                     Dimension d = comp.getPreferredSize();
 620                     if (d.getWidth() > 400 || d.getHeight() > 250) {
 621                         comp.setPreferredSize(new Dimension(400, 250));
 622                     }
 623                     message = comp;
 624                 }
 625             }
 626             EventQueue.invokeLater(new ThreadDialog(
 627                     (Component) e.getSource(),
 628                     message,
 629                     Messages.OPERATION_RETURN_VALUE,
 630                     JOptionPane.INFORMATION_MESSAGE));
 631         }
 632         // Got notification
 633         else if (e.getType().equals(
 634                 XMBeanNotifications.NOTIFICATION_RECEIVED_EVENT)) {
 635             DefaultMutableTreeNode emitter = (DefaultMutableTreeNode) handback;
 636             Long received = (Long) e.getUserData();
 637             updateReceivedNotifications(emitter, received.longValue(), true);
 638         }
 639     }
 640 
 641     /**
 642      * Action listener: handles actions in panel buttons
 643      */
 644     public void actionPerformed(ActionEvent e) {
 645         if (e.getSource() instanceof JButton) {
 646             JButton button = (JButton) e.getSource();
 647             // Refresh button
 648             if (button == refreshButton) {
 649                 mbeansTab.workerAdd(new Runnable() {


 652                     }
 653                 });
 654                 return;
 655             }
 656             // Clear button
 657             if (button == clearButton) {
 658                 clearCurrentNotifications();
 659                 return;
 660             }
 661             // Subscribe button
 662             if (button == subscribeButton) {
 663                 mbeansTab.workerAdd(new Runnable() {
 664                     public void run() {
 665                         try {
 666                             registerListener();
 667                         } catch (Throwable ex) {
 668                             ex = Utils.getActualException(ex);
 669                             EventQueue.invokeLater(new ThreadDialog(
 670                                     XSheet.this,
 671                                     ex.getMessage(),
 672                                     Messages.PROBLEM_ADDING_LISTENER,
 673                                     JOptionPane.ERROR_MESSAGE));
 674                         }
 675                     }
 676                 });
 677                 return;
 678             }
 679             // Unsubscribe button
 680             if (button == unsubscribeButton) {
 681                 mbeansTab.workerAdd(new Runnable() {
 682                     public void run() {
 683                         try {
 684                             unregisterListener();
 685                         } catch (Throwable ex) {
 686                             ex = Utils.getActualException(ex);
 687                             EventQueue.invokeLater(new ThreadDialog(
 688                                     XSheet.this,
 689                                     ex.getMessage(),
 690                                     Messages.PROBLEM_REMOVING_LISTENER,
 691                                     JOptionPane.ERROR_MESSAGE));
 692                         }
 693                     }
 694                 });
 695                 return;
 696             }
 697         }
 698     }
 699 }
< prev index next >