/** * @param optionsMap options map */ @SuppressWarnings("unchecked") default void setOptionsMap(Map<String, ?> optionsMap) { setOptions(new MapOptions(optionsMap)); }
/** * @return options map * @deprecated Use {@link #getOptions()} instead. */ @SuppressWarnings("unchecked") @Deprecated default Map<String, ?> getOptionsMap() { Options options = getOptions(); if (options instanceof MapOptions) { return ((MapOptions) options).getItemsCollection(); } return null; }
/** * @return options map * * @deprecated use {@link TokenList#getOptions()} instead */ @SuppressWarnings("unchecked") @Deprecated default Map<String, ?> getOptionsMap() { Options options = getOptions(); if (options instanceof MapOptions) { return ((MapOptions) options).getItemsCollection(); } return null; }
/** * Sets options from the passed map and automatically applies option caption provider based on map keys. * * @param map options * @see ListOptions#of(Object, Object[]) */ default void setOptionsMap(Map<String, I> map) { checkNotNullArgument(map); BiMap<String, I> biMap = ImmutableBiMap.copyOf(map); setOptions(new MapOptions<>(map)); setOptionCaptionProvider(v -> biMap.inverse().get(v)); }
protected void addValueToLayout(final Object value, String str) { BoxLayout itemLayout = uiComponents.create(HBoxLayout.class); itemLayout.setId("itemLayout"); itemLayout.setSpacing(true); Label<String> itemLab = uiComponents.create(Label.NAME); if (options instanceof MapOptions) { //noinspection unchecked Map<String, Object> optionsMap = ((MapOptions) options).getItemsCollection(); str = optionsMap.entrySet() .stream() .filter(entry -> Objects.equals(entry.getValue(), value)) .findFirst() .get().getKey(); } itemLab.setValue(str); itemLayout.add(itemLab); itemLab.setAlignment(Alignment.MIDDLE_LEFT); LinkButton delItemBtn = uiComponents.create(LinkButton.class); delItemBtn.setIcon("icons/item-remove.png"); delItemBtn.addClickListener(e -> { valuesMap.remove(value); valuesLayout.remove(itemLayout); }); itemLayout.add(delItemBtn); if (BooleanUtils.isFalse(editable)) { delItemBtn.setEnabled(false); } valuesLayout.add(itemLayout); valuesMap.put(value, str); }