use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.
the class TextFieldTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
TextField component = factory.createComponent(TextField.class);
AtomicInteger counter = new AtomicInteger(0);
Component.ValueChangeListener okListener = e -> {
assertNull(e.getPrevValue());
assertEquals("OK", e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(okListener);
component.setValue("OK");
assertEquals(1, counter.get());
component.removeValueChangeListener(okListener);
component.setValue("Test");
assertEquals(1, counter.get());
// noinspection unchecked
Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
testDs.setItem(new User());
((DatasourceImpl) testDs).valid();
Component.ValueChangeListener dsLoadListener = e -> {
assertEquals("Test", e.getPrevValue());
assertNull(e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(dsLoadListener);
component.setDatasource(testDs, "login");
assertEquals(2, counter.get());
component.removeValueChangeListener(dsLoadListener);
Component.ValueChangeListener dsListener = e -> {
assertNull(e.getPrevValue());
assertEquals("dsValue", e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(dsListener);
testDs.getItem().setLogin("dsValue");
assertEquals(3, counter.get());
}
use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.
the class DsApiConsistencyTestCase method getTestRoleDatasource.
protected Datasource<Role> getTestRoleDatasource() {
// noinspection unchecked
Datasource<Role> roleDs = (Datasource<Role>) new DsBuilder().setId("roleDs").setJavaClass(Role.class).setView(viewRepository.getView(Role.class, View.LOCAL)).buildDatasource();
roleDs.refresh();
Role role = metadata.create(Role.class);
roleDs.setItem(role);
((DatasourceImpl) roleDs).valid();
return roleDs;
}
use of com.haulmont.cuba.gui.data.DsBuilder 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();
}
}
use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.
the class DsContextTest method createDetailDsContext.
private void createDetailDsContext() {
detailDsContext = new DsContextImpl(dataService);
DsBuilder detailDsBuilder = new DsBuilder(detailDsContext);
detailDsBuilder.reset().setId("detailDs").setMetaClass(metadataSession.getClass(TestDetailEntity.class)).setViewName("_local");
detailDs = detailDsBuilder.buildDatasource();
detailDsBuilder.reset().setId("embeddedDs").setMetaClass(metadataSession.getClass(TestEmbeddableEntity.class)).setMaster(detailDs).setProperty("embeddable");
embeddableDs = detailDsBuilder.buildDatasource();
detailDsBuilder.reset().setId("partsDs").setMetaClass(metadataSession.getClass(TestPartEntity.class)).setMaster(detailDs).setProperty("parts");
partsDs = detailDsBuilder.buildCollectionDatasource();
for (Datasource ds : detailDsContext.getAll()) {
((DatasourceImplementation) ds).initialized();
}
}
use of com.haulmont.cuba.gui.data.DsBuilder in project cuba by cuba-platform.
the class LookupPickerFieldTest method testValueLoadFromOptions.
@Test
public void testValueLoadFromOptions() {
LookupPickerField component = factory.createComponent(LookupPickerField.class);
// noinspection unchecked
Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
testDs.setItem(new User());
((DatasourceImpl) testDs).valid();
assertNull(component.getValue());
Group g = new Group();
testDs.getItem().setGroup(g);
// noinspection unchecked
CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
groupsDs.includeItem(g);
Group g1 = new Group();
g1.setId(g.getId());
groupsDs.includeItem(g1);
Group g2 = new Group();
groupsDs.includeItem(g2);
component.setOptionsDatasource(groupsDs);
component.setDatasource(testDs, "group");
assertTrue("Value should be from options ds", g1 == component.getValue());
component.setValue(g2);
Component.ValueChangeListener listener1 = e -> {
assertEquals(g2, e.getPrevValue());
assertEquals(g1, e.getValue());
};
component.addValueChangeListener(listener1);
component.setValue(g);
}
Aggregations