use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class CheckBoxDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
CheckBox checkBox = (CheckBox) factory.createComponent(CheckBox.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setActive(true);
// listener before datasource
Boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
checkBox.addValueChangeListener(listener);
checkBox.setDatasource(userDs, "active");
assertEquals(true, valueWasChanged[0]);
// reset state
checkBox.setDatasource(null, null);
checkBox.removeValueChangeListener(listener);
valueWasChanged[0] = false;
// datasource before listener
checkBox.setDatasource(userDs, "active");
checkBox.addValueChangeListener(listener);
user.setActive(false);
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DateFieldDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
DateField dateField = (DateField) factory.createComponent(DateField.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;
dateField.addValueChangeListener(listener);
dateField.setDatasource(userDs, "updateTs");
assertEquals(true, valueWasChanged[0]);
// reset state
dateField.setDatasource(null, null);
dateField.removeValueChangeListener(listener);
valueWasChanged[0] = false;
// datasource before listener
dateField.setDatasource(userDs, "updateTs");
dateField.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 DateFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
DateField dateField = (DateField) factory.createComponent(DateField.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
Date updateTs = new Date();
user.setUpdateTs(updateTs);
dateField.setDatasource(userDs, "updateTs");
// unbind
dateField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
dateField.setDatasource(userDs, "updateTs");
dateField.setResolution(DateField.Resolution.SEC);
Date updateTs2 = new Date();
dateField.setValue(updateTs2);
assertEquals(true, valueWasChanged[0]);
assertEquals(updateTs2, user.getUpdateTs());
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DateFieldDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
DateField dateField = (DateField) factory.createComponent(DateField.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
Date updateTs = new Date();
user.setUpdateTs(updateTs);
dateField.setDatasource(userDs, "updateTs");
// unbind
dateField.setDatasource(null, null);
// datasource before listener
dateField.setDatasource(userDs, "updateTs");
dateField.setResolution(DateField.Resolution.SEC);
assertEquals(updateTs, dateField.getValue());
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
dateField.addValueChangeListener(listener);
Date updateTs2 = new Date();
user.setUpdateTs(updateTs2);
assertEquals(true, valueWasChanged[0]);
assertEquals(updateTs2, dateField.getValue());
// reset state
dateField.removeValueChangeListener(listener);
dateField.setDatasource(null, null);
valueWasChanged[0] = false;
dateField.setValue(updateTs);
// listener before datasource
dateField.addValueChangeListener(listener);
dateField.setDatasource(userDs, "updateTs");
dateField.setResolution(DateField.Resolution.SEC);
assertEquals(true, valueWasChanged[0]);
assertEquals(updateTs2, dateField.getValue());
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DatePickerDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
DatePicker datePicker = (DatePicker) factory.createComponent(DatePicker.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
Date updateTs = new Date();
user.setUpdateTs(updateTs);
datePicker.setDatasource(userDs, "updateTs");
// unbind
datePicker.setDatasource(null, null);
Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(propertyChangeListener);
datePicker.setValue(new Date());
assertEquals(updateTs, user.getUpdateTs());
}
Aggregations