use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class DatePickerDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
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);
Consumer<HasValue.ValueChangeEvent> valueChangeListener = e -> {
throw new RuntimeException("Value was changed externally");
};
datePicker.addValueChangeListener(valueChangeListener);
user.setUpdateTs(new Date());
assertEquals(updateTs, datePicker.getValue());
}
use of com.haulmont.cuba.core.model.common.User 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]);
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LabelDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
Label label = uiComponents.create(Label.NAME);
Datasource<User> userDs = createTestDatasource(User.class);
User user = userDs.getItem();
user.setName("testName");
label.setDatasource(userDs, "name");
// unbind
label.setDatasource(null, null);
assertNotNull(label.getValue());
Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(propertyChangeListener);
label.setValue("anotherName");
assertEquals("testName", user.getName());
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LabelDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
Label label = uiComponents.create(Label.NAME);
Datasource<User> userDs = createTestDatasource(User.class);
User user = userDs.getItem();
user.setName("testName");
label.setDatasource(userDs, "name");
// unbind
label.setDatasource(null, null);
assertNotNull(label.getValue());
Consumer<HasValue.ValueChangeEvent> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
label.addValueChangeListener(listener);
user.setName("anotherName");
assertEquals("testName", label.getValue());
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
LookupField lookupField = uiComponents.create(LookupField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
lookupField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = createTestDatasource(User.class);
Group group = groupsDs.getItems().iterator().next();
userDs.getItem().setGroup(group);
lookupField.setDatasource(userDs, "group");
// unbind
lookupField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
lookupField.setDatasource(userDs, "group");
lookupField.setValue(null);
assertTrue(valueWasChanged[0]);
}
Aggregations