List of usage examples for com.vaadin.data.validator FloatRangeValidator FloatRangeValidator
public FloatRangeValidator(String errorMessage, Float minValue, Float maxValue)
From source file:qbic.vaadincomponents.ParameterComponent.java
License:Open Source License
public void buildForm(final Workflow workFlow) { parameterForm.removeAllComponents(); parameterFieldGroup = new FieldGroup(); inputListFieldGroup = new FieldGroup(); /*/*from w w w .ja v a 2s.c o m*/ * for (Map.Entry<String, Parameter> entry : workFlow.getData().getData().entrySet()) { * FileParameter param = (FileParameter) entry.getValue(); FileNameValidator fileNameValidator = * new FileNameValidator("Please provide a valid file path"); TextField newField = * createInputField(param, fileNameValidator); * * parameterForm.addComponent(newField); inputListFieldGroup.bind(newField, entry.getKey()); // * Have to set it here because field gets cleared upon binding * newField.setValue(param.getValue().toString()); } */ for (Map.Entry<String, Parameter> entry : workFlow.getParameters().getParams().entrySet()) { if (entry.getValue() instanceof FloatParameter) { FloatParameter param = (FloatParameter) entry.getValue(); FloatRangeValidator floatValidator = new FloatRangeValidator( String.format("Parameter has to be in the range of %s to %s", param.getMinimum(), param.getMaximum()), param.getMinimum(), param.getMaximum()); TextField newField = createParameterField(param, floatValidator, new StringToFloatConverter()); parameterForm.addComponent(newField); parameterFieldGroup.bind(newField, entry.getKey()); // Have to set it here because field gets cleared upon binding newField.setValue(param.getValue().toString()); newField.setRequired(param.isRequired()); } else if (entry.getValue() instanceof IntParameter) { IntParameter param = (IntParameter) entry.getValue(); IntegerRangeValidator intValidator = new IntegerRangeValidator( String.format("Parameter has to be in the range of %s to %s", param.getMinimum(), param.getMaximum()), param.getMinimum(), param.getMaximum()); TextField newField = createParameterField(param, intValidator, new StringToIntegerConverter()); parameterForm.addComponent(newField); parameterFieldGroup.bind(newField, entry.getKey()); // Have to set it here because field gets cleared upon binding newField.setValue(param.getValue().toString()); newField.setRequired(param.isRequired()); } else if (entry.getValue() instanceof StringParameter) { StringParameter param = (StringParameter) entry.getValue(); if (param.getRange().size() == 0) { TextField newField = createInputField(param, null); parameterForm.addComponent(newField); parameterFieldGroup.bind(newField, entry.getKey()); // Have to set it here because field gets cleared upon binding newField.setValue(param.getValue().toString()); newField.setRequired(param.isRequired()); } else { ComboBox newField = createStringSelectionParameterField(param); parameterForm.addComponent(newField); parameterFieldGroup.bind(newField, entry.getKey()); // Have to set it here because field gets cleared upon binding newField.setValue(param.getValue().toString()); newField.setRequired(param.isRequired()); } } else if (entry.getValue() instanceof BooleanParameter) { BooleanParameter param = (BooleanParameter) entry.getValue(); CheckBox newField = createParameterCheckBox(param); newField.setValue((boolean) param.getValue()); parameterForm.addComponent(newField); parameterFieldGroup.bind(newField, entry.getKey()); // Have to set it here because field gets cleared upon binding newField.setValue((Boolean) param.getValue()); newField.setRequired(param.isRequired()); } } }