Search in sources :

Example 1 with LookupSelectionChangeNotifier

use of io.jmix.ui.component.LookupComponent.LookupSelectionChangeNotifier in project jmix by jmix-framework.

the class StandardLookup method setSelectHandler.

@Override
public void setSelectHandler(@Nullable Consumer<Collection<T>> selectHandler) {
    this.selectHandler = selectHandler;
    Component lookupActionsLayout = getLookupActionsLayout();
    if (lookupActionsLayout != null) {
        lookupActionsLayout.setVisible(true);
        Component lookupComponent = getLookupComponent();
        if (lookupComponent instanceof LookupSelectionChangeNotifier) {
            LookupSelectionChangeNotifier selectionNotifier = (LookupSelectionChangeNotifier) lookupComponent;
            Action commitAction = getWindow().getAction(LOOKUP_SELECT_ACTION_ID);
            if (commitAction != null) {
                // noinspection unchecked
                selectionNotifier.addLookupValueChangeListener(valueChangeEvent -> commitAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty()));
                commitAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty());
            }
        }
    }
}
Also used : Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) LookupSelectionChangeNotifier(io.jmix.ui.component.LookupComponent.LookupSelectionChangeNotifier) LookupComponent(io.jmix.ui.component.LookupComponent)

Aggregations

Action (io.jmix.ui.action.Action)1 BaseAction (io.jmix.ui.action.BaseAction)1 LookupComponent (io.jmix.ui.component.LookupComponent)1 LookupSelectionChangeNotifier (io.jmix.ui.component.LookupComponent.LookupSelectionChangeNotifier)1