use of com.haulmont.cuba.gui.components.SearchField in project cuba by cuba-platform.
the class SearchFieldDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
SearchField searchField = factory.createComponent(SearchField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
searchField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = getTestUserDatasource();
Group group = groupsDs.getItems().iterator().next();
User user = userDs.getItem();
user.setGroup(group);
searchField.setDatasource(userDs, "group");
// unbind
searchField.setDatasource(null, null);
Component.ValueChangeListener listener = e -> {
throw new RuntimeException("Value was changed externally");
};
searchField.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
}
use of com.haulmont.cuba.gui.components.SearchField in project cuba by cuba-platform.
the class SearchFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
SearchField searchField = factory.createComponent(SearchField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
searchField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = getTestUserDatasource();
Group group = groupsDs.getItems().iterator().next();
userDs.getItem().setGroup(group);
searchField.setDatasource(userDs, "group");
// unbind
searchField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
searchField.setDatasource(userDs, "group");
searchField.setValue(null);
assertEquals(true, valueWasChanged[0]);
}
Aggregations