Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Implement ValuePicker/ValuesPicker components #6

Closed
glebfox opened this issue Aug 10, 2020 · 3 comments
Closed

Implement ValuePicker/ValuesPicker components #6

glebfox opened this issue Aug 10, 2020 · 3 comments
Assignees
Milestone

Comments

@glebfox
Copy link
Contributor

glebfox commented Aug 10, 2020

EntityPicker like component for any value type.

@glebfox
Copy link
Contributor Author

glebfox commented Aug 19, 2020

Breaking Changes

  • ClearAction renamed to EntityClearAction
  • JmixIcon.ENTITYPICKER_CLEAR -> JmixIcon.VALUEPICKER_CLEAR
  • JmixIcon.ENTITYPICKER_CLEAR_READONLY -> JmixIcon.VALUEPICKER_CLEAR_READONLY

@glebfox
Copy link
Contributor Author

glebfox commented Dec 1, 2020

ValuePicker is a component similar to EntityPicker (in fact, it is a base class for EntityPicker), but can display arbitrary values. Like any other *Picker components, can have actions - both predefined and custom.

<window xmlns="http://jmix.io/schema/ui/window">
    <data>
        <instance id="customerDc"
                  class="io.jmix.sampler.entity.Customer">
            <fetchPlan extends="_local"/>
        </instance>
    </data>
    <layout>
        <valuePicker id="valuePicker"
                     caption="Customer's name"
                     dataContainer="customerDc"
                     property="name">
            <actions>
                <action id="generate" icon="REFRESH"/>
            </actions>
        </valuePicker>
    </layout>
</window>
@UiController("valuepicker-actions")
@UiDescriptor("valuepicker-actions.xml")
public class ValuePickerActionsSample extends ScreenFragment {

    @Autowired
    protected ValuePicker<String> valuePicker;

    @Autowired
    protected Notifications notifications;
    @Autowired
    protected Actions actions;

    @Subscribe
    protected void onInit(InitEvent event) {

        valuePicker.addAction(new BaseAction("showValue")
                .withHandler(actionPerformedEvent -> {
                    String value = valuePicker.getValue();

                    notifications.create()
                            .withCaption(value != null ? value : "No value")
                            .show();
                })
                .withDescription("Show Value")
                .withIcon(JmixIcon.EYE.source()));

        valuePicker.addAction(actions.create(ValueClearAction.ID));
    }

    @Subscribe("valuePicker.generate")
    protected void onValuePickerGenerate(Action.ActionPerformedEvent event) {
        customerDc.getItem().setName(RandomStringUtils.randomAlphabetic(5, 10));
    }
}

There is only one predefined action for ValuePicker:

<action id="clear" type="value_clear"/>

@glebfox
Copy link
Contributor Author

glebfox commented Dec 1, 2020

ValuesPicker is a component that works with lists of values. Have the same API as ValuePicker. Have a predefined action to choose a list of values: SelectAction. SelectAction can be used to select any type of value, e.g.:

Primitive types, like String:

<valuesPicker id="stringsValuePicker"
              caption="Strings">
    <actions>
        <action id="select" type="values_select">
            <properties>
                <property name="javaClass" value="java.lang.String"/>
            </properties>
        </action>
        <action id="clear" type="value_clear"/>
    </actions>
</valuesPicker>

Enums:

<valuesPicker id="valuePicker">
    <actions>
        <action id="select" type="values_select">
            <properties>
                <property name="enumClass" value="io.jmix.sampler.entity.CustomerGrade"/>
            </properties>
        </action>
        <action id="clear" type="value_clear"/>
    </actions>
</valuesPicker>

Entities:

<valuesPicker id="valuePicker">
    <actions>
        <action id="select" type="values_select">
            <properties>
                <property name="entityName" value="sampler_Customer"/>
            </properties>
        </action>
        <action id="clear" type="value_clear"/>
    </actions>
</valuesPicker>

SelectAction has the following settings:

  • selectValueScreenId - id of a screen that implements the SelectValueController interface
  • selectValueScreenClass - class of a screen that implements the SelectValueController interface
  • lookupScreenId- the lookup screen id that will be used in SelectValueController to select entity values
  • entityName - the entity name which is used as the component value type in SelectValueController screen
  • javaClass - the java class which is used as the component value type in SelectValueController screen
  • enumClass - the enumeration class which is used as the component value type in SelectValueController screen
  • useComboBox - whether the ComboBox should be used in SelectValueController screen to select entity values
  • resolution - the resolution of DateField component that is used to select values which have date value type

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant