use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DatePickerDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
DatePicker datePicker = (DatePicker) factory.createComponent(DatePicker.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setUpdateTs(new Date());
// listener before datasource
Boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
datePicker.addValueChangeListener(listener);
datePicker.setDatasource(userDs, "updateTs");
assertEquals(true, valueWasChanged[0]);
// reset state
datePicker.setDatasource(null, null);
datePicker.removeValueChangeListener(listener);
valueWasChanged[0] = false;
// datasource before listener
datePicker.setDatasource(userDs, "updateTs");
datePicker.addValueChangeListener(listener);
user.setUpdateTs(new Date());
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DsApiConsistencyTestCase method getTestRoleDatasource.
protected Datasource<Role> getTestRoleDatasource() {
// noinspection unchecked
Datasource<Role> roleDs = (Datasource<Role>) new DsBuilder().setId("roleDs").setJavaClass(Role.class).setView(viewRepository.getView(Role.class, View.LOCAL)).buildDatasource();
roleDs.refresh();
Role role = metadata.create(Role.class);
roleDs.setItem(role);
((DatasourceImpl) roleDs).valid();
return roleDs;
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class LabelDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
Label label = (Label) factory.createComponent(Label.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setName("testName");
label.setDatasource(userDs, "name");
// listener after datasource
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
label.addValueChangeListener(listener);
user.setName("anotherName");
assertEquals(true, valueWasChanged[0]);
// reset state
label.removeValueChangeListener(listener);
label.setDatasource(null, null);
valueWasChanged[0] = false;
label.setValue("testName");
// datasource after listener
label.addValueChangeListener(listener);
label.setDatasource(userDs, "name");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class LabelDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
Label label = (Label) factory.createComponent(Label.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setName("testName");
label.setDatasource(userDs, "name");
label.setDatasource(null, null);
// datasource before listener
label.setDatasource(userDs, "name");
assertEquals("testName", label.getValue());
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
label.addValueChangeListener(listener);
user.setName("anotherName");
assertEquals(true, valueWasChanged[0]);
assertEquals("anotherName", label.getValue());
// reset state
label.removeValueChangeListener(listener);
label.setDatasource(null, null);
valueWasChanged[0] = false;
label.setValue("testName");
// listener before datasource
label.addValueChangeListener(listener);
label.setDatasource(userDs, "name");
assertEquals(true, valueWasChanged[0]);
assertEquals("anotherName", label.getValue());
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class LookupFieldDsTest method testOptionsDsUnsubscribe.
@Test
public void testOptionsDsUnsubscribe() {
LookupField lookupField = factory.createComponent(LookupField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
lookupField.setOptionsDatasource(groupsDs);
List<Group> groups = new ArrayList<>(groupsDs.getItems());
Datasource<User> userDs = getTestUserDatasource();
userDs.getItem().setGroup(groups.get(0));
lookupField.setDatasource(userDs, "group");
// unbind
lookupField.setOptionsDatasource(null);
Datasource.ItemChangeListener<Group> itemChangeListener = e -> {
throw new RuntimeException("Value was changed externally");
};
groupsDs.addItemChangeListener(itemChangeListener);
lookupField.setValue(groups.get(1));
}
Aggregations