com.talk2object.plum.interaction.view.annotation.parameter.helper.DateParameterWrapper Maven / Gradle / Ivy
package com.talk2object.plum.interaction.view.annotation.parameter.helper;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.talk2object.plum.interaction.rich.field.DateField;
import com.talk2object.plum.interaction.rich.field.InteractiveField;
import com.talk2object.plum.interaction.view.annotation.parameter.DateParameter;
public class DateParameterWrapper extends AbstractParameterWrapper {
private DateParameter getDateParameter() {
return (DateParameter) parameter;
}
@Override
public Object getInitValue() {
return getDateParameter().initValue();
}
@Override
Object[] getOptionValues() {
return getDateParameter().options();
}
@Override
public Object value2Object(Object value) {
String strDate = (String) value;
if (strDate == null || strDate.trim().isEmpty())
return null;
SimpleDateFormat sdf = new SimpleDateFormat(getDateParameter().format());
try {
Date date = sdf.parse(strDate);
return date;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
@Override
public void enrich(InteractiveField input) {
super.enrich(input);
DateField dateInput = (DateField) input;
DateParameter dateParameter = getDateParameter();
dateInput.setFormat(dateParameter.format());
dateInput.setMode(dateParameter.mode());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy