jmix-framework / jmix

Jmix framework
https://www.jmix.io
Apache License 2.0
561 stars 118 forks source link

"Enabled" control system for component #2554

Open Flamesson opened 9 months ago

Flamesson commented 9 months ago

io.jmix.ui.action.BaseAction has a fluent and convenient system of the "enabled" control (EnabledRules). My team is wondered why there is no the same mechanism for io.jmix.ui.component.Component.

We often set rules like:

final boolean enabled = Objects.nonNull(route) && BooleanUtils.isNotTrue(route.getRtCalc());
component.setEnabled(enabled);

Probably it would be more convenient to setup control over "Enabled" via a bunch of @Install methods in such kind of cases.

Is there a pitfall why this wasn't implemented? Is it possible to expand the component editing system in this way?

glebfox commented 9 months ago

Is there a pitfall why this wasn't implemented?

Actions have refreshState() method that is called either by ActionsHolder component (e.g. when selection in Table has changed) and programatically, i.e. refreshState() isn't called when a Screen is opened, but when corresponding Parent UI component decided to update its actions. UI components do not and should not have such a method. I agree that using @Install is more convenient, but it's unclear when and why call refreshState()/enableRule for UI components.

Any thoughts are welcome.


Also, it must be kept in mind that in Flow UI we don't wrap Vaadin components, instead we extend some of them if needed. Such API will require extending all Vaadin components that is we want to avoid.