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-25 20:17:02
|
Update of /cvsroot/ejtools/libraries/adwt/src/main/net/sourceforge/ejtools/awt In directory usw-pr-cvs1:/tmp/cvs-serv25491/adwt/src/main/net/sourceforge/ejtools/awt Modified Files: GenericMBeanCustomizer.java Log Message: Add test for null PropertyEditor on array value property Index: GenericMBeanCustomizer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/adwt/src/main/net/sourceforge/ejtools/awt/GenericMBeanCustomizer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenericMBeanCustomizer.java 18 Apr 2002 21:10:30 -0000 1.1 --- GenericMBeanCustomizer.java 25 Apr 2002 20:16:57 -0000 1.2 *************** *** 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; *************** *** 103,106 **** --- 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 *************** *** 329,338 **** } } ! ! public void addUnsupportedProperty(MBeanAttributeInfo attributeInfo) { System.out.println("In addUnsupportedProperty " + attributeInfo.getType()); ! GridBagConstraints gridbagconstraints = new GridBagConstraints(); gridbagconstraints.insets = new Insets(3, 3, 3, 3); --- 495,509 ---- } } ! ! ! /** ! * 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) { System.out.println("In addUnsupportedProperty " + attributeInfo.getType()); ! GridBagConstraints gridbagconstraints = new GridBagConstraints(); gridbagconstraints.insets = new Insets(3, 3, 3, 3); *************** *** 359,465 **** /** - * 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); - - 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(); - } - } - - - /** * Description of the Method * --- 530,533 ---- *************** *** 475,534 **** /** - * 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; - } - - - /** * Description of the Class * --- 543,546 ---- *************** *** 573,587 **** } /* ! * 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) --- 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) *************** *** 732,743 **** else { ! ! new GenericMBeanMethodDialog( ! object, ! object.getObjectName(), ! info, ! (Frame) frame ! ); ! } } --- 744,755 ---- else { ! ! new GenericMBeanMethodDialog( ! object, ! object.getObjectName(), ! info, ! (Frame) frame ! ); ! } } *************** *** 748,752 **** PropertyEditorManager.setEditorSearchPath(new String[]{"sun.beans.editors", "net.sourceforge.ejtools.awt.editors"}); } - } --- 760,763 ---- |