예제 #1
0
  /**
   * Get the appropriate editor for the given property.
   *
   * @param prop Property to get editor for.
   * @return Editor to use, or null if none found.
   */
  private PropertyEditor getEditorForProperty(PropertyDescriptor prop) {
    PropertyEditor retval = null;
    Class type = prop.getPropertyEditorClass();
    if (type != null) {
      try {
        retval = (PropertyEditor) type.newInstance();
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
    // Handle case where there is no special editor
    // associated with the property. In that case we ask the
    // PropertyEditor manager for the editor registered for the
    // given property type.
    if (retval == null) {
      Class t = prop.getPropertyType();
      if (t != null) {
        retval = PropertyEditorManager.findEditor(t);
      }
    }

    // In the worse case we resort to the generic editor for Object types.
    if (retval == null) {
      retval = PropertyEditorManager.findEditor(Object.class);
    }

    return retval;
  }
예제 #2
0
 static {
   PropertyEditorManager.registerEditor(String.class, StringPropertyEditor.class);
   PropertyEditorManager.registerEditor(String[].class, StringArrayPropertyEditor.class);
   PropertyEditorManager.registerEditor(int.class, IntegerPropertyEditor.class);
   PropertyEditorManager.registerEditor(Integer.class, IntegerPropertyEditor.class);
   PropertyEditorManager.registerEditor(double.class, DoublePropertyEditor.class);
   PropertyEditorManager.registerEditor(Double.class, DoublePropertyEditor.class);
   PropertyEditorManager.registerEditor(Properties.class, PropertiesPropertyEditor.class);
   PropertyEditorManager.registerEditor(File.class, FilePropertyEditor.class);
   PropertyEditorManager.registerEditor(Object.class, ObjectPropertyEditor.class);
 }