use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class TextFieldDsTest method testUnsubscribeSubscribeComponentListener.
@Test
public void testUnsubscribeSubscribeComponentListener() {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setName("testName");
textField.setDatasource(userDs, "name");
// unbind
textField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
// datasource before listener
textField.setDatasource(userDs, "name");
textField.addValueChangeListener(listener);
user.setName("anotherName");
assertEquals(true, valueWasChanged[0]);
// reset state
textField.removeValueChangeListener(listener);
textField.setDatasource(null, null);
valueWasChanged[0] = false;
textField.setValue("testName");
// listener before datasource
textField.addValueChangeListener(listener);
textField.setDatasource(userDs, "name");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class TextFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
Datasource<User> userDs = getTestUserDatasource();
userDs.getItem().setName("testName");
textField.setDatasource(userDs, "name");
// unbind
textField.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
textField.setDatasource(userDs, "name");
textField.setValue("anotherName");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class TextFieldDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
Datasource<User> userDs = getTestUserDatasource();
userDs.getItem().setName("testName");
textField.setDatasource(userDs, "name");
// unbind
textField.setDatasource(null, null);
Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(propertyChangeListener);
textField.setValue("anotherName");
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class TextFieldDsTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
TextField textField = (TextField) factory.createComponent(TextField.NAME);
Datasource<User> userDs = getTestUserDatasource();
userDs.getItem().setName("testName");
// listener before datasource
boolean[] valueWasChanged = { false };
Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
textField.addValueChangeListener(listener);
textField.setDatasource(userDs, "name");
assertEquals(true, valueWasChanged[0]);
// reset state
valueWasChanged[0] = false;
textField.removeValueChangeListener(listener);
textField.setDatasource(null, null);
// datasource before listener
textField.setDatasource(userDs, "name");
textField.addValueChangeListener(listener);
userDs.getItem().setName("anotherName");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.
the class DsContextApplyChangesTest method createMasterDsContext.
private void createMasterDsContext() {
masterDsContext = new DsContextImpl(dataService);
DsBuilder masterDsBuilder = new DsBuilder(masterDsContext);
masterDsBuilder.reset().setId("masterDs").setMetaClass(metadataSession.getClass(TestMasterEntity.class)).setViewName("withDetail");
masterDs = masterDsBuilder.buildDatasource();
masterDsBuilder.reset().setId("detailDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setMaster(masterDs).setProperty("detail");
detailDs = masterDsBuilder.buildDatasource();
masterDsBuilder.reset().setId("embeddedDs").setMetaClass(metadataSession.getClass(TestEmbeddableEntity.class)).setMaster(detailDs).setProperty("embeddable");
embeddableDs = masterDsBuilder.buildDatasource();
for (Datasource ds : masterDsContext.getAll()) {
((DatasourceImplementation) ds).initialized();
}
}
Aggregations