use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class PickerFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
PickerField pickerField = (PickerField) factory.createComponent(PickerField.NAME);
Datasource<User> userDs = getTestUserDatasource();
Group group = metadata.create(Group.class);
group.setName("Test group");
userDs.getItem().setGroup(group);
pickerField.setDatasource(userDs, "group");
// unbind
pickerField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
pickerField.setDatasource(userDs, "group");
pickerField.setValue(null);
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class PickerFieldDsTest method testUnsubscribeWithDsListener.
@Test
public void testUnsubscribeWithDsListener() {
PickerField pickerField = (PickerField) factory.createComponent(PickerField.NAME);
Datasource<User> userDs = getTestUserDatasource();
Group group = metadata.create(Group.class);
group.setName("Test group");
userDs.getItem().setGroup(group);
pickerField.setDatasource(userDs, "group");
// unbind
pickerField.setDatasource(null, null);
Datasource.ItemPropertyChangeListener<User> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(listener);
pickerField.setValue(null);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class PickerFieldDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
PickerField pickerField = (PickerField) factory.createComponent(PickerField.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
Group group = metadata.create(Group.class);
group.setName("Test group");
user.setGroup(group);
pickerField.setDatasource(userDs, "group");
// unbind
pickerField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
// datasource before listener
pickerField.setDatasource(userDs, "group");
pickerField.addValueChangeListener(listener);
user.setGroup(null);
assertEquals(true, valueWasChanged[0]);
// reset state
pickerField.setDatasource(null, null);
pickerField.removeValueChangeListener(listener);
valueWasChanged[0] = false;
user.setGroup(metadata.create(Group.class));
// listener before datasource
pickerField.addValueChangeListener(listener);
pickerField.setDatasource(userDs, "group");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class SearchFieldDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
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);
Datasource.ItemPropertyChangeListener<User> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(listener);
searchField.setValue(metadata.create(Group.class));
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class SearchFieldDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
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);
// setup
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
// datasource before listener
searchField.setDatasource(userDs, "group");
searchField.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
assertEquals(true, valueWasChanged[0]);
// reset state
valueWasChanged[0] = false;
searchField.setDatasource(null, null);
searchField.removeValueChangeListener(listener);
searchField.setValue(null);
// listener before datasource
searchField.addValueChangeListener(listener);
searchField.setDatasource(userDs, "group");
assertEquals(true, valueWasChanged[0]);
}
Aggregations