1 12 13 package org.ejtools.jmx.browser.ui; 14 15 16 17 import java.awt.Color ; 18 19 import java.awt.Component ; 20 21 import java.awt.GridBagConstraints ; 22 23 import java.awt.GridBagLayout ; 24 25 import java.awt.GridLayout ; 26 27 import java.awt.Insets ; 28 29 import java.awt.event.ActionEvent ; 30 31 import java.awt.event.ActionListener ; 32 33 import java.beans.Customizer ; 34 35 import java.beans.PropertyChangeEvent ; 36 37 import java.beans.PropertyChangeListener ; 38 39 import java.beans.PropertyEditor ; 40 41 import java.util.ArrayList ; 42 43 import java.util.Arrays ; 44 45 import java.util.Hashtable ; 46 47 import java.util.Iterator ; 48 49 import java.util.List ; 50 51 import java.util.ResourceBundle ; 52 53 54 55 import javax.management.Attribute ; 56 57 import javax.management.MBeanAttributeInfo ; 58 59 import javax.management.MBeanConstructorInfo ; 60 61 import javax.management.MBeanInfo ; 62 63 import javax.management.MBeanNotificationInfo ; 64 65 import javax.management.MBeanOperationInfo ; 66 67 import javax.management.MBeanParameterInfo ; 68 69 import javax.swing.BorderFactory ; 70 71 import javax.swing.JButton ; 72 73 import javax.swing.JComponent ; 74 75 import javax.swing.JLabel ; 76 77 import javax.swing.JPanel ; 78 79 import javax.swing.JScrollPane ; 80 81 import javax.swing.JTextArea ; 82 83 import javax.swing.SwingConstants ; 84 85 86 87 import org.apache.log4j.Logger; 88 89 import org.ejtools.adwt.AwtToolkit; 90 91 import org.ejtools.adwt.editor.ArrayEditor; 92 93 import org.ejtools.adwt.jmx.MBeanMethodDialog; 94 95 import org.ejtools.beans.CustomPropertyEditorManager; 96 97 import org.ejtools.graph.service.GraphConsumer; 98 99 import org.ejtools.graph.service.GraphConsumerMediator; 100 101 import org.ejtools.graph.service.GraphConsumerSelector; 102 103 import org.ejtools.jmx.MBeanAccessor; 104 105 import org.ejtools.jmx.MBeanSorter; 106 107 import org.ejtools.jmx.browser.model.Resource; 108 109 import org.ejtools.util.ClassTools; 110 111 112 113 import com.dreambean.awt.GenericPropertyCustomizer; 114 115 116 117 136 137 public class MBeanCustomizer extends JScrollPane implements Customizer , GraphConsumerMediator 138 139 { 140 141 142 143 private Hashtable invocationDialogs = new Hashtable (); 144 145 146 147 private JPanel mbeanAttributes = null; 148 149 150 151 private JPanel mbeanConstructors = null; 152 153 154 155 private JPanel mbeanInfo = null; 156 157 158 159 private JPanel mbeanNotifications = null; 160 161 162 163 private JPanel mbeanOperations = null; 164 165 166 167 private Resource object = null; 168 169 170 171 private JPanel p = null; 172 173 174 175 private JComponent previous; 176 177 178 179 private ArrayList updaters = new ArrayList (); 180 181 182 183 private static Logger logger = Logger.getLogger(MBeanCustomizer.class); 184 185 186 187 private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.jmx.browser.Resources"); 188 189 190 191 192 193 194 195 196 197 public MBeanCustomizer() 198 199 { 200 201 super(new JPanel ()); 202 203 this.setBorder(BorderFactory.createEmptyBorder()); 204 205 this.previous = null; 206 207 this.p = (JPanel ) getViewport().getView(); 208 209 this.p.setLayout(new GridBagLayout ()); 210 211 } 212 213 214 215 216 217 226 227 public MBeanCustomizer(Object obj) 228 229 { 230 231 this(); 232 233 this.setObject(obj); 234 235 } 236 237 238 239 240 241 250 251 public GraphConsumer[] getGraphConsumers() 252 253 { 254 255 return this.object.getGraphConsumers(); 256 257 } 258 259 260 261 262 263 272 273 public void setObject(Object obj) 274 275 { 276 277 try 278 279 { 280 281 this.p.removeAll(); 282 283 284 285 if (obj == null) 286 287 { 288 289 this.validate(); 290 291 this.repaint(); 292 293 return; 294 295 } 296 297 298 299 this.object = (Resource) obj; 300 301 MBeanInfo beaninfo = object.getMBeanInfo(); 302 303 304 305 GridBagConstraints gridbagconstraints = new GridBagConstraints (); 306 307 gridbagconstraints.insets = new Insets (3, 3, 3, 3); 308 309 gridbagconstraints.anchor = GridBagConstraints.NORTH; 310 311 gridbagconstraints.weightx = 1.0D; 312 313 gridbagconstraints.weighty = 0.0D; 314 315 gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; 316 317 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 318 319 320 321 this.buildInfosPanel(beaninfo, object); 322 323 this.buildConstructorsPanel(beaninfo); 324 325 this.buildNotificationsPanel(beaninfo); 326 327 this.buildAttributesPanel(beaninfo); 328 329 this.buildOperationsPanel(beaninfo); 330 331 332 333 this.p.add(mbeanInfo, gridbagconstraints); 334 335 if (this.mbeanConstructors != null) 336 337 { 338 339 this.p.add(this.mbeanConstructors, gridbagconstraints); 340 341 } 342 343 if (this.mbeanNotifications != null) 344 345 { 346 347 this.p.add(this.mbeanNotifications, gridbagconstraints); 348 349 } 350 351 if (this.mbeanAttributes != null) 352 353 { 354 355 this.p.add(this.mbeanAttributes, gridbagconstraints); 356 357 } 358 359 if (this.mbeanOperations != null) 360 361 { 362 363 this.p.add(this.mbeanOperations, gridbagconstraints); 364 365 } 366 367 368 369 371 gridbagconstraints.weighty = 1.0D; 372 373 gridbagconstraints.fill = GridBagConstraints.BOTH; 374 375 this.p.add(new JLabel (" "), gridbagconstraints); 376 377 378 379 this.validate(); 380 381 this.repaint(); 382 383 } 384 385 catch (Exception exception) 386 387 { 388 389 System.out.println("Exception occurred"); 390 391 exception.printStackTrace(); 392 393 } 394 395 } 396 397 398 399 400 401 412 413 protected void addProperty(PropertyEditor propertyeditor, MBeanAttributeInfo attributeInfo) 414 415 { 416 417 GridBagConstraints gridbagconstraints = new GridBagConstraints (); 418 419 gridbagconstraints.insets = new Insets (2, 2, 2, 2); 420 421 422 423 try 424 425 { 426 427 if (attributeInfo.isReadable()) 428 429 { 430 431 propertyeditor.setValue(object.getAttribute(attributeInfo.getName())); 432 433 } 434 435 } 436 437 catch (Throwable throwable) 438 439 { 440 441 logger.warn("Can't read the property from MBean", throwable); 442 443 } 444 445 446 447 449 JLabel label = new JLabel (attributeInfo.getName() + " :", SwingConstants.RIGHT); 450 451 label.setToolTipText(attributeInfo.getDescription()); 452 453 label.setForeground(AwtToolkit.DARK_BLUE); 454 455 456 457 459 JButton button = null; 460 461 Class c = ClassTools.getClass(attributeInfo.getType()); 462 463 if (ClassTools.isNumeric(c)) 464 465 { 466 467 button = new JButton (resources.getString("customizer.button.graph")); 468 469 final String name = attributeInfo.getName(); 470 471 button.addActionListener( 472 473 new ActionListener () 474 475 { 476 477 public void actionPerformed(ActionEvent e) 478 479 { 480 481 MBeanCustomizer.this.addToGraph(name); 482 483 } 484 485 } 486 487 ); 488 489 } 490 491 492 493 Object obj1; 494 495 if (propertyeditor.supportsCustomEditor()) 496 497 { 498 499 obj1 = propertyeditor.getCustomEditor(); 500 501 if (obj1 instanceof JComponent ) 502 503 { 504 505 if (previous != null) 506 507 { 508 509 previous.setNextFocusableComponent(((Component ) (obj1))); 510 511 } 512 513 previous = (JComponent ) obj1; 514 515 } 516 517 } 518 519 else 520 521 { 522 523 String [] tags = propertyeditor.getTags(); 524 525 if (tags != null) 526 527 { 528 529 obj1 = new GenericPropertyCustomizer(propertyeditor, tags); 530 531 if (previous != null) 532 533 { 534 535 previous.setNextFocusableComponent((Component ) (obj1)); 536 537 } 538 539 previous = (JComponent ) obj1; 540 541 } 542 543 else 544 545 { 546 547 if (attributeInfo.isWritable()) 548 549 { 550 551 obj1 = new GenericPropertyCustomizer(propertyeditor); 552 553 if (previous != null) 554 555 { 556 557 previous.setNextFocusableComponent((Component ) (obj1)); 558 559 } 560 561 previous = (JComponent ) obj1; 562 563 } 564 565 else 566 567 { 568 569 String content = "" + propertyeditor.getAsText(); 570 571 573 575 577 if (content.indexOf('\n') >= 0) 578 579 { 580 581 final JTextArea area = new JTextArea (propertyeditor.getAsText()); 582 583 area.setEditable(false); 584 585 final PropertyEditor pcEditor = propertyeditor; 586 587 obj1 = area; 588 589 pcEditor.addPropertyChangeListener( 590 591 new PropertyChangeListener () 592 593 { 594 595 public void propertyChange(PropertyChangeEvent evt) 596 597 { 598 599 area.setText(pcEditor.getAsText()); 600 601 } 602 603 }); 604 605 } 606 607 else 608 609 { 610 611 final JLabel lbl = new JLabel (propertyeditor.getAsText()); 612 613 final PropertyEditor pcEditor = propertyeditor; 614 615 obj1 = lbl; 616 617 pcEditor.addPropertyChangeListener( 618 619 new PropertyChangeListener () 620 621 { 622 623 public void propertyChange(PropertyChangeEvent evt) 624 625 { 626 627 lbl.setText(pcEditor.getAsText()); 628 629 } 630 631 }); 632 633 } 634 635 } 636 637 } 638 639 } 640 641 642 643 gridbagconstraints.anchor = GridBagConstraints.NORTH; 644 645 gridbagconstraints.weighty = 1.0D; 646 647 gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; 648 649 650 651 if (button != null) 652 653 { 654 655 gridbagconstraints.weightx = 0.0D; 656 657 gridbagconstraints.gridwidth = 1; 658 659 this.mbeanAttributes.add(label, gridbagconstraints); 660 661 662 663 gridbagconstraints.weightx = 1.0D; 664 665 gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE; 666 667 this.mbeanAttributes.add(((Component ) (obj1)), gridbagconstraints); 668 669 670 671 gridbagconstraints.weightx = 0.0D; 672 673 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 674 675 this.mbeanAttributes.add(button, gridbagconstraints); 676 677 } 678 679 else 680 681 { 682 683 gridbagconstraints.weightx = 0.0D; 684 685 gridbagconstraints.gridwidth = 1; 686 687 this.mbeanAttributes.add(label, gridbagconstraints); 688 689 690 691 gridbagconstraints.weightx = 1.0D; 692 693 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 694 695 this.mbeanAttributes.add(((Component ) (obj1)), gridbagconstraints); 696 697 } 698 699 701 Updater updater = new Updater(propertyeditor, attributeInfo); 702 703 this.getUpdaters().add(updater); 704 705 } 706 707 708 709 710 711 720 721 protected void addToGraph(String attribute) 722 723 { 724 725 GraphConsumer consumer = GraphConsumerSelector.selectWithDialog(this); 726 727 if (consumer != null) 728 729 { 730 731 this.object.registerForGraph(consumer, attribute); 732 733 } 734 735 } 736 737 738 739 740 741 754 755 protected void addUnsupportedProperty(MBeanAttributeInfo attributeInfo) 756 757 { 758 759 GridBagConstraints gridbagconstraints = new GridBagConstraints (); 760 761 gridbagconstraints.insets = new Insets (2, 2, 2, 2); 762 763 764 765 JLabel jlabel = new JLabel (attributeInfo.getName() + " :", SwingConstants.RIGHT); 766 767 jlabel.setToolTipText(attributeInfo.getDescription()); 768 769 jlabel.setForeground(AwtToolkit.DARK_BLUE); 770 771 772 773 gridbagconstraints.anchor = GridBagConstraints.NORTH; 774 775 gridbagconstraints.weightx = 0.0D; 776 777 gridbagconstraints.weighty = 1.0D; 778 779 gridbagconstraints.gridwidth = 1; 780 781 gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; 782 783 784 785 this.mbeanAttributes.add(jlabel, gridbagconstraints); 786 787 788 789 JLabel lbl = new JLabel (resources.getString("customizer.text.unloadable.class") + " " + ClassTools.classDisplay(attributeInfo.getType())); 790 791 lbl.setForeground(AwtToolkit.DARK_RED); 792 793 794 795 gridbagconstraints.weightx = 1.0D; 796 797 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 798 799 800 801 this.mbeanAttributes.add(lbl, gridbagconstraints); 802 803 } 804 805 806 807 808 809 818 819 protected void buildAttributesPanel(MBeanInfo info) 820 821 { 822 823 GridBagConstraints gridbagconstraints = new GridBagConstraints (); 824 825 gridbagconstraints.insets = new Insets (0, 0, 0, 0); 826 827 gridbagconstraints.anchor = GridBagConstraints.NORTH; 828 829 gridbagconstraints.weightx = 0.0D; 830 831 gridbagconstraints.weighty = 1.0D; 832 833 gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; 834 835 836 837 MBeanAttributeInfo [] infosArray = info.getAttributes(); 838 839 if (infosArray.length == 0) 840 841 { 842 843 return; 844 845 } 846 847 List infos = Arrays.asList(infosArray); 848 849 MBeanSorter.sortByName(infos); 850 851 852 853 this.mbeanAttributes = new JPanel (new GridBagLayout ()); 854 855 this.mbeanAttributes.setBorder(BorderFactory.createTitledBorder(resources.getString("customizer.text.attributes"))); 856 857 for (int i = 0; i < infos.size(); i++) 858 859 { 860 861 MBeanAttributeInfo attributeInfo = (MBeanAttributeInfo ) infos.get(i); 862 863 PropertyEditor propertyeditor = null; 864 865 Class c = ClassTools.getClass(attributeInfo.getType()); 866 867 868 869 if (c == null) 870 871 { 872 873 this.addUnsupportedProperty(attributeInfo); 874 875 } 876 877 else 878 879 { 880 881 if (c.isArray()) 882 883 { 884 885 Class componentType = c.getComponentType(); 886 887 propertyeditor = new ArrayEditor(componentType); 888 889 this.addProperty(propertyeditor, attributeInfo); 890 891 } 892 893 else 894 895 { 896 897 propertyeditor = CustomPropertyEditorManager.findEditor(c); 898 899 if (propertyeditor == null) 900 901 { 902 903 propertyeditor = CustomPropertyEditorManager.findEditor(String .class); 904 905 } 906 907 this.addProperty(propertyeditor, attributeInfo); 908 909 } 910 911 gridbagconstraints.weighty = 1.0D; 912 913 } 914 915 } 916 917 918 919 gridbagconstraints.weightx = 1.0D; 920 921 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 922 923 924 925 JPanel buttonPanel = new JPanel (new GridLayout (1, 2, 1, 1)); 926 927 JButton button1 = new JButton (resources.getString("customizer.button.refresh")); 928 929 button1.addActionListener( 930 931 new ActionListener () 932 933 { 934 935 public void actionPerformed(ActionEvent e) 936 937 { 938 939 try 940 941 { 942 943 Iterator it = MBeanCustomizer.this.getUpdaters().iterator(); 944 945 while (it.hasNext()) 946 947 { 948 949 Updater updater = (Updater) it.next(); 950 951 updater.updateFromBean(); 952 953 } 954 955 } 956 957 catch (Exception ex) 958 959 { 960 961 logger.error("Error while refreshing" + ex); 962 963 } 964 965 } 966 967 } 968 969 ); 970 971 JButton button2 = new JButton (resources.getString("customizer.button.update")); 972 973 button2.addActionListener( 974 975 new ActionListener () 976 977 { 978 979 public void actionPerformed(ActionEvent e) 980 981 { 982 983 try 984 985 { 986 987 Iterator it = updaters.iterator(); 988 989 while (it.hasNext()) 990 991 { 992 993 Updater updater = (Updater) it.next(); 994 995 updater.updateFromEditor(); 996 997 updater.updateFromBean(); 998 999 } 1000 1001 } 1002 1003 catch (Exception ex) 1004 1005 { 1006 1007 logger.error("Error while updating" + ex); 1008 1009 } 1010 1011 } 1012 1013 } 1014 1015 ); 1016 1017 buttonPanel.add(button1); 1018 1019 buttonPanel.add(button2); 1020 1021 this.mbeanAttributes.add(buttonPanel, gridbagconstraints); 1022 1023 } 1024 1025 1026 1027 1028 1029 1038 1039 protected void buildConstructorsPanel(MBeanInfo info) 1040 1041 { 1042 1043 GridBagConstraints gridbagconstraints = new GridBagConstraints (); 1044 1045 gridbagconstraints.insets = new Insets (0, 0, 0, 0); 1046 1047 gridbagconstraints.anchor = GridBagConstraints.NORTH; 1048 1049 gridbagconstraints.weightx = 1.0D; 1050 1051 gridbagconstraints.weighty = 1.0D; 1052 1053 gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; 1054 1055 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 1056 1057 1058 1059 MBeanConstructorInfo [] infosArray = info.getConstructors(); 1060 1061 if (infosArray.length == 0) 1062 1063 { 1064 1065 return; 1066 1067 } 1068 1069 List infos = Arrays.asList(infosArray); 1070 1071 MBeanSorter.sortByName(infos); 1072 1073 1074 1075 this.mbeanConstructors = new JPanel (new GridBagLayout ()); 1076 1077 this.mbeanConstructors.setBorder(BorderFactory.createTitledBorder(resources.getString("customizer.text.constructors"))); 1078 1079 for (int i = 0; i < infos.size(); i++) 1080 1081 { 1082 1083 MBeanConstructorInfo ctorInfo = (MBeanConstructorInfo ) infos.get(i); 1084 1085 StringBuffer display = new StringBuffer (); 1086 1087 display.append(ctorInfo.getName()); 1088 1089 display.append("("); 1090 1091 MBeanParameterInfo [] parameters = ctorInfo.getSignature(); 1092 1093 if (parameters.length > 0) 1094 1095 { 1096 1097 for (int j = 0; j < parameters.length; j++) 1098 1099 { 1100 1101 if (j > 0) 1102 1103 { 1104 1105 display.append(", "); 1106 1107 } 1108 1109 display.append(ClassTools.classDisplay(parameters[j].getType())); 1110 1111 } 1112 1113 } 1114 1115 display.append(")"); 1116 1117 1118 1119 JLabel label = new JLabel (display.toString(), SwingConstants.LEFT); 1120 1121 label.setToolTipText(ctorInfo.getDescription()); 1122 1123 label.setForeground(Color.black); 1124 1125 this.mbeanConstructors.add(label, gridbagconstraints); 1126 1127 } 1128 1129 } 1130 1131 1132 1133 1134 1135 1146 1147 protected void buildInfosPanel(MBeanInfo info, MBeanAccessor object) 1148 1149 { 1150 1151 JLabel label = null; 1152 1153 GridBagConstraints gridbagconstraints = new GridBagConstraints (); 1154 1155 gridbagconstraints.insets = new Insets (0, 0, 0, 0); 1156 1157 gridbagconstraints.anchor = GridBagConstraints.NORTH; 1158 1159 gridbagconstraints.weightx = 0.0D; 1160 1161 gridbagconstraints.weighty = 1.0D; 1162 1163 gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; 1164 1165 1166 1167 this.mbeanInfo = new JPanel (new GridBagLayout ()); 1168 1169 this.mbeanInfo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), object.getCanonicalName())); 1170 1171 1172 1173 gridbagconstraints.weightx = 0.0D; 1174 1175 gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE; 1176 1177 label = new JLabel (resources.getString("customizer.text.class.name") + " : ", SwingConstants.RIGHT); 1178 1179 label.setToolTipText(resources.getString("customizer.tooltip.class.name")); 1180 1181 label.setForeground(AwtToolkit.DARK_BLUE); 1182 1183 this.mbeanInfo.add(label, gridbagconstraints); 1184 1185 1186 1187 gridbagconstraints.weightx = 1.0D; 1188 1189 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 1190 1191 label = new JLabel (info.getClassName(), SwingConstants.LEFT); 1192 1193 label.setForeground(Color.black); 1194 1195 this.mbeanInfo.add(label, gridbagconstraints); 1196 1197 1198 1199 gridbagconstraints.weightx = 0.0D; 1200 1201 gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE; 1202 1203 label = new JLabel (resources.getString("customizer.text.class.description") + " : ", SwingConstants.RIGHT); 1204 1205 label.setToolTipText(resources.getString("customizer.tooltip.class.description")); 1206 1207 label.setForeground(AwtToolkit.DARK_BLUE); 1208 1209 this.mbeanInfo.add(label, gridbagconstraints); 1210 1211 1212 1213 gridbagconstraints.weightx = 1.0D; 1214 1215 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 1216 1217 label = new JLabel (info.getDescription(), SwingConstants.LEFT); 1218 1219 label.setForeground(Color.black); 1220 1221 this.mbeanInfo.add(label, gridbagconstraints); 1222 1223 1224 1225 JPanel buttonPanel = new JPanel (new GridLayout (1, 2, 5, 5)); 1226 1227 JButton button1 = new JButton (resources.getString("customizer.button.unregister")); 1228 1229 button1.addActionListener( 1230 1231 new ActionListener () 1232 1233 { 1234 1235 public void actionPerformed(ActionEvent e) 1236 1237 { 1238 1239 try 1240 1241 { 1242 1243 MBeanCustomizer.this.object.unregisterMBean(); 1244 1245 } 1246 1247 catch (Exception ue) 1248 1249 { 1250 1251 } 1252 1253 } 1254 1255 } 1256 1257 ); 1258 1259 1260 1261 buttonPanel.add(button1); 1262 1263 this.mbeanInfo.add(buttonPanel, gridbagconstraints); 1264 1265 } 1266 1267 1268 1269 1270 1271 1280 1281 protected void buildNotificationsPanel(MBeanInfo info) 1282 1283 { 1284 1285 GridBagConstraints gridbagconstraints = new GridBagConstraints (); 1286 1287 gridbagconstraints.insets = new Insets (0, 0, 0, 0); 1288 1289 gridbagconstraints.anchor = GridBagConstraints.NORTH; 1290 1291 gridbagconstraints.weightx = 0.0D; 1292 1293 gridbagconstraints.weighty = 1.0D; 1294 1295 gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; 1296 1297 1298 1299 MBeanNotificationInfo [] infosArray = info.getNotifications(); 1300 1301 if (infosArray.length == 0) 1302 1303 { 1304 1305 return; 1306 1307 } 1308 1309 List infos = Arrays.asList(infosArray); 1310 1311 MBeanSorter.sortByName(infos); 1312 1313 1314 1315 this.mbeanNotifications = new JPanel (new GridBagLayout ()); 1316 1317 this.mbeanNotifications.setBorder(BorderFactory.createTitledBorder(resources.getString("customizer.text.notifications"))); 1318 1319 for (int i = 0; i < infos.size(); i++) 1320 1321 { 1322 1323 MBeanNotificationInfo notificationInfo = (MBeanNotificationInfo ) infos.get(i); 1324 1325 gridbagconstraints.weightx = 0.0D; 1326 1327 gridbagconstraints.gridheight = notificationInfo.getNotifTypes().length; 1328 1329 gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE; 1330 1331 JLabel label = new JLabel (notificationInfo.getName() + " ", SwingConstants.RIGHT); 1332 1333 label.setToolTipText(notificationInfo.getDescription()); 1334 1335 label.setForeground(AwtToolkit.DARK_BLUE); 1336 1337 this.mbeanNotifications.add(label, gridbagconstraints); 1338 1339 1340 1341 gridbagconstraints.weightx = 1.0D; 1342 1343 gridbagconstraints.gridheight = 1; 1344 1345 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 1346 1347 for (int j = 0; j < notificationInfo.getNotifTypes().length; j++) 1348 1349 { 1350 1351 label = new JLabel (notificationInfo.getNotifTypes()[j], SwingConstants.LEFT); 1352 1353 label.setForeground(Color.black); 1354 1355 this.mbeanNotifications.add(label, gridbagconstraints); 1356 1357 } 1358 1359 } 1360 1361 1362 1363 gridbagconstraints.weightx = 1.0D; 1364 1365 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 1366 1367 1368 1369 JPanel buttonPanel = new JPanel (new GridLayout (1, 2, 1, 1)); 1370 1371 final JButton button1 = new JButton (resources.getString("customizer.button.listen")); 1372 1373 final JButton button2 = new JButton (resources.getString("customizer.button.unlisten")); 1374 1375 1376 1377 button1.addActionListener( 1378 1379 new ActionListener () 1380 1381 { 1382 1383 public void actionPerformed(ActionEvent e) 1384 1385 { 1386 1387 try 1388 1389 { 1390 1391 MBeanCustomizer.this.object.registerForNotifications(); 1392 1393 if (MBeanCustomizer.this.object.isRegisteredForNotifications()) 1394 1395 { 1396 1397 button1.setEnabled(false); 1398 1399 button2.setEnabled(true); 1400 1401 } 1402 1403 } 1404 1405 catch (Exception ue) 1406 1407 { 1408 1409 } 1410 1411 } 1412 1413 } 1414 1415 ); 1416 1417 1418 1419 button2.addActionListener( 1420 1421 new ActionListener () 1422 1423 { 1424 1425 public void actionPerformed(ActionEvent e) 1426 1427 { 1428 1429 try 1430 1431 { 1432 1433 MBeanCustomizer.this.object.unregisterForNotifications(); 1434 1435 if (!MBeanCustomizer.this.object.isRegisteredForNotifications()) 1436 1437 { 1438 1439 button1.setEnabled(true); 1440 1441 button2.setEnabled(false); 1442 1443 } 1444 1445 } 1446 1447 catch (Exception ue) 1448 1449 { 1450 1451 } 1452 1453 } 1454 1455 } 1456 1457 ); 1458 1459 1460 1461 try 1462 1463 { 1464 1465 if (MBeanCustomizer.this.object.isRegisteredForNotifications()) 1466 1467 { 1468 1469 button1.setEnabled(false); 1470 1471 button2.setEnabled(true); 1472 1473 } 1474 1475 else 1476 1477 { 1478 1479 button1.setEnabled(true); 1480 1481 button2.setEnabled(false); 1482 1483 } 1484 1485 } 1486 1487 catch (Exception ue) 1488 1489 { 1490 1491 } 1492 1493 1494 1495 buttonPanel.add(button1); 1496 1497 buttonPanel.add(button2); 1498 1499 this.mbeanNotifications.add(buttonPanel, gridbagconstraints); 1500 1501 } 1502 1503 1504 1505 1506 1507 1516 1517 protected void buildOperationsPanel(MBeanInfo info) 1518 1519 { 1520 1521 GridBagConstraints gridbagconstraints = new GridBagConstraints (); 1522 1523 gridbagconstraints.insets = new Insets (0, 0, 0, 0); 1524 1525 gridbagconstraints.anchor = GridBagConstraints.NORTH; 1526 1527 gridbagconstraints.weightx = 1.0D; 1528 1529 gridbagconstraints.weighty = 1.0D; 1530 1531 gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; 1532 1533 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 1534 1535 1536 1537 MBeanOperationInfo [] infosArray = info.getOperations(); 1538 1539 if (infosArray.length == 0) 1540 1541 { 1542 1543 return; 1544 1545 } 1546 1547 List infos = Arrays.asList(infosArray); 1548 1549 MBeanSorter.sortByName(infos); 1550 1551 1552 1553 this.mbeanOperations = new JPanel (new GridBagLayout ()); 1554 1555 this.mbeanOperations.setBorder(BorderFactory.createTitledBorder(resources.getString("customizer.text.operations"))); 1556 1557 for (int i = 0; i < infos.size(); i++) 1558 1559 { 1560 1561 MBeanOperationInfo operationInfo = (MBeanOperationInfo ) infos.get(i); 1562 1563 1564 1565 gridbagconstraints.weightx = 0.0D; 1566 1567 gridbagconstraints.gridwidth = 1; 1568 1569 String returnType = ClassTools.classDisplay(operationInfo.getReturnType() + " "); 1570 1571 JLabel label = new JLabel (returnType, SwingConstants.RIGHT); 1572 1573 label.setForeground(AwtToolkit.DARK_BLUE); 1574 1575 this.mbeanOperations.add(label, gridbagconstraints); 1576 1577 1578 1579 StringBuffer display = new StringBuffer (); 1580 1581 display.append(operationInfo.getName()); 1582 1583 display.append("("); 1584 1585 MBeanParameterInfo [] parameters = operationInfo.getSignature(); 1586 1587 if (parameters.length > 0) 1588 1589 { 1590 1591 for (int j = 0; j < parameters.length; j++) 1592 1593 { 1594 1595 if (j > 0) 1596 1597 { 1598 1599 display.append(", "); 1600 1601 } 1602 1603 display.append(ClassTools.classDisplay(parameters[j].getType())); 1604 1605 } 1606 1607 } 1608 1609 display.append(")"); 1610 1611 1612 1613 gridbagconstraints.weightx = 1.0D; 1614 1615 gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE; 1616 1617 label = new JLabel (display.toString(), SwingConstants.LEFT); 1618 1619 label.setToolTipText(operationInfo.getDescription()); 1620 1621 label.setForeground(Color.black); 1622 1623 this.mbeanOperations.add(label, gridbagconstraints); 1624 1625 1626 1627 gridbagconstraints.weightx = 0.0D; 1628 1629 gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; 1630 1631 JButton button = new JButton (resources.getString("customizer.button.invoke")); 1632 1633 final MBeanMethodDialog dialog = new MBeanMethodDialog(this.object, operationInfo, null); 1634 1635 this.invocationDialogs.put(operationInfo.getName(), dialog); 1636 1637 button.addActionListener( 1638 1639 new ActionListener () 1640 1641 { 1642 1643 public void actionPerformed(ActionEvent e) 1644 1645 { 1646 1647 dialog.show(); 1648 1649 } 1650 1651 } 1652 1653 ); 1654 1655 this.mbeanOperations.add(button, gridbagconstraints); 1656 1657 } 1658 1659 } 1660 1661 1662 1663 1664 1665 1674 1675 protected ArrayList getUpdaters() 1676 1677 { 1678 1679 if (this.updaters == null) 1680 1681 { 1682 1683 this.updaters = new ArrayList (); 1684 1685 } 1686 1687 return this.updaters; 1688 1689 } 1690 1691 1692 1693 1694 1695 1708 1709 protected void updated(String s, Object obj, Object obj1) 1710 1711 { 1712 1713 this.firePropertyChange(s, obj, obj1); 1714 1715 } 1716 1717 1718 1719 1720 1721 1734 1735 protected class Updater 1736 1737 { 1738 1739 1740 1741 protected PropertyEditor editor; 1742 1743 1744 1745 protected MBeanAttributeInfo info; 1746 1747 1748 1749 1750 1751 1762 1763 public Updater(PropertyEditor editor, MBeanAttributeInfo info) 1764 1765 { 1766 1767 this.editor = editor; 1768 1769 this.info = info; 1770 1771 } 1772 1773 1774 1775 1776 1777 1778 1779 public void updateFromBean() 1780 1781 { 1782 1783 if (this.info.isReadable()) 1784 1785 { 1786 1787 try 1788 1789 { 1790 1791 this.editor.setValue(MBeanCustomizer.this.object.getAttribute(this.info.getName())); 1792 1793 } 1794 1795 catch (Exception e) 1796 1797 { 1798 1799 e.printStackTrace(); 1800 1801 } 1802 1803 } 1804 1805 } 1806 1807 1808 1809 1810 1811 1812 1813 public void updateFromEditor() 1814 1815 { 1816 1817 if (this.info.isWritable()) 1818 1819 { 1820 1821 try 1822 1823 { 1824 1825 Object newValue = this.editor.getValue(); 1826 1827 if (newValue != null) 1828 1829 { 1830 1831 Attribute attr = new Attribute (this.info.getName(), newValue); 1832 1833 if (this.info.isReadable()) 1834 1835 { 1836 1837 Object oldValue = MBeanCustomizer.this.object.getAttribute(this.info.getName()); 1838 1839 if (!newValue.equals(oldValue)) 1840 1841 { 1842 1843 MBeanCustomizer.this.object.setAttribute(attr); 1844 1845 } 1846 1847 } 1848 1849 else 1850 1851 { 1852 1853 MBeanCustomizer.this.object.setAttribute(attr); 1854 1855 } 1856 1857 } 1858 1859 } 1860 1861 catch (Exception e) 1862 1863 { 1864 1865 e.printStackTrace(); 1866 1867 } 1868 1869 } 1870 1871 } 1872 1873 } 1874 1875} 1876 1877 | Popular Tags |