use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class LabelDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
Label label = (Label) factory.createComponent(Label.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setName("testName");
label.setDatasource(userDs, "name");
// unbind
label.setDatasource(null, null);
assertNotNull(label.getValue());
Component.ValueChangeListener listener = e -> {
throw new RuntimeException("Value was changed externally");
};
label.addValueChangeListener(listener);
user.setName("anotherName");
assertEquals("testName", label.getValue());
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class LabelDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
Label label = (Label) factory.createComponent(Label.NAME);
Datasource<User> userDs = getTestUserDatasource();
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.gui.data.Datasource in project cuba by cuba-platform.
the class LabelDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
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);
label.setDatasource(userDs, "name");
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(propertyChangeListener);
label.setValue("anotherName");
assertEquals(true, valueWasChanged[0]);
assertEquals("anotherName", user.getName());
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class LookupFieldDsTest method testUnsubscribeSubscribeOptions.
@Test
public void testUnsubscribeSubscribeOptions() {
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> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
groupsDs.addItemChangeListener(listener);
lookupField.setValue(groups.get(1));
// setup
groupsDs.removeItemChangeListener(listener);
boolean[] valueWasChanged = { false };
listener = e -> valueWasChanged[0] = true;
groupsDs.addItemChangeListener(listener);
lookupField.setOptionsDatasource(groupsDs);
lookupField.setValue(groups.get(2));
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class LookupFieldDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
LookupField lookupField = factory.createComponent(LookupField.class);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
lookupField.setOptionsDatasource(groupsDs);
Datasource<User> userDs = getTestUserDatasource();
Group group = groupsDs.getItems().iterator().next();
User user = userDs.getItem();
user.setGroup(group);
lookupField.setDatasource(userDs, "group");
// unbind
lookupField.setDatasource(null, null);
Component.ValueChangeListener listener = e -> {
throw new RuntimeException("Value was changed externally");
};
lookupField.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
}
Aggregations