KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > adwt > GenericMBeanCustomizer


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

7 package org.ejtools.adwt;
8
9 import java.awt.Component JavaDoc;
10 import java.awt.Container JavaDoc;
11 import java.awt.Frame JavaDoc;
12 import java.awt.GridBagConstraints JavaDoc;
13 import java.awt.GridBagLayout JavaDoc;
14 import java.awt.GridLayout JavaDoc;
15 import java.awt.Insets JavaDoc;
16 import java.awt.event.ActionEvent JavaDoc;
17 import java.awt.event.ActionListener JavaDoc;
18 import java.beans.Customizer JavaDoc;
19 import java.beans.PropertyChangeEvent JavaDoc;
20 import java.beans.PropertyChangeListener JavaDoc;
21 import java.beans.PropertyEditor JavaDoc;
22 import java.lang.reflect.Method JavaDoc;
23
24 import javax.management.Attribute JavaDoc;
25 import javax.management.MBeanAttributeInfo JavaDoc;
26 import javax.management.MBeanConstructorInfo JavaDoc;
27 import javax.management.MBeanInfo JavaDoc;
28 import javax.management.MBeanNotificationInfo JavaDoc;
29 import javax.management.MBeanOperationInfo JavaDoc;
30 import javax.management.MBeanParameterInfo JavaDoc;
31 import javax.swing.BorderFactory JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.JLabel JavaDoc;
35 import javax.swing.JOptionPane JavaDoc;
36 import javax.swing.JPanel JavaDoc;
37 import javax.swing.JScrollPane JavaDoc;
38 import javax.swing.SwingConstants JavaDoc;
39 import javax.swing.SwingUtilities JavaDoc;
40
41 import org.ejtools.jmx.MBeanAccessor;
42 import org.ejtools.util.ClassTools;
43
44 import com.dreambean.awt.GenericPropertyCustomizer;
45
46 /**
47  * Description of the Class
48  *
49  * @author Laurent Etiemble
50  * @version $Revision: 1.8 $
51  * @todo Protected method to choose PropertyEditor by Class and Name
52  * @todo Constructor Info
53  * @todo Notification Info
54  * @todo Layout for Contructor Attribute Operation and Notification
55  * @todo Non Supported classes displayed
56  * @todo Result of Command put into an Output List
57  */

58 public class GenericMBeanCustomizer extends JScrollPane JavaDoc implements Customizer JavaDoc
59 {
60    /** Description of the Field */
61    private JPanel JavaDoc mbeanConstructors = null;
62    /** Description of the Field */
63    private JPanel JavaDoc mbeanInfo = null;
64    /** Description of the Field */
65    private JPanel JavaDoc mbeanNotifications = null;
66    /** Description of the Field */
67    private JPanel JavaDoc mbeanOperations = null;
68    /** Description of the Field */
69    private MBeanAccessor object;
70    /** Description of the Field */
71    private JPanel JavaDoc p;
72    /** Description of the Field */
73    private JComponent JavaDoc previous;
74
75
76
77    /** Constructor for the GenericCustomizer object */
78    public GenericMBeanCustomizer()
79    {
80       super(new JPanel JavaDoc());
81       previous = null;
82       this.p = (JPanel JavaDoc) getViewport().getView();
83       this.p.setLayout(new GridBagLayout JavaDoc());
84    }
85
86
87    /**
88     * Constructor for the GenericCustomizer object
89     *
90     * @param obj Description of Parameter
91     */

92    public GenericMBeanCustomizer(Object JavaDoc obj)
93    {
94       this();
95       this.setObject(obj);
96    }
97
98
99    /**
100     * Adds a feature to the ArrayProperty attribute of the GenericCustomizer object
101     *
102     * @param propertyeditor The feature to be added to the ArrayProperty attribute
103     * @param attributeInfo The feature to be added to the ArrayProperty attribute
104     */

105    public void addArrayProperty(PropertyEditor JavaDoc propertyeditor, MBeanAttributeInfo JavaDoc attributeInfo)
106    {
107       Object JavaDoc obj = null;
108       Object JavaDoc[] array = null;
109       JPanel JavaDoc jpanel = null;
110
111       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
112       gridbagconstraints.insets = new Insets JavaDoc(3, 3, 3, 3);
113
114       try
115       {
116          if (attributeInfo.isReadable())
117          {
118             obj = object.getAttribute(attributeInfo.getName());
119          }
120          if (obj != null)
121          {
122             array = (Object JavaDoc[]) obj;
123          }
124       }
125       catch (Throwable JavaDoc _ex)
126       {
127       }
128
129       JLabel JavaDoc jlabel = new JLabel JavaDoc(attributeInfo.getName() + " :", SwingConstants.RIGHT);
130       jlabel.setToolTipText(attributeInfo.getDescription());
131
132       gridbagconstraints.anchor = GridBagConstraints.NORTH;
133       gridbagconstraints.weightx = 0.0D;
134       gridbagconstraints.weighty = 1.0D;
135       gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE;
136       gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
137
138 // beanGui.add(jlabel, gridbagconstraints);
139

140       if (array == null)
141       {
142          jpanel = new JPanel JavaDoc();
143       }
144       else
145       {
146          jpanel = new JPanel JavaDoc(new GridLayout JavaDoc(array.length, 1));
147          for (int i = 0; i < array.length; i++)
148          {
149             try
150             {
151                PropertyEditor JavaDoc propertyeditor1 = (PropertyEditor JavaDoc) propertyeditor.getClass().newInstance();
152                propertyeditor1.setValue(array[i]);
153
154                Object JavaDoc obj1;
155
156                if (propertyeditor1.supportsCustomEditor())
157                {
158                   obj1 = propertyeditor1.getCustomEditor();
159                   if (obj1 instanceof JComponent JavaDoc)
160                   {
161                      if (previous != null)
162                      {
163                         previous.setNextFocusableComponent(((Component JavaDoc) (obj1)));
164                      }
165                      previous = (JComponent JavaDoc) obj1;
166                   }
167                }
168                else
169                {
170                   String JavaDoc as[] = propertyeditor1.getTags();
171                   if (as != null)
172                   {
173                      obj1 = new GenericPropertyCustomizer(propertyeditor1, as);
174                      if (previous != null)
175                      {
176                         previous.setNextFocusableComponent(((Component JavaDoc) (obj1)));
177                      }
178                      previous = (JComponent JavaDoc) obj1;
179                   }
180                   else
181                   {
182                      final JLabel JavaDoc lbl = new JLabel JavaDoc(propertyeditor1.getAsText());
183                      final PropertyEditor JavaDoc pcEditor = propertyeditor1;
184                      obj1 = lbl;
185                      pcEditor.addPropertyChangeListener(
186                         new PropertyChangeListener JavaDoc()
187                         {
188                            public void propertyChange(PropertyChangeEvent JavaDoc evt)
189                            {
190                               lbl.setText(pcEditor.getAsText());
191                            }
192                         });
193                   }
194                }
195                jpanel.add((Component JavaDoc) obj1);
196             }
197             catch (Exception JavaDoc _ex)
198             {
199             }
200          }
201       }
202
203       gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
204       gridbagconstraints.weightx = 1.0D;
205 // beanGui.add(jpanel, gridbagconstraints);
206
}
207
208
209    /**
210     * Adds a feature to the Property attribute of the GenericCustomizer object
211     *
212     * @param propertyeditor The feature to be added to the Property attribute
213     * @param attributeInfo The feature to be added to the Property attribute
214     */

215    public void addProperty(PropertyEditor JavaDoc propertyeditor, MBeanAttributeInfo JavaDoc attributeInfo)
216    {
217       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
218       gridbagconstraints.insets = new Insets JavaDoc(3, 3, 3, 3);
219
220       try
221       {
222          if (attributeInfo.isReadable())
223          {
224             propertyeditor.setValue(object.getAttribute(attributeInfo.getName()));
225          }
226       }
227       catch (Throwable JavaDoc _ex)
228       {
229       }
230
231       JLabel JavaDoc jlabel = new JLabel JavaDoc(attributeInfo.getName() + " :", SwingConstants.RIGHT);
232       jlabel.setToolTipText(attributeInfo.getDescription());
233
234       gridbagconstraints.anchor = GridBagConstraints.NORTH;
235       gridbagconstraints.weightx = 0.0D;
236       gridbagconstraints.weighty = 1.0D;
237       gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE;
238       gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
239
240 // beanGui.add(jlabel, gridbagconstraints);
241

242       Object JavaDoc obj1;
243       if (propertyeditor.supportsCustomEditor())
244       {
245          obj1 = propertyeditor.getCustomEditor();
246          if (obj1 instanceof JComponent JavaDoc)
247          {
248             if (previous != null)
249             {
250                previous.setNextFocusableComponent(((Component JavaDoc) (obj1)));
251             }
252             previous = (JComponent JavaDoc) obj1;
253          }
254       }
255       else
256       {
257          String JavaDoc[] tags = propertyeditor.getTags();
258          if (tags != null)
259          {
260             obj1 = new GenericPropertyCustomizer(propertyeditor, tags);
261             if (previous != null)
262             {
263                previous.setNextFocusableComponent((Component JavaDoc) (obj1));
264             }
265             previous = (JComponent JavaDoc) obj1;
266          }
267          else
268          {
269             if (attributeInfo.isWritable())
270             {
271                obj1 = new GenericPropertyCustomizer(propertyeditor);
272                if (previous != null)
273                {
274                   previous.setNextFocusableComponent((Component JavaDoc) (obj1));
275                }
276                previous = (JComponent JavaDoc) obj1;
277             }
278             else
279             {
280                final JLabel JavaDoc lbl = new JLabel JavaDoc(propertyeditor.getAsText());
281                final PropertyEditor JavaDoc pcEditor = propertyeditor;
282                obj1 = lbl;
283                pcEditor.addPropertyChangeListener(
284                   new PropertyChangeListener JavaDoc()
285                   {
286                      public void propertyChange(PropertyChangeEvent JavaDoc evt)
287                      {
288                         lbl.setText(pcEditor.getAsText());
289                      }
290                   });
291             }
292          }
293       }
294
295       gridbagconstraints.weightx = 1.0D;
296       gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
297       gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
298
299 // beanGui.add(((Component) (obj1)), gridbagconstraints);
300

301       if (attributeInfo.isWritable())
302       {
303          propertyeditor.addPropertyChangeListener(new BeanUpdater(attributeInfo));
304       }
305
306       try
307       {
308          Method JavaDoc method = object.getClass().getMethod("addPropertyChangeListener", new Class JavaDoc[]{java.lang.String JavaDoc.class, java.beans.PropertyChangeListener JavaDoc.class});
309          method.invoke(object, new Object JavaDoc[]{attributeInfo.getName(), new EditorUpdater(propertyeditor, attributeInfo.getName())});
310       }
311       catch (Exception JavaDoc _ex)
312       {
313          try
314          {
315             Method JavaDoc method1 = object.getClass().getMethod("addPropertyChangeListener", new Class JavaDoc[]{java.beans.PropertyChangeListener JavaDoc.class});
316             method1.invoke(object, new Object JavaDoc[]{new EditorUpdater(propertyeditor, attributeInfo)});
317          }
318          catch (Exception JavaDoc _ex2)
319          {
320          }
321       }
322    }
323
324
325    /**
326     * Adds a feature to the UnsupportedProperty attribute of the GenericMBeanCustomizer object
327     *
328     * @param attributeInfo The feature to be added to the UnsupportedProperty attribute
329     */

330    public void addUnsupportedProperty(MBeanAttributeInfo JavaDoc attributeInfo)
331    {
332       System.out.println("In addUnsupportedProperty " + attributeInfo.getType());
333
334       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
335       gridbagconstraints.insets = new Insets JavaDoc(3, 3, 3, 3);
336
337       JLabel JavaDoc jlabel = new JLabel JavaDoc(attributeInfo.getName() + " :", SwingConstants.RIGHT);
338       jlabel.setToolTipText(attributeInfo.getDescription());
339
340       gridbagconstraints.anchor = GridBagConstraints.NORTH;
341       gridbagconstraints.weightx = 0.0D;
342       gridbagconstraints.weighty = 1.0D;
343       gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE;
344       gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
345
346 // beanGui.add(jlabel, gridbagconstraints);
347

348       JLabel JavaDoc lbl = new JLabel JavaDoc("Unloadabled class " + attributeInfo.getType());
349
350       gridbagconstraints.weightx = 1.0D;
351       gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
352
353 // beanGui.add(lbl, gridbagconstraints);
354
}
355
356
357    /**
358     * Sets the Object attribute of the GenericCustomizer object
359     *
360     * @param obj The new Object value
361     */

362    public void setObject(Object JavaDoc obj)
363    {
364       try
365       {
366          this.p.removeAll();
367
368          if (obj == null)
369          {
370             this.validate();
371             this.repaint();
372             return;
373          }
374
375          this.object = (MBeanAccessor) obj;
376          MBeanInfo JavaDoc beaninfo = object.getMBeanInfo();
377
378          GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
379          gridbagconstraints.insets = new Insets JavaDoc(3, 3, 3, 3);
380          gridbagconstraints.anchor = GridBagConstraints.NORTH;
381          gridbagconstraints.weightx = 1.0D;
382          gridbagconstraints.weighty = 0.0D;
383          gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
384          gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
385
386          this.buildInfosPanel(beaninfo, object);
387          this.buildConstructorsPanel(beaninfo);
388          this.buildNotificationsPanel(beaninfo);
389          this.buildOperationsPanel(beaninfo);
390
391          this.p.add(mbeanInfo, gridbagconstraints);
392          if (mbeanConstructors != null)
393          {
394             this.p.add(mbeanConstructors, gridbagconstraints);
395          }
396          if (mbeanNotifications != null)
397          {
398             this.p.add(mbeanNotifications, gridbagconstraints);
399          }
400          if (mbeanOperations != null)
401          {
402             this.p.add(mbeanOperations, gridbagconstraints);
403          }
404
405          // Add a spacer
406
gridbagconstraints.weighty = 1.0D;
407          gridbagconstraints.fill = GridBagConstraints.BOTH;
408          this.p.add(new JLabel JavaDoc(" "), gridbagconstraints);
409
410          validate();
411          repaint();
412       }
413       catch (Exception JavaDoc exception)
414       {
415          System.out.println("Exception occurred");
416          exception.printStackTrace();
417       }
418    }
419
420
421    /**
422     * Description of the Method
423     *
424     * @param s Description of Parameter
425     * @param obj Description of Parameter
426     * @param obj1 Description of Parameter
427     */

428    protected void updated(String JavaDoc s, Object JavaDoc obj, Object JavaDoc obj1)
429    {
430       firePropertyChange(s, obj, obj1);
431    }
432
433
434    /**
435     * Description of the Method
436     *
437     * @param info Description of the Parameter
438     */

439    private void buildConstructorsPanel(MBeanInfo JavaDoc info)
440    {
441       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
442       gridbagconstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
443       gridbagconstraints.anchor = GridBagConstraints.NORTH;
444       gridbagconstraints.weightx = 1.0D;
445       gridbagconstraints.weighty = 1.0D;
446       gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
447       gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
448
449       MBeanConstructorInfo JavaDoc[] infos = info.getConstructors();
450       if (infos.length == 0)
451       {
452          return;
453       }
454       this.mbeanConstructors = new JPanel JavaDoc(new GridBagLayout JavaDoc());
455       this.mbeanConstructors.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Constructors"));
456       for (int i = 0; i < infos.length; i++)
457       {
458          StringBuffer JavaDoc display = new StringBuffer JavaDoc();
459          display.append(infos[i].getName());
460          display.append("(");
461          MBeanParameterInfo JavaDoc[] parameters = infos[i].getSignature();
462          if (parameters.length > 0)
463          {
464             for (int j = 0; j < parameters.length; j++)
465             {
466                if (j > 0)
467                {
468                   display.append(", ");
469                }
470                display.append(ClassTools.classDisplay(parameters[j].getType()));
471             }
472          }
473          display.append(")");
474
475          JLabel JavaDoc label = new JLabel JavaDoc(display.toString(), SwingConstants.LEFT);
476          label.setToolTipText(infos[i].getDescription());
477          this.mbeanConstructors.add(label, gridbagconstraints);
478       }
479    }
480
481
482    /**
483     * Description of the Method
484     *
485     * @param info Description of the Parameter
486     * @param object Description of the Parameter
487     */

488    private void buildInfosPanel(MBeanInfo JavaDoc info, MBeanAccessor object)
489    {
490       JLabel JavaDoc label = null;
491       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
492       gridbagconstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
493       gridbagconstraints.anchor = GridBagConstraints.NORTH;
494       gridbagconstraints.weightx = 0.0D;
495       gridbagconstraints.weighty = 1.0D;
496       gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
497
498       this.mbeanInfo = new JPanel JavaDoc(new GridBagLayout JavaDoc());
499       this.mbeanInfo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), object.getCanonicalName()));
500
501       gridbagconstraints.weightx = 0.0D;
502       gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE;
503       label = new JLabel JavaDoc("ClassName : ", SwingConstants.RIGHT);
504       label.setToolTipText("Class Name of the MBean");
505       label.setForeground(AwtToolkit.DARK_BLUE);
506       this.mbeanInfo.add(label, gridbagconstraints);
507
508       gridbagconstraints.weightx = 1.0D;
509       gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
510       label = new JLabel JavaDoc(info.getClassName(), SwingConstants.LEFT);
511       this.mbeanInfo.add(label, gridbagconstraints);
512
513       gridbagconstraints.weightx = 0.0D;
514       gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE;
515       label = new JLabel JavaDoc("Description : ", SwingConstants.RIGHT);
516       label.setToolTipText("Description of the MBean");
517       label.setForeground(AwtToolkit.DARK_BLUE);
518       this.mbeanInfo.add(label, gridbagconstraints);
519
520       gridbagconstraints.weightx = 1.0D;
521       gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
522       label = new JLabel JavaDoc(info.getDescription(), SwingConstants.LEFT);
523       this.mbeanInfo.add(label, gridbagconstraints);
524    }
525
526
527    /**
528     * Description of the Method
529     *
530     * @param info Description of the Parameter
531     */

532    private void buildNotificationsPanel(MBeanInfo JavaDoc info)
533    {
534       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
535       gridbagconstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
536       gridbagconstraints.anchor = GridBagConstraints.NORTH;
537       gridbagconstraints.weightx = 0.0D;
538       gridbagconstraints.weighty = 1.0D;
539       gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
540
541       MBeanNotificationInfo JavaDoc[] infos = info.getNotifications();
542       if (infos.length == 0)
543       {
544          return;
545       }
546       this.mbeanNotifications = new JPanel JavaDoc(new GridBagLayout JavaDoc());
547       this.mbeanNotifications.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Notifications"));
548       for (int i = 0; i < infos.length; i++)
549       {
550          gridbagconstraints.weightx = 0.0D;
551          gridbagconstraints.gridheight = infos[i].getNotifTypes().length;
552          gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE;
553          JLabel JavaDoc label = new JLabel JavaDoc(infos[i].getName(), SwingConstants.RIGHT);
554          label.setToolTipText(infos[i].getDescription());
555          label.setForeground(AwtToolkit.DARK_BLUE);
556          this.mbeanNotifications.add(label, gridbagconstraints);
557
558          gridbagconstraints.weightx = 1.0D;
559          gridbagconstraints.gridheight = 1;
560          gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
561          for (int j = 0; j < infos[i].getNotifTypes().length; j++)
562          {
563             label = new JLabel JavaDoc(infos[i].getNotifTypes()[j], SwingConstants.LEFT);
564             this.mbeanNotifications.add(label, gridbagconstraints);
565          }
566       }
567       if (infos.length > 0)
568       {
569          JPanel JavaDoc buttonPanel = new JPanel JavaDoc(new GridLayout JavaDoc(1, 2, 5, 5));
570          JButton JavaDoc button1 = new JButton JavaDoc("Register");
571          JButton JavaDoc button2 = new JButton JavaDoc("Unregister");
572          buttonPanel.add(button1);
573          buttonPanel.add(button2);
574          this.mbeanNotifications.add(buttonPanel, gridbagconstraints);
575       }
576    }
577
578
579    /**
580     * Description of the Method
581     *
582     * @param info Description of the Parameter
583     */

584    private void buildOperationsPanel(MBeanInfo JavaDoc info)
585    {
586       GridBagConstraints JavaDoc gridbagconstraints = new GridBagConstraints JavaDoc();
587       gridbagconstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
588       gridbagconstraints.anchor = GridBagConstraints.NORTH;
589       gridbagconstraints.weightx = 1.0D;
590       gridbagconstraints.weighty = 1.0D;
591       gridbagconstraints.fill = GridBagConstraints.HORIZONTAL;
592       gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
593
594       MBeanOperationInfo JavaDoc[] infos = info.getOperations();
595       if (infos.length == 0)
596       {
597          return;
598       }
599       this.mbeanOperations = new JPanel JavaDoc(new GridBagLayout JavaDoc());
600       this.mbeanOperations.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Operations"));
601       for (int i = 0; i < infos.length; i++)
602       {
603          gridbagconstraints.weightx = 0.0D;
604          gridbagconstraints.gridwidth = 1;
605          String JavaDoc returnType = ClassTools.classDisplay(infos[i].getReturnType());
606          JLabel JavaDoc label = new JLabel JavaDoc(returnType, SwingConstants.RIGHT);
607          label.setForeground(AwtToolkit.DARK_BLUE);
608          this.mbeanOperations.add(label, gridbagconstraints);
609
610          StringBuffer JavaDoc display = new StringBuffer JavaDoc();
611          display.append(infos[i].getName());
612          display.append("(");
613          MBeanParameterInfo JavaDoc[] parameters = infos[i].getSignature();
614          if (parameters.length > 0)
615          {
616             for (int j = 0; j < parameters.length; j++)
617             {
618                if (j > 0)
619                {
620                   display.append(", ");
621                }
622                display.append(ClassTools.classDisplay(parameters[j].getType()));
623             }
624          }
625          display.append(")");
626
627          gridbagconstraints.weightx = 1.0D;
628          gridbagconstraints.gridwidth = GridBagConstraints.RELATIVE;
629          label = new JLabel JavaDoc(display.toString(), SwingConstants.LEFT);
630          label.setToolTipText(infos[i].getDescription());
631          this.mbeanOperations.add(label, gridbagconstraints);
632
633          gridbagconstraints.weightx = 0.0D;
634          gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER;
635          JButton JavaDoc button = new JButton JavaDoc("Execute");
636          this.mbeanOperations.add(button, gridbagconstraints);
637       }
638    }
639
640
641    /**
642     * Description of the Class
643     *
644     * @author laurent
645     * @version $Revision: 1.8 $
646     */

647    class BeanUpdater implements PropertyChangeListener JavaDoc
648    {
649       /** Description of the Field */
650       MBeanAttributeInfo JavaDoc info;
651
652
653       /**
654        * Constructor for the BeanUpdater object
655        *
656        * @param info Description of Parameter
657        */

658       public BeanUpdater(MBeanAttributeInfo JavaDoc info)
659       {
660          this.info = info;
661       }
662
663
664       /**
665        * Description of the Method
666        *
667        * @param event Description of Parameter
668        */

669       public void propertyChange(PropertyChangeEvent JavaDoc event)
670       {
671          Object JavaDoc old = null;
672          try
673          {
674             if (info.isReadable())
675             {
676                old = object.getAttribute(info.getName());
677             }
678             Object JavaDoc obj = ((PropertyEditor JavaDoc) event.getSource()).getValue();
679
680             object.setAttribute(new Attribute JavaDoc(info.getName(), obj));
681             updated(info.getName(), old, obj);
682          }
683          /*
684           * AS Adapt to the JMXConnector exceptions
685           * catch( InvocationTargetException e ) {
686           * if( e.getTargetException() instanceof PropertyVetoException ) {
687           * JOptionPane.showMessageDialog(
688           * (Frame) SwingUtilities.windowForComponent( GenericMBeanCustomizer.this ),
689           * "Could not change value:" + e.getTargetException().getMessage(),
690           * "Error",
691           * JOptionPane.ERROR_MESSAGE
692           * );
693           * }
694           * }
695           */

696          catch (Exception JavaDoc e)
697          {
698             System.err.println(e);
699          }
700       }
701    }
702
703
704    /**
705     * This class makes sure that the customizer is updated with the object changes
706     *
707     * @author andreass
708     * @version $Revision: 1.8 $
709     */

710    class EditorUpdater implements PropertyChangeListener JavaDoc
711    {
712       /** Description of the Field */
713       PropertyEditor JavaDoc editor;
714       /** Description of the Field */
715       MBeanAttributeInfo JavaDoc info;
716       /** Description of the Field */
717       String JavaDoc name;
718
719
720       /**
721        * Constructor for the EditorUpdater object
722        *
723        * @param editor Description of Parameter
724        * @param info Description of Parameter
725        */

726       public EditorUpdater(PropertyEditor JavaDoc editor, MBeanAttributeInfo JavaDoc info)
727       {
728          this.editor = editor;
729          this.info = info;
730          this.name = info.getName();
731       }
732
733
734       /**
735        * Constructor for the EditorUpdater object
736        *
737        * @param editor Description of Parameter
738        * @param name Description of Parameter
739        */

740       public EditorUpdater(PropertyEditor JavaDoc editor, String JavaDoc name)
741       {
742          this.editor = editor;
743          this.name = name;
744       }
745
746
747       /**
748        * Description of the Method
749        *
750        * @param event Description of Parameter
751        */

752       public void propertyChange(PropertyChangeEvent JavaDoc event)
753       {
754          System.out.println("$$$ Attribute has been changed " + event);
755          System.out.println("$$$ Attribute has been changed " + name + "/" + event.getPropertyName());
756
757          if (name != null && event.getPropertyName() != null)
758          {
759             if (!event.getPropertyName().equals(name))
760             {
761                return;
762             }
763          }
764          if (event.getPropertyName() != null)
765          {
766             if (!editor.getValue().equals(event.getNewValue()))
767             {
768                editor.setValue(event.getNewValue());
769             }
770          }
771          else
772          {
773             try
774             {
775                Object JavaDoc value = object.getAttribute(event.getSource() + "");
776                if (editor != null && !editor.equals(editor.getValue()))
777                {
778                   editor.setValue(value);
779                }
780             }
781             catch (Exception JavaDoc e)
782             {
783             }
784          }
785       }
786    }
787
788
789    /**
790     * Description of the Class
791     *
792     * @author letiembl
793     * @version $Revision: 1.8 $
794     */

795    class MethodInvoker implements ActionListener JavaDoc
796    {
797       /** Description of the Field */
798       MBeanOperationInfo JavaDoc info;
799
800
801       /**
802        * Constructor for the MethodInvoker object
803        *
804        * @param info Description of Parameter
805        */

806       MethodInvoker(MBeanOperationInfo JavaDoc info)
807       {
808          this.info = info;
809       }
810
811
812       /**
813        * Description of the Method
814        *
815        * @param e Description of Parameter
816        */

817       public void actionPerformed(ActionEvent JavaDoc e)
818       {
819          Container JavaDoc frame = SwingUtilities.getAncestorOfClass(Frame JavaDoc.class, p);
820
821          // No parameters->invoke right away
822
MBeanParameterInfo JavaDoc[] parameters = info.getSignature();
823          if (parameters.length == 0)
824          {
825             try
826             {
827                Object JavaDoc obj1 = object.invoke(info.getName(), new Object JavaDoc[]{}, new String JavaDoc[]{});
828
829                if (obj1 != null)
830                {
831                   JOptionPane.showMessageDialog(frame, obj1.toString(), "Result", 1);
832                }
833             }
834             catch (Exception JavaDoc ex)
835             {
836                System.err.println(ex);
837                JOptionPane.showMessageDialog(frame, "An exception occured. Check log for details", "Error", JOptionPane.ERROR_MESSAGE);
838             }
839          }
840          else
841          {
842
843             new GenericMBeanMethodDialog(
844                object,
845                object.getObjectName(),
846                info,
847                (Frame JavaDoc) frame
848                );
849
850          }
851       }
852    }
853
854
855    /**
856     * Description of the Class
857     *
858     * @author laurent
859     * @version $Revision: 1.8 $
860     */

861    class UnregisterInvoker implements ActionListener JavaDoc
862    {
863       /**
864        * Description of the Method
865        *
866        * @param e Description of the Parameter
867        */

868       public void actionPerformed(ActionEvent JavaDoc e)
869       {
870          Container JavaDoc frame = SwingUtilities.getAncestorOfClass(Frame JavaDoc.class, p);
871
872          try
873          {
874             object.unregisterMBean();
875          }
876          catch (Exception JavaDoc ex)
877          {
878             System.err.println(ex);
879             JOptionPane.showMessageDialog(frame, "An exception occured. Check log for details", "Error", JOptionPane.ERROR_MESSAGE);
880          }
881       }
882    }
883 }
884
885
Popular Tags