use of com.haulmont.cuba.gui.components.LookupPickerField in project cuba by cuba-platform.
the class LookupPickerFieldDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
component.setOptionsDatasource(groupsDs);
List<Group> groups = new ArrayList<>(groupsDs.getItems());
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setGroup(groups.get(0));
// listener before datasource
boolean[] valueWasChanged = { false };
Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
component.addValueChangeListener(listener);
component.setDatasource(userDs, "group");
assertEquals(true, valueWasChanged[0]);
// reset state
valueWasChanged[0] = false;
component.removeValueChangeListener(listener);
component.setDatasource(null, null);
// datasource before listener
component.setDatasource(userDs, "group");
component.addValueChangeListener(listener);
user.setGroup(null);
assertEquals(true, valueWasChanged[0]);
}
Aggregations