use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.
the class CheckBoxDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
CheckBox checkBox = uiComponents.create(CheckBox.NAME);
Datasource<User> userDs = createTestDatasource(User.class);
User user = userDs.getItem();
user.setActive(true);
// listener before datasource
Boolean[] valueWasChanged = { false };
Consumer listener = e -> valueWasChanged[0] = true;
Subscription valueChangeListenerSub = checkBox.addValueChangeListener(listener);
checkBox.setDatasource(userDs, "active");
assertEquals(true, valueWasChanged[0]);
// reset state
checkBox.setDatasource(null, null);
valueChangeListenerSub.remove();
valueWasChanged[0] = false;
// datasource before listener
checkBox.setDatasource(userDs, "active");
checkBox.addValueChangeListener(listener);
user.setActive(false);
assertEquals(true, valueWasChanged[0]);
}
use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.
the class DateFieldDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
DateField dateField = uiComponents.create(DateField.NAME);
Datasource<User> userDs = createTestDatasource(User.class);
User user = userDs.getItem();
user.setUpdateTs(new Date());
// listener before datasource
Boolean[] valueWasChanged = { false };
Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
Subscription subscription = dateField.addValueChangeListener(listener);
dateField.setDatasource(userDs, "updateTs");
assertEquals(true, valueWasChanged[0]);
// reset state
dateField.setDatasource(null, null);
subscription.remove();
valueWasChanged[0] = false;
// datasource before listener
dateField.setDatasource(userDs, "updateTs");
dateField.addValueChangeListener(listener);
user.setUpdateTs(new Date());
assertEquals(true, valueWasChanged[0]);
}
use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.
the class DatePickerDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
DatePicker datePicker = uiComponents.create(DatePicker.NAME);
Datasource<User> userDs = createTestDatasource(User.class);
User user = userDs.getItem();
Date updateTs = new Date();
user.setUpdateTs(updateTs);
datePicker.setDatasource(userDs, "updateTs");
// unbind
datePicker.setDatasource(null, null);
// datasource before listener
datePicker.setDatasource(userDs, "updateTs");
assertEquals(updateTs, datePicker.getValue());
boolean[] valueWasChanged = { false };
Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
Subscription subscription = datePicker.addValueChangeListener(listener);
Date updateTs2 = new Date();
user.setUpdateTs(updateTs2);
assertTrue(valueWasChanged[0]);
assertEquals(updateTs2, datePicker.getValue());
// reset state
subscription.remove();
datePicker.setDatasource(null, null);
valueWasChanged[0] = false;
datePicker.setValue(updateTs);
// listener before datasource
datePicker.addValueChangeListener(listener);
datePicker.setDatasource(userDs, "updateTs");
assertTrue(valueWasChanged[0]);
assertEquals(updateTs2, datePicker.getValue());
}
use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.
the class DatePickerDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
DatePicker datePicker = uiComponents.create(DatePicker.NAME);
Datasource<User> userDs = createTestDatasource(User.class);
User user = userDs.getItem();
user.setUpdateTs(new Date());
// listener before datasource
Boolean[] valueWasChanged = { false };
Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
Subscription subscription = datePicker.addValueChangeListener(listener);
datePicker.setDatasource(userDs, "updateTs");
assertEquals(true, valueWasChanged[0]);
// reset state
datePicker.setDatasource(null, null);
subscription.remove();
valueWasChanged[0] = false;
// datasource before listener
datePicker.setDatasource(userDs, "updateTs");
datePicker.addValueChangeListener(listener);
user.setUpdateTs(new Date());
assertEquals(true, valueWasChanged[0]);
}
use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.
the class LabelDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
Label label = uiComponents.create(Label.NAME);
Datasource<User> userDs = createTestDatasource(User.class);
User user = userDs.getItem();
user.setName("testName");
label.setDatasource(userDs, "name");
// listener after datasource
boolean[] valueWasChanged = { false };
Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
Subscription subscription = label.addValueChangeListener(listener);
user.setName("anotherName");
assertTrue(valueWasChanged[0]);
// reset state
subscription.remove();
label.setDatasource(null, null);
valueWasChanged[0] = false;
label.setValue("testName");
// datasource after listener
label.addValueChangeListener(listener);
label.setDatasource(userDs, "name");
assertTrue(valueWasChanged[0]);
}
Aggregations