Example #1
0
 private void refresh() {
   if (this.value == null) {
     this.setEnabled(false);
     return;
   }
   this.setEnabled(true);
   for (final PropertyDescriptor pd : this.beanInfo.getPropertyDescriptors()) {
     final JTextField field = this.fieldMap.get(pd.getName());
     PropertyEditor editor = pd.createPropertyEditor(this.getValue());
     if (editor == null) {
       editor = PropertyEditorManager.findEditor(pd.getPropertyType());
     }
     if (editor == null) {
       continue;
     }
     Object propertyValue = null;
     try {
       propertyValue = pd.getReadMethod().invoke(this.getValue());
     } catch (final Exception e) {
       // Just continue
       continue;
     }
     field.setText(propertyValue != null ? propertyValue.toString() : "null");
   }
 }
 /**
  * Find a default editor for the given type.
  *
  * @param requiredType the type to find an editor for
  * @param descriptor the JavaBeans descriptor for the property
  * @return the corresponding editor, or <code>null</code> if none
  */
 protected PropertyEditor findDefaultEditor(Class requiredType, TypeDescriptor typeDescriptor) {
   PropertyEditor editor = null;
   if (typeDescriptor instanceof PropertyTypeDescriptor) {
     PropertyDescriptor pd = ((PropertyTypeDescriptor) typeDescriptor).getPropertyDescriptor();
     editor = pd.createPropertyEditor(this.targetObject);
   }
   if (editor == null && requiredType != null) {
     // No custom editor -> check BeanWrapperImpl's default editors.
     editor = this.propertyEditorRegistry.getDefaultEditor(requiredType);
     if (editor == null && !String.class.equals(requiredType)) {
       // No BeanWrapper default editor -> check standard JavaBean editor.
       editor = BeanUtils.findEditorByConvention(requiredType);
     }
   }
   return editor;
 }