The nice part is that we already have a lot of predefined PropertyEditors for boolean/integer/string/font/color/date values.
But if one of the editors doesn't please us, just use Node.Property.getPropertyEditor() .
For example if we need a different date format, it would boil down to a new class:
class DatePropertyEditor extends PropertyEditorSupport{
private SimpleDateFormat sdf=new SimpleDateFormat("yyyy/mm/dd");
public String getAsText(){
if(getValue()==null){
return "";
}else{
return sdf.format((Date)getValue());
}
}
}
We just return a new instance of this class in getPropertyEditor() and that's it.
This gets a little more complicated if you actually need to edit the value as you have to provide a custom editor component but for simple read-only properties, this is all there is !
No comments:
Post a Comment