2929
3030import static java .util .Optional .ofNullable ;
3131
32- public class DropdownComponentProvider extends ValueComponentProvider {
32+ public class OptionListComponentProvider extends ValueComponentProvider {
33+ private final Type type ;
3334 private final Map <UUID , List <String >> optionsMap = new ConcurrentHashMap <>();
3435 private final String text ;
3536 private final List <String > options ;
3637 private final String defaultOption ;
3738
38- public DropdownComponentProvider ( ComponentProviderBuilder .Input input ) {
39+ public OptionListComponentProvider ( Type type , ComponentProviderBuilder .Input input ) {
3940 super (input );
41+ this .type = type ;
4042 this .text = ofNullable (MapUtils .getIfFound (input .options , "text" ))
4143 .map (Object ::toString )
4244 .orElse ("" );
@@ -57,12 +59,33 @@ protected void apply(UUID uuid, CustomForm.Builder builder) {
5759 String replacedDefaultOption = StringReplacerApplier .replace (this .defaultOption , uuid , this );
5860 int defaultOption = Validate .getNumber (replacedDefaultOption ).map (Number ::intValue ).orElse (0 );
5961
60- builder .dropdown (replacedText , replacedOptions , defaultOption );
62+ switch (this .type ) {
63+ case DROPDOWN :
64+ builder .dropdown (replacedText , replacedOptions , defaultOption );
65+ break ;
66+ case STEP_SLIDER :
67+ builder .stepSlider (replacedText , replacedOptions , defaultOption );
68+ break ;
69+ }
6170 this .optionsMap .put (uuid , replacedOptions );
6271 }
6372
6473 @ Override
6574 protected String getValue (UUID uuid , CustomFormResponse response ) {
66- return this .optionsMap .get (uuid ).get (response .asDropdown ());
75+ int index = 0 ;
76+ switch (this .type ) {
77+ case DROPDOWN :
78+ index = response .asDropdown ();
79+ break ;
80+ case STEP_SLIDER :
81+ index = response .asStepSlider ();
82+ break ;
83+ }
84+ return this .optionsMap .get (uuid ).get (index );
85+ }
86+
87+ public enum Type {
88+ DROPDOWN ,
89+ STEP_SLIDER
6790 }
6891}
0 commit comments