JAL-3066 Create labels for fields and hack it to work with multiple valued parameters
[jalview.git] / src / jalview / ws / slivkaws / SlivkaParamSet.java
index ed4dbd2..7e81684 100644 (file)
@@ -32,50 +32,63 @@ public class SlivkaParamSet implements WsParamSetI
     SlivkaForm form = service.getForm();
     for (FormField field : form.getFields())
     {
-      ArgumentI arg;
       switch (field.getType()) {
       case BOOLEAN:
         BooleanField boolField = (BooleanField) field;
-        arg = new BooleanOption(
-            field.getName(), field.getDescription(), field.isRequired(),
-            boolField.getDefault(), boolField.getDefault(), null
-        );
+        args.add(new BooleanOption(
+            field.getName(), field.getDescription(), field.getLabel(),
+            field.isRequired(), boolField.getDefault(), null
+        ));
         break;
       case TEXT:
         TextField textField = (TextField) field;
-        arg = new StringParameter(
+        args.add(new StringParameter(
             field.getName(), field.getDescription(), field.isRequired(),
             textField.getDefault(), textField.getDefault()
-        );
+        ));
         break;
       case INTEGER:
         IntegerField intField = (IntegerField) field;
-        arg = new IntegerParameter(
+        args.add(new IntegerParameter(
             field.getName(), field.getDescription(), field.isRequired(),
             intField.getDefault(), intField.getMin(), intField.getMax()
-        );
+        ));
         break;
       case DECIMAL:
         DecimalField doubleField = (DecimalField) field;
-        arg = new DoubleParameter(
+        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());
-        arg = new StringParameter(field.getName(), field.getDescription(),
-            field.isRequired(), choiceField.getDefault(), choiceField.getDefault(),
-            choices, choices
-        );
+        if (field.hasMultipleValues()) {
+          int counter = 0;
+          for (String choice : choices) {
+            args.add(new BooleanOption(
+                String.format("%s$%d", field.getName(), counter++),
+                field.getDescription(), choice, field.isRequired(),
+                choice.equals(choiceField.getDefault()), choice,
+                null
+            ));
+          }
+        }
+        else
+        {
+          args.add(new StringParameter(
+              field.getName(), field.getDescription(),
+              field.isRequired(), choiceField.getDefault(), choiceField.getDefault(),
+              choices, choices
+          ));
+        }
         break;
       case FILE:
       default:
         continue;
       }
-      args.add(arg);
     }
   }