05-20-2015 07:09 AM
public class ProdottoFinitoFormType extends AbstractFormType {
private static final long serialVersionUID = 1L;
RecuperoPF pf = new RecuperoPF();
protected Map <String,String> values = pf.RecuperoDati();
public ProdottoFinitoFormType(Map <String,String> values){
this.values = values;
}
public String getName(){
return "prodotto_finito";
}
@Override
public Object getInformation(String key) {
if (key.equals("values")) {
return values;
}
return null;
}
@Override
public Object convertFormValueToModelValue(String propertyValue) {
validateValue(propertyValue);
return propertyValue;
}
@Override
public String convertModelValueToFormValue(Object modelValue) {
if(modelValue != null) {
if(!(modelValue instanceof String)) {
throw new ActivitiIllegalArgumentException("Model value should be a String");
}
validateValue((String) modelValue);
}
return (String) modelValue;
}
protected void validateValue(String value) {
if(value != null) {
if(values != null && !values.containsKey(value)) {
throw new ActivitiIllegalArgumentException("Invalid value for the form property: " + value);
}
}
}
}
public class ProdottoFinitoFormPropertyRenderer extends AbstractFormPropertyRenderer {
public ProdottoFinitoFormPropertyRenderer() {
super(ProdottoFinitoFormType.class);
}
@SuppressWarnings("unchecked")
@Override
public Field getPropertyField(FormProperty formProperty) {
ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty));
comboBox.setRequired(formProperty.isRequired());
comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
comboBox.setEnabled(formProperty.isWritable());
comboBox.setNullSelectionAllowed(false);
Object firstItemId = null;
Object itemToSelect = null;
Map<String, String> values = (Map<String, String>) formProperty.getType().getInformation("values");
if (values != null) {
for (Entry<String, String> prodfinEntry : values.entrySet()) {
// Add value and label (if any)
comboBox.addItem(prodfinEntry.getKey());
if (firstItemId == null) {
firstItemId = prodfinEntry.getKey(); // select first element
}
String selectedValue = formProperty.getValue();
if (selectedValue != null && selectedValue.equals(prodfinEntry.getKey())) {
itemToSelect = prodfinEntry.getKey(); // select first element
}
if (prodfinEntry.getValue() != null) {
comboBox.setItemCaption(prodfinEntry.getKey(), prodfinEntry.getValue());
}
}
}
// Select value or first element
if (itemToSelect != null) {
comboBox.select(itemToSelect);
} else if (firstItemId != null) {
comboBox.select(firstItemId);
}
return comboBox;
}
}
05-28-2015 11:04 AM
06-19-2015 09:20 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.