KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > ui > MBeanCustomizer


1 /*
2
3  * EJTools, the Enterprise Java Tools
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms of license at www.gnu.org.
10
11  */

12
13 package org.ejtools.jmx.browser.ui;
14
15
16
17 import java.awt.Color JavaDoc;
18
19 import java.awt.Component JavaDoc;
20
21 import java.awt.GridBagConstraints JavaDoc;
22
23 import java.awt.GridBagLayout JavaDoc;
24
25 import java.awt.GridLayout JavaDoc;
26
27 import java.awt.Insets JavaDoc;
28
29 import java.awt.event.ActionEvent JavaDoc;
30
31 import java.awt.event.ActionListener JavaDoc;
32
33 import java.beans.Customizer JavaDoc;
34
35 import java.beans.PropertyChangeEvent JavaDoc;
36
37 import java.beans.PropertyChangeListener JavaDoc;
38
39 import java.beans.PropertyEditor JavaDoc;
40
41 import java.util.ArrayList JavaDoc;
42
43 import java.util.Arrays JavaDoc;
44
45 import java.util.Hashtable JavaDoc;
46
47 import java.util.Iterator JavaDoc;
48
49 import java.util.List JavaDoc;
50
51 import java.util.ResourceBundle JavaDoc;
52
53
54
55 import javax.management.Attribute JavaDoc;
56
57 import javax.management.MBeanAttributeInfo JavaDoc;
58
59 import javax.management.MBeanConstructorInfo JavaDoc;
60
61 import javax.management.MBeanInfo JavaDoc;
62
63 import javax.management.MBeanNotificationInfo JavaDoc;
64
65 import javax.management.MBeanOperationInfo JavaDoc;
66
67 import javax.management.MBeanParameterInfo JavaDoc;
68
69 import javax.swing.BorderFactory JavaDoc;
70
71 import javax.swing.JButton JavaDoc;
72
73 import javax.swing.JComponent JavaDoc;
74
75 import javax.swing.JLabel JavaDoc;
76
77 import javax.swing.JPanel JavaDoc;
78
79 import javax.swing.JScrollPane JavaDoc;
80
81 import javax.swing.JTextArea JavaDoc;
82
83 import javax.swing.SwingConstants JavaDoc;
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 /**
118
119  * Description of the Class
120
121  *
122
123  * @author letiemble
124
125  * @version $Revision: 1.7 $
126
127  * @created 8 avril 2002
128
129  * @todo Protected method to choose PropertyEditor by Class and Name
130
131  * @todo Non Supported classes displayed
132
133  * @todo Result of Command put into an Output List
134
135  */

136
137 public class MBeanCustomizer extends JScrollPane JavaDoc implements Customizer JavaDoc, GraphConsumerMediator
138
139 {
140
141    /** Description of the Field */
142
143    private Hashtable JavaDoc invocationDialogs = new Hashtable JavaDoc();
144
145    /** Description of the Field */
146
147    private JPanel JavaDoc mbeanAttributes = null;
148
149    /** Description of the Field */
150
151    private JPanel JavaDoc mbeanConstructors = null;
152
153    /** Description of the Field */
154
155    private JPanel JavaDoc mbeanInfo = null;
156
157    /** Description of the Field */
158
159    private JPanel JavaDoc mbeanNotifications = null;
160
161    /** Description of the Field */
162
163    private JPanel JavaDoc mbeanOperations = null;
164
165    /** Description of the Field */
166
167    private Resource object = null;
168
169    /** Description of the Field */
170
171    private JPanel JavaDoc p = null;
172
173    /** Description of the Field */
174
175    private JComponent JavaDoc previous;
176
177    /** Description of the Field */
178
179    private ArrayList JavaDoc updaters = new ArrayList JavaDoc();
180
181    /** Description of the Field */
182
183    private static Logger logger = Logger.getLogger(MBeanCustomizer.class);
184
185    /** Description of the Field */
186
187    private static ResourceBundle JavaDoc resources = ResourceBundle.getBundle("org.ejtools.jmx.browser.Resources");
188
189
190
191
192
193
194
195    /** Constructor for the GenericCustomizer object */
196
197    public MBeanCustomizer()
198
199    {
200
201       super(new JPanel JavaDoc());
202
203       this.setBorder(BorderFactory.createEmptyBorder());
204
205       this.previous = null;
206
207       this.p = (JPanel JavaDoc) getViewport().getView();
208
209       this.p.setLayout(new GridBagLayout JavaDoc());
210
211    }
212
213
214
215
216
217    /**
218
219     * Constructor for the GenericCustomizer object
220
221     *
222
223     * @param obj Description of Parameter
224
225     */

226
227    public MBeanCustomizer(Object JavaDoc obj)
228
229    {
230
231       this();
232
233       this.setObject(obj);
234
235    }
236
237
238
239
240
241    /**
242
243     * Gets the graphConsumers attribute of the ManagedObject object
244
245     *
246
247     * @return The graphConsumers value
248
249     */

250
251    public GraphConsumer[] getGraphConsumers()
252
253    {
254
255       return this.object.getGraphConsumers();
256
257    }
258
259
260
261
262
263    /**
264
265     * Sets the Object attribute of the GenericCustomizer object
266
267     *
268
269     * @param obj The new Object value
270
271     */

272
273    public void setObject(Object JavaDoc 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 JavaDoc beaninfo = object.getMBeanInfo();
302
303
304
305          GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
306
307          gridbagconstraints.insets = new Insets JavaDoc(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          // Add a spacer
370

371          gridbagconstraints.weighty = 1.0D;
372
373          gridbagconstraints.fill = GridBagConstraints.BOTH;
374
375          this.p.add(new JLabel JavaDoc(" "), gridbagconstraints);
376
377
378
379          this.validate();
380
381          this.repaint();
382
383       }
384
385       catch (Exception JavaDoc exception)
386
387       {
388
389          System.out.println("Exception occurred");
390
391          exception.printStackTrace();
392
393       }
394
395    }
396
397
398
399
400
401    /**
402
403     * Adds a feature to the Property attribute of the GenericCustomizer object
404
405     *
406
407     * @param propertyeditor The feature to be added to the Property attribute
408
409     * @param attributeInfo The feature to be added to the Property attribute
410
411     */

412
413    protected void addProperty(PropertyEditor JavaDoc propertyeditor, MBeanAttributeInfo JavaDoc attributeInfo)
414
415    {
416
417       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
418
419       gridbagconstraints.insets = new Insets JavaDoc(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 JavaDoc throwable)
438
439       {
440
441          logger.warn("Can't read the property from MBean", throwable);
442
443       }
444
445
446
447       // Create the attribute label
448

449       JLabel JavaDoc label = new JLabel JavaDoc(attributeInfo.getName() + " :", SwingConstants.RIGHT);
450
451       label.setToolTipText(attributeInfo.getDescription());
452
453       label.setForeground(AwtToolkit.DARK_BLUE);
454
455
456
457       // Check if the attribute is numeric and grapheable
458

459       JButton JavaDoc button = null;
460
461       Class JavaDoc c = ClassTools.getClass(attributeInfo.getType());
462
463       if (ClassTools.isNumeric(c))
464
465       {
466
467          button = new JButton JavaDoc(resources.getString("customizer.button.graph"));
468
469          final String JavaDoc name = attributeInfo.getName();
470
471          button.addActionListener(
472
473             new ActionListener JavaDoc()
474
475             {
476
477                public void actionPerformed(ActionEvent JavaDoc e)
478
479                {
480
481                   MBeanCustomizer.this.addToGraph(name);
482
483                }
484
485             }
486
487             );
488
489       }
490
491
492
493       Object JavaDoc obj1;
494
495       if (propertyeditor.supportsCustomEditor())
496
497       {
498
499          obj1 = propertyeditor.getCustomEditor();
500
501          if (obj1 instanceof JComponent JavaDoc)
502
503          {
504
505             if (previous != null)
506
507             {
508
509                previous.setNextFocusableComponent(((Component JavaDoc) (obj1)));
510
511             }
512
513             previous = (JComponent JavaDoc) obj1;
514
515          }
516
517       }
518
519       else
520
521       {
522
523          String JavaDoc[] 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 JavaDoc) (obj1));
536
537             }
538
539             previous = (JComponent JavaDoc) 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 JavaDoc) (obj1));
558
559                }
560
561                previous = (JComponent JavaDoc) obj1;
562
563             }
564
565             else
566
567             {
568
569                String JavaDoc content = "" + propertyeditor.getAsText();
570
571                //
572

573                // ToDo : Put in constant
574

575                //
576

577                if (content.indexOf('\n') >= 0)
578
579                {
580
581                   final JTextArea JavaDoc area = new JTextArea JavaDoc(propertyeditor.getAsText());
582
583                   area.setEditable(false);
584
585                   final PropertyEditor JavaDoc pcEditor = propertyeditor;
586
587                   obj1 = area;
588
589                   pcEditor.addPropertyChangeListener(
590
591                      new PropertyChangeListener JavaDoc()
592
593                      {
594
595                         public void propertyChange(PropertyChangeEvent JavaDoc evt)
596
597                         {
598
599                            area.setText(pcEditor.getAsText());
600
601                         }
602
603                      });
604
605                }
606
607                else
608
609                {
610
611                   final JLabel JavaDoc lbl = new JLabel JavaDoc(propertyeditor.getAsText());
612
613                   final PropertyEditor JavaDoc pcEditor = propertyeditor;
614
615                   obj1 = lbl;
616
617                   pcEditor.addPropertyChangeListener(
618
619                      new PropertyChangeListener JavaDoc()
620
621                      {
622
623                         public void propertyChange(PropertyChangeEvent JavaDoc 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 JavaDoc) (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 JavaDoc) (obj1)), gridbagconstraints);
696
697       }
698
699       // Allow attribute to be update
700

701       Updater updater = new Updater(propertyeditor, attributeInfo);
702
703       this.getUpdaters().add(updater);
704
705    }
706
707
708
709
710
711    /**
712
713     * Adds a feature to the ToGraph attribute of the FullMBeanCustomizer object
714
715     *
716
717     * @param attribute The feature to be added to the ToGraph attribute
718
719     */

720
721    protected void addToGraph(String JavaDoc 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    /**
742
743     * Adds a feature to the UnsupportedProperty attribute of the
744
745     * GenericMBeanCustomizer object
746
747     *
748
749     * @param attributeInfo The feature to be added to the UnsupportedProperty
750
751     * attribute
752
753     */

754
755    protected void addUnsupportedProperty(MBeanAttributeInfo JavaDoc attributeInfo)
756
757    {
758
759       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
760
761       gridbagconstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
762
763
764
765       JLabel JavaDoc jlabel = new JLabel JavaDoc(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 JavaDoc lbl = new JLabel JavaDoc(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    /**
810
811     * Description of the Method
812
813     *
814
815     * @param info Description of the Parameter
816
817     */

818
819    protected void buildAttributesPanel(MBeanInfo JavaDoc info)
820
821    {
822
823       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
824
825       gridbagconstraints.insets = new Insets JavaDoc(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 JavaDoc[] infosArray = info.getAttributes();
838
839       if (infosArray.length == 0)
840
841       {
842
843          return;
844
845       }
846
847       List JavaDoc infos = Arrays.asList(infosArray);
848
849       MBeanSorter.sortByName(infos);
850
851
852
853       this.mbeanAttributes = new JPanel JavaDoc(new GridBagLayout JavaDoc());
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 JavaDoc attributeInfo = (MBeanAttributeInfo JavaDoc) infos.get(i);
862
863          PropertyEditor JavaDoc propertyeditor = null;
864
865          Class JavaDoc 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 JavaDoc 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 JavaDoc.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 JavaDoc buttonPanel = new JPanel JavaDoc(new GridLayout JavaDoc(1, 2, 1, 1));
926
927       JButton JavaDoc button1 = new JButton JavaDoc(resources.getString("customizer.button.refresh"));
928
929       button1.addActionListener(
930
931          new ActionListener JavaDoc()
932
933          {
934
935             public void actionPerformed(ActionEvent JavaDoc e)
936
937             {
938
939                try
940
941                {
942
943                   Iterator JavaDoc 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 JavaDoc ex)
958
959                {
960
961                   logger.error("Error while refreshing" + ex);
962
963                }
964
965             }
966
967          }
968
969          );
970
971       JButton JavaDoc button2 = new JButton JavaDoc(resources.getString("customizer.button.update"));
972
973       button2.addActionListener(
974
975          new ActionListener JavaDoc()
976
977          {
978
979             public void actionPerformed(ActionEvent JavaDoc e)
980
981             {
982
983                try
984
985                {
986
987                   Iterator JavaDoc 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 JavaDoc 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   /**
1030
1031    * Description of the Method
1032
1033    *
1034
1035    * @param info Description of the Parameter
1036
1037    */

1038
1039   protected void buildConstructorsPanel(MBeanInfo JavaDoc info)
1040
1041   {
1042
1043      GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
1044
1045      gridbagconstraints.insets = new Insets JavaDoc(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 JavaDoc[] infosArray = info.getConstructors();
1060
1061      if (infosArray.length == 0)
1062
1063      {
1064
1065         return;
1066
1067      }
1068
1069      List JavaDoc infos = Arrays.asList(infosArray);
1070
1071      MBeanSorter.sortByName(infos);
1072
1073
1074
1075      this.mbeanConstructors = new JPanel JavaDoc(new GridBagLayout JavaDoc());
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 JavaDoc ctorInfo = (MBeanConstructorInfo JavaDoc) infos.get(i);
1084
1085         StringBuffer JavaDoc display = new StringBuffer JavaDoc();
1086
1087         display.append(ctorInfo.getName());
1088
1089         display.append("(");
1090
1091         MBeanParameterInfo JavaDoc[] 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 JavaDoc label = new JLabel JavaDoc(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   /**
1136
1137    * Description of the Method
1138
1139    *
1140
1141    * @param info Description of the Parameter
1142
1143    * @param object Description of the Parameter
1144
1145    */

1146
1147   protected void buildInfosPanel(MBeanInfo JavaDoc info, MBeanAccessor object)
1148
1149   {
1150
1151      JLabel JavaDoc label = null;
1152
1153      GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
1154
1155      gridbagconstraints.insets = new Insets JavaDoc(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 JavaDoc(new GridBagLayout JavaDoc());
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 JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc(info.getDescription(), SwingConstants.LEFT);
1218
1219      label.setForeground(Color.black);
1220
1221      this.mbeanInfo.add(label, gridbagconstraints);
1222
1223
1224
1225      JPanel JavaDoc buttonPanel = new JPanel JavaDoc(new GridLayout JavaDoc(1, 2, 5, 5));
1226
1227      JButton JavaDoc button1 = new JButton JavaDoc(resources.getString("customizer.button.unregister"));
1228
1229      button1.addActionListener(
1230
1231         new ActionListener JavaDoc()
1232
1233         {
1234
1235            public void actionPerformed(ActionEvent JavaDoc e)
1236
1237            {
1238
1239               try
1240
1241               {
1242
1243                  MBeanCustomizer.this.object.unregisterMBean();
1244
1245               }
1246
1247               catch (Exception JavaDoc 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   /**
1272
1273    * Description of the Method
1274
1275    *
1276
1277    * @param info Description of the Parameter
1278
1279    */

1280
1281   protected void buildNotificationsPanel(MBeanInfo JavaDoc info)
1282
1283   {
1284
1285      GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
1286
1287      gridbagconstraints.insets = new Insets JavaDoc(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 JavaDoc[] infosArray = info.getNotifications();
1300
1301      if (infosArray.length == 0)
1302
1303      {
1304
1305         return;
1306
1307      }
1308
1309      List JavaDoc infos = Arrays.asList(infosArray);
1310
1311      MBeanSorter.sortByName(infos);
1312
1313
1314
1315      this.mbeanNotifications = new JPanel JavaDoc(new GridBagLayout JavaDoc());
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 JavaDoc notificationInfo = (MBeanNotificationInfo JavaDoc) 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 JavaDoc label = new JLabel JavaDoc(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 JavaDoc(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 JavaDoc buttonPanel = new JPanel JavaDoc(new GridLayout JavaDoc(1, 2, 1, 1));
1370
1371      final JButton JavaDoc button1 = new JButton JavaDoc(resources.getString("customizer.button.listen"));
1372
1373      final JButton JavaDoc button2 = new JButton JavaDoc(resources.getString("customizer.button.unlisten"));
1374
1375
1376
1377      button1.addActionListener(
1378
1379         new ActionListener JavaDoc()
1380
1381         {
1382
1383            public void actionPerformed(ActionEvent JavaDoc 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 JavaDoc ue)
1406
1407               {
1408
1409               }
1410
1411            }
1412
1413         }
1414
1415         );
1416
1417
1418
1419      button2.addActionListener(
1420
1421         new ActionListener JavaDoc()
1422
1423         {
1424
1425            public void actionPerformed(ActionEvent JavaDoc 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 JavaDoc 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 JavaDoc 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   /**
1508
1509    * Description of the Method
1510
1511    *
1512
1513    * @param info Description of the Parameter
1514
1515    */

1516
1517   protected void buildOperationsPanel(MBeanInfo JavaDoc info)
1518
1519   {
1520
1521      GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
1522
1523      gridbagconstraints.insets = new Insets JavaDoc(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 JavaDoc[] infosArray = info.getOperations();
1538
1539      if (infosArray.length == 0)
1540
1541      {
1542
1543         return;
1544
1545      }
1546
1547      List JavaDoc infos = Arrays.asList(infosArray);
1548
1549      MBeanSorter.sortByName(infos);
1550
1551
1552
1553      this.mbeanOperations = new JPanel JavaDoc(new GridBagLayout JavaDoc());
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 JavaDoc operationInfo = (MBeanOperationInfo JavaDoc) infos.get(i);
1562
1563
1564
1565         gridbagconstraints.weightx = 0.0D;
1566
1567         gridbagconstraints.gridwidth = 1;
1568
1569         String JavaDoc returnType = ClassTools.classDisplay(operationInfo.getReturnType() + " ");
1570
1571         JLabel JavaDoc label = new JLabel JavaDoc(returnType, SwingConstants.RIGHT);
1572
1573         label.setForeground(AwtToolkit.DARK_BLUE);
1574
1575         this.mbeanOperations.add(label, gridbagconstraints);
1576
1577
1578
1579         StringBuffer JavaDoc display = new StringBuffer JavaDoc();
1580
1581         display.append(operationInfo.getName());
1582
1583         display.append("(");
1584
1585         MBeanParameterInfo JavaDoc[] 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 JavaDoc(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 JavaDoc button = new JButton JavaDoc(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 JavaDoc()
1640
1641            {
1642
1643               public void actionPerformed(ActionEvent JavaDoc 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   /**
1666
1667    * Returns the updaters.
1668
1669    *
1670
1671    * @return Vector
1672
1673    */

1674
1675   protected ArrayList JavaDoc getUpdaters()
1676
1677   {
1678
1679      if (this.updaters == null)
1680
1681      {
1682
1683         this.updaters = new ArrayList JavaDoc();
1684
1685      }
1686
1687      return this.updaters;
1688
1689   }
1690
1691
1692
1693
1694
1695   /**
1696
1697    * Description of the Method
1698
1699    *
1700
1701    * @param s Description of Parameter
1702
1703    * @param obj Description of Parameter
1704
1705    * @param obj1 Description of Parameter
1706
1707    */

1708
1709   protected void updated(String JavaDoc s, Object JavaDoc obj, Object JavaDoc obj1)
1710
1711   {
1712
1713      this.firePropertyChange(s, obj, obj1);
1714
1715   }
1716
1717
1718
1719
1720
1721   /**
1722
1723    * Description of the Class
1724
1725    *
1726
1727    * @author letiembl
1728
1729    * @version $Revision: 1.7 $
1730
1731    * @created 21 novembre 2002
1732
1733    */

1734
1735   protected class Updater
1736
1737   {
1738
1739      /** Description of the Field */
1740
1741      protected PropertyEditor JavaDoc editor;
1742
1743      /** Description of the Field */
1744
1745      protected MBeanAttributeInfo JavaDoc info;
1746
1747
1748
1749
1750
1751      /**
1752
1753       * Constructor for the EditorUpdater object
1754
1755       *
1756
1757       * @param editor Description of Parameter
1758
1759       * @param info Description of Parameter
1760
1761       */

1762
1763      public Updater(PropertyEditor JavaDoc editor, MBeanAttributeInfo JavaDoc info)
1764
1765      {
1766
1767         this.editor = editor;
1768
1769         this.info = info;
1770
1771      }
1772
1773
1774
1775
1776
1777      /** Description of the Method */
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 JavaDoc e)
1796
1797            {
1798
1799               e.printStackTrace();
1800
1801            }
1802
1803         }
1804
1805      }
1806
1807
1808
1809
1810
1811      /** Description of the Method */
1812
1813      public void updateFromEditor()
1814
1815      {
1816
1817         if (this.info.isWritable())
1818
1819         {
1820
1821            try
1822
1823            {
1824
1825               Object JavaDoc newValue = this.editor.getValue();
1826
1827               if (newValue != null)
1828
1829               {
1830
1831                  Attribute JavaDoc attr = new Attribute JavaDoc(this.info.getName(), newValue);
1832
1833                  if (this.info.isReadable())
1834
1835                  {
1836
1837                     Object JavaDoc 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 JavaDoc e)
1862
1863            {
1864
1865               e.printStackTrace();
1866
1867            }
1868
1869         }
1870
1871      }
1872
1873   }
1874
1875}
1876
1877
Popular Tags