Thread: [Ejtools-cvs] CVS: libraries/adwt/src/main/net/sourceforge/ejtools/awt GenericMBeanCustomizer.java,1
Brought to you by:
letiemble
From: Laurent E. <let...@us...> - 2002-04-28 19:43:37
|
Update of /cvsroot/ejtools/libraries/adwt/src/main/net/sourceforge/ejtools/awt In directory usw-pr-cvs1:/tmp/cvs-serv17133/libraries/adwt/src/main/net/sourceforge/ejtools/awt Modified Files: GenericMBeanCustomizer.java Log Message: Add access to unregisterMBean method via Unregister button Index: GenericMBeanCustomizer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/adwt/src/main/net/sourceforge/ejtools/awt/GenericMBeanCustomizer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenericMBeanCustomizer.java 25 Apr 2002 20:16:57 -0000 1.2 --- GenericMBeanCustomizer.java 28 Apr 2002 10:18:54 -0000 1.3 *************** *** 1,7 **** /* ! * EJTools, the Enterprise Java Tools * ! * Distributable under LGPL license. ! * See terms of license at gnu.org. */ package net.sourceforge.ejtools.awt; --- 1,7 ---- /* ! * EJTools, the Enterprise Java Tools * ! * Distributable under LGPL license. ! * See terms of license at gnu.org. */ package net.sourceforge.ejtools.awt; *************** *** 21,24 **** --- 21,25 ---- import com.dreambean.awt.*; import net.sourceforge.ejtools.jmx.MBeanAccessor; + import net.sourceforge.ejtools.util.*; /** *************** *** 37,55 **** { /** Description of the Field */ ! private JPanel beanGui; ! /** Description of the Field */ ! private MBeanAttributeInfo mbai[]; /** Description of the Field */ ! private MBeanNotificationInfo mbni[]; /** Description of the Field */ ! private MBeanOperationInfo mboi[]; /** Description of the Field */ ! private MBeanAccessor object; /** Description of the Field */ ! private JPanel p; /** Description of the Field */ ! private JComponent previous; /** Description of the Field */ ! private boolean showMethods; --- 38,54 ---- { /** Description of the Field */ ! protected JPanel beanGui; /** Description of the Field */ ! protected MBeanAttributeInfo mbai[]; /** Description of the Field */ ! protected MBeanNotificationInfo mbni[]; /** Description of the Field */ ! protected MBeanOperationInfo mboi[]; /** Description of the Field */ ! protected MBeanAccessor object; /** Description of the Field */ ! protected JPanel p; /** Description of the Field */ ! protected JComponent previous; *************** *** 58,89 **** public GenericMBeanCustomizer() { - this(true); - } - - - /** - * Constructor for the GenericCustomizer object - * - * @param obj Description of Parameter - */ - public GenericMBeanCustomizer(Object obj) - { - this(); - setObject(obj); - } - - - /** - * Constructor for the GenericCustomizer object - * - * @param flag Description of Parameter - */ - public GenericMBeanCustomizer(boolean flag) - { super(new JPanel()); previous = null; p = (JPanel) getViewport().getView(); p.setLayout(new GridBagLayout()); - showMethods = flag; } --- 57,64 ---- *************** *** 92,101 **** * Constructor for the GenericCustomizer object * ! * @param flag Description of Parameter ! * @param obj Description of Parameter */ ! public GenericMBeanCustomizer(boolean flag, Object obj) { ! this(flag); setObject(obj); } --- 67,75 ---- * Constructor for the GenericCustomizer object * ! * @param obj Description of Parameter */ ! public GenericMBeanCustomizer(Object obj) { ! this(); setObject(obj); } *************** *** 103,272 **** /** - * Gets the class attribute of the GenericMBeanCustomizer class - * - * @param fullPathClassName Description of the Parameter - * @return The class value - */ - static Class getClass(String fullPathClassName) - { - if (fullPathClassName.equals("int")) - { - return Integer.TYPE; - } - if (fullPathClassName.equals("short")) - { - return Short.TYPE; - } - if (fullPathClassName.equals("long")) - { - return Long.TYPE; - } - if (fullPathClassName.equals("byte")) - { - return Byte.TYPE; - } - if (fullPathClassName.equals("char")) - { - return Character.TYPE; - } - if (fullPathClassName.equals("float")) - { - return Float.TYPE; - } - if (fullPathClassName.equals("double")) - { - return Double.TYPE; - } - if (fullPathClassName.equals("boolean")) - { - return Boolean.TYPE; - } - - Class c = null; - try - { - c = Class.forName(fullPathClassName); - } - catch (Throwable e) - { - } - - System.out.println("Class is " + c); - - return c; - } - - - /** - * Sets the Object attribute of the GenericCustomizer object - * - * @param obj The new Object value - */ - public void setObject(Object obj) - { - try - { - p.removeAll(); - - if (obj == null) - { - validate(); - repaint(); - return; - } - - object = (MBeanAccessor) obj; - MBeanInfo beaninfo = object.getMBeanInfo(); - - GridBagConstraints gridbagconstraints = new GridBagConstraints(); - gridbagconstraints.insets = new Insets(3, 3, 3, 3); - gridbagconstraints.anchor = GridBagConstraints.NORTH; - gridbagconstraints.weighty = 1.0D; - - beanGui = new JPanel(new GridBagLayout()); - beanGui.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), object.getCanonicalName())); - - mbai = beaninfo.getAttributes(); - if (mbai != null) - { - for (int i = 0; i < mbai.length; i++) - { - PropertyEditor propertyeditor = null; - Class c = getClass(mbai[i].getType()); - - if (c == null) - { - addUnsupportedProperty(mbai[i]); - } - else - { - - if (c.isArray()) - { - Class componentType = c.getComponentType(); - propertyeditor = PropertyEditorManager.findEditor(componentType); - - if (propertyeditor == null) - { - propertyeditor = PropertyEditorManager.findEditor(String.class); - } - addArrayProperty(propertyeditor, mbai[i]); - } - else - { - propertyeditor = PropertyEditorManager.findEditor(c); - - if (propertyeditor == null) - { - propertyeditor = PropertyEditorManager.findEditor(String.class); - } - addProperty(propertyeditor, mbai[i]); - } - gridbagconstraints.weighty = 1.0D; - } - } - } - - if (showMethods) - { - mboi = beaninfo.getOperations(); - gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; - gridbagconstraints.fill = GridBagConstraints.BOTH; - if (mboi != null) - { - for (int j = 0; j < mboi.length; j++) - { - if (!mboi[j].getName().startsWith("get") && !mboi[j].getName().startsWith("set") && !mboi[j].getName().startsWith("is")) - { - JButton jbutton = new JButton(mboi[j].getName()); - jbutton.setToolTipText(mboi[j].getDescription()); - beanGui.add(jbutton, gridbagconstraints); - jbutton.addActionListener(new MethodInvoker(mboi[j])); - } - } - } - } - - gridbagconstraints.weighty = 0.0D; - gridbagconstraints.weightx = 1.0D; - gridbagconstraints.fill = GridBagConstraints.BOTH; - p.add(beanGui, gridbagconstraints); - - // Add a spacer - gridbagconstraints.weighty = 1.0D; - p.add(new JLabel(" "), gridbagconstraints); - - validate(); - repaint(); - } - catch (Exception exception) - { - System.out.println("Exception occurred"); - exception.printStackTrace(); - } - } - - - /** * Adds a feature to the ArrayProperty attribute of the GenericCustomizer * object --- 77,80 ---- *************** *** 498,504 **** /** ! * Adds a feature to the UnsupportedProperty attribute of the GenericMBeanCustomizer object * ! * @param attributeInfo The feature to be added to the UnsupportedProperty attribute */ public void addUnsupportedProperty(MBeanAttributeInfo attributeInfo) --- 306,314 ---- /** ! * Adds a feature to the UnsupportedProperty attribute of the ! * GenericMBeanCustomizer object * ! * @param attributeInfo The feature to be added to the UnsupportedProperty ! * attribute */ public void addUnsupportedProperty(MBeanAttributeInfo attributeInfo) *************** *** 530,533 **** --- 340,508 ---- /** + * Gets the class attribute of the GenericMBeanCustomizer class + * + * @param obj The new object value + */ + /* + * static Class getClass(String fullPathClassName) + * { + * if (fullPathClassName.equals("int")) + * { + * return Integer.TYPE; + * } + * if (fullPathClassName.equals("short")) + * { + * return Short.TYPE; + * } + * if (fullPathClassName.equals("long")) + * { + * return Long.TYPE; + * } + * if (fullPathClassName.equals("byte")) + * { + * return Byte.TYPE; + * } + * if (fullPathClassName.equals("char")) + * { + * return Character.TYPE; + * } + * if (fullPathClassName.equals("float")) + * { + * return Float.TYPE; + * } + * if (fullPathClassName.equals("double")) + * { + * return Double.TYPE; + * } + * if (fullPathClassName.equals("boolean")) + * { + * return Boolean.TYPE; + * } + * Class c = null; + * try + * { + * c = Class.forName(fullPathClassName); + * } + * catch (Throwable e) + * { + * } + * System.out.println("Class is " + c); + * return c; + * } + */ + /** + * Sets the Object attribute of the GenericCustomizer object + * + * @param obj The new Object value + */ + public void setObject(Object obj) + { + try + { + p.removeAll(); + + if (obj == null) + { + validate(); + repaint(); + return; + } + + object = (MBeanAccessor) obj; + MBeanInfo beaninfo = object.getMBeanInfo(); + + GridBagConstraints gridbagconstraints = new GridBagConstraints(); + gridbagconstraints.insets = new Insets(3, 3, 3, 3); + gridbagconstraints.anchor = GridBagConstraints.NORTH; + gridbagconstraints.weighty = 1.0D; + + beanGui = new JPanel(new GridBagLayout()); + beanGui.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), object.getCanonicalName())); + + mbai = beaninfo.getAttributes(); + if (mbai != null) + { + for (int i = 0; i < mbai.length; i++) + { + PropertyEditor propertyeditor = null; + Class c = ClassTools.getClass(mbai[i].getType()); + + if (c == null) + { + addUnsupportedProperty(mbai[i]); + } + else + { + + if (c.isArray()) + { + Class componentType = c.getComponentType(); + propertyeditor = PropertyEditorManager.findEditor(componentType); + + if (propertyeditor == null) + { + propertyeditor = PropertyEditorManager.findEditor(String.class); + } + addArrayProperty(propertyeditor, mbai[i]); + } + else + { + propertyeditor = PropertyEditorManager.findEditor(c); + + if (propertyeditor == null) + { + propertyeditor = PropertyEditorManager.findEditor(String.class); + } + addProperty(propertyeditor, mbai[i]); + } + gridbagconstraints.weighty = 1.0D; + } + } + } + + gridbagconstraints.gridwidth = GridBagConstraints.REMAINDER; + gridbagconstraints.fill = GridBagConstraints.BOTH; + + //TODO : I18N + JButton ubutton = new JButton("Unregister"); + beanGui.add(ubutton, gridbagconstraints); + ubutton.addActionListener(new UnregisterInvoker()); + + mboi = beaninfo.getOperations(); + if (mboi != null) + { + for (int j = 0; j < mboi.length; j++) + { + if (!mboi[j].getName().startsWith("get") && !mboi[j].getName().startsWith("set") && !mboi[j].getName().startsWith("is")) + { + JButton jbutton = new JButton(mboi[j].getName()); + jbutton.setToolTipText(mboi[j].getDescription()); + beanGui.add(jbutton, gridbagconstraints); + jbutton.addActionListener(new MethodInvoker(mboi[j])); + } + } + } + + gridbagconstraints.weighty = 0.0D; + gridbagconstraints.weightx = 1.0D; + gridbagconstraints.fill = GridBagConstraints.BOTH; + p.add(beanGui, gridbagconstraints); + + // Add a spacer + gridbagconstraints.weighty = 1.0D; + p.add(new JLabel(" "), gridbagconstraints); + + validate(); + repaint(); + } + catch (Exception exception) + { + System.out.println("Exception occurred"); + exception.printStackTrace(); + } + } + + + /** * Description of the Method * *************** *** 585,599 **** } /* ! * AS Adapt to the JMXConnector exceptions ! * catch( InvocationTargetException e ) { ! * if( e.getTargetException() instanceof PropertyVetoException ) { ! * JOptionPane.showMessageDialog( ! * (Frame) SwingUtilities.windowForComponent( GenericMBeanCustomizer.this ), ! * "Could not change value:" + e.getTargetException().getMessage(), ! * "Error", ! * JOptionPane.ERROR_MESSAGE ! * ); ! * } ! * } */ catch (Exception e) --- 560,574 ---- } /* ! * AS Adapt to the JMXConnector exceptions ! * catch( InvocationTargetException e ) { ! * if( e.getTargetException() instanceof PropertyVetoException ) { ! * JOptionPane.showMessageDialog( ! * (Frame) SwingUtilities.windowForComponent( GenericMBeanCustomizer.this ), ! * "Could not change value:" + e.getTargetException().getMessage(), ! * "Error", ! * JOptionPane.ERROR_MESSAGE ! * ); ! * } ! * } */ catch (Exception e) *************** *** 752,755 **** --- 727,760 ---- ); + } + } + } + + + /** + * Description of the Class + * + * @author laurent + * @created 27 avril 2002 + */ + class UnregisterInvoker implements ActionListener + { + /** + * Description of the Method + * + * @param e Description of the Parameter + */ + public void actionPerformed(ActionEvent e) + { + Container frame = SwingUtilities.getAncestorOfClass(Frame.class, p); + + try + { + object.unregisterMBean(object.getObjectName()); + } + catch (Exception ex) + { + System.err.println(ex); + JOptionPane.showMessageDialog(frame, "An exception occured. Check log for details", "Error", JOptionPane.ERROR_MESSAGE); } } |