I’m getting confused with the PropertyConverter<PC, FC> class in CustomField add-on. Shouldn’t the getType() return a Class instead of a Class since both getValue() and setValue() return and receive FC values?
What I’m attempting to do is an editor for joda.time.Partial where I store month/year values, here’s my code:
public class PartialEditor extends PopupDateField {
private static class DateFieldConverter extends PropertyConverter<Partial, Date> {
public DateFieldConverter(Property propertyDataSource) {
super(propertyDataSource);
}
@Override
public Partial parse(Date date) throws ConversionException {
if (date == null) {
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return new Partial().with(DateTimeFieldType.year(), cal.get(Calendar.YEAR)).with(DateTimeFieldType.monthOfYear(),
cal.get(Calendar.MONTH));
}
@Override
public Date format(Partial partial) {
return partial == null ? null : partial.toDateTime(new DateTime()).toDate();
}
}
public PartialEditor() {
setResolution(DateField.RESOLUTION_MONTH);
}
@Override
public void setPropertyDataSource(Property newDataSource) {
super.setPropertyDataSource(new DateFieldConverter(newDataSource));
}
}
This blows up in the PopupDateField that is expecting a property of Date.class and gets a Partial.class one.