- switch (field.getType()) {
- case BOOLEAN:
- BooleanField boolField = (BooleanField) field;
- args.add(new BooleanOption(
- field.getName(), field.getDescription(), field.getLabel(),
- field.isRequired(), boolField.getDefault(), null
- ));
- break;
- case TEXT:
- TextField textField = (TextField) field;
- args.add(new StringParameter(
- field.getName(), field.getDescription(), field.isRequired(),
- textField.getDefault(), textField.getDefault()
- ));
- break;
- case INTEGER:
- IntegerField intField = (IntegerField) field;
- args.add(new IntegerParameter(
- field.getName(), field.getDescription(), field.isRequired(),
- intField.getDefault(), intField.getMin(), intField.getMax()
- ));
- break;
- case DECIMAL:
- DecimalField doubleField = (DecimalField) field;
- args.add(new DoubleParameter(
- field.getName(), field.getDescription(), field.isRequired(),
- doubleField.getDefault(), doubleField.getMin(),
- doubleField.getMax()
- ));
- break;
- case CHOICE:
- ChoiceField choiceField = (ChoiceField) field;
- List<String> choices = new ArrayList<>(choiceField.getChoices());
- if (field.hasMultipleValues()) {
- int counter = 0;
- for (String choice : choices) {
+ Object defaultValue = param.getDefault() instanceof List
+ ? ((List<?>) param.getDefault()).get(0)
+ : param.getDefault();
+ if (param instanceof Parameter.FlagParameter)
+ {
+ args.add(new BooleanOption(param.getId(), param.getDescription(),
+ param.getName(), param.isRequired(), (Boolean) defaultValue, null));
+ }
+ else if (param instanceof Parameter.TextParameter)
+ {
+ args.add(new StringParameter(param.getId(), param.getDescription(),
+ param.isRequired(), (String) defaultValue, (String) defaultValue));
+ }
+ else if (param instanceof Parameter.IntegerParameter)
+ {
+ Integer min = ((Parameter.IntegerParameter) param).getMin();
+ Integer max = ((Parameter.IntegerParameter) param).getMax();
+ Integer defVal = defaultValue != null
+ ? ((Number) defaultValue).intValue()
+ : null;
+ args.add(new IntegerParameter(param.getId(), param.getDescription(),
+ param.isRequired(), defVal, (min == null) ? Integer.MIN_VALUE : min,
+ (max == null) ? Integer.MAX_VALUE : max));
+ }
+ else if (param instanceof Parameter.DecimalParameter)
+ {
+ Double min = ((Parameter.DecimalParameter) param).getMin();
+ Double max = ((Parameter.DecimalParameter) param).getMax();
+ Double defVal = defaultValue != null
+ ? ((Number) defaultValue).doubleValue()
+ : null;
+ args.add(new DoubleParameter(param.getId(), param.getDescription(),
+ param.isRequired(), defVal, (min == null) ? -Double.MAX_VALUE : min,
+ (max == null) ? Double.MAX_VALUE : max));
+ }
+ else if (param instanceof Parameter.ChoiceParameter)
+ {
+ List<String> choices = ((Parameter.ChoiceParameter) param)
+ .getChoices();
+ if (param.isArray())
+ {
+ int i = 0;
+ List<?> selected = param.getDefault() != null
+ ? (List<?>) param.getDefault()
+ : Collections.EMPTY_LIST;
+ for (String choice : choices)
+ {