use of com.haulmont.cuba.gui.data.impl.DatasourceImpl in project cuba by cuba-platform.
the class DateFieldTest method testDatasource.
@Test
public void testDatasource() throws ParseException {
DateField component = factory.createComponent(DateField.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());
Date dsInitValue = new SimpleDateFormat("dd.MM.yyyy").parse("12.12.2000");
testDs.getItem().setCreateTs(dsInitValue);
component.setValue(new Date());
component.setDatasource(testDs, "createTs");
assertEquals(dsInitValue, component.getValue());
Date componentValue = new SimpleDateFormat("dd.MM.yyyy").parse("06.06.2000");
component.setValue(componentValue);
assertEquals(componentValue, testDs.getItem().getCreateTs());
Date dsValue = new SimpleDateFormat("dd.MM.yyyy").parse("08.08.2000");
testDs.getItem().setCreateTs(dsValue);
assertEquals(dsValue, component.getValue());
}
use of com.haulmont.cuba.gui.data.impl.DatasourceImpl in project cuba by cuba-platform.
the class DateFieldTest method testValueChangeListener.
@Test
public void testValueChangeListener() throws ParseException {
DateField component = factory.createComponent(DateField.class);
AtomicInteger counter = new AtomicInteger(0);
Date value1 = new SimpleDateFormat("dd.MM.yyyy").parse("12.12.2000");
Component.ValueChangeListener okListener = e -> {
assertNull(e.getPrevValue());
assertEquals(value1, e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(okListener);
component.setValue(value1);
assertEquals(1, counter.get());
component.removeValueChangeListener(okListener);
Date value2 = new SimpleDateFormat("dd.MM.yyyy").parse("10.10.2000");
component.setValue(value2);
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(value2, e.getPrevValue());
assertNull(e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(dsLoadListener);
component.setDatasource(testDs, "createTs");
assertEquals(2, counter.get());
component.removeValueChangeListener(dsLoadListener);
Date value3 = new SimpleDateFormat("dd.MM.yyyy").parse("01.01.2000");
Component.ValueChangeListener dsListener = e -> {
assertNull(e.getPrevValue());
assertEquals(value3, e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(dsListener);
testDs.getItem().setCreateTs(value3);
assertEquals(3, counter.get());
}
use of com.haulmont.cuba.gui.data.impl.DatasourceImpl in project cuba by cuba-platform.
the class LookupFieldTest method testDatasource.
@Test
public void testDatasource() {
LookupField component = factory.createComponent(LookupField.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();
g.setName("Group 0");
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();
Group g1 = new Group();
g1.setName("Group 1");
groupsDs.includeItem(g1);
Group g2 = new Group();
g2.setName("Group 2");
groupsDs.includeItem(g2);
component.setOptionsDatasource(groupsDs);
component.setValue(g2);
assertEquals(g2, groupsDs.getItem());
component.setDatasource(testDs, "group");
assertEquals(g, component.getValue());
assertEquals(g, groupsDs.getItem());
// due to #PL-4625
assertFalse(groupsDs.containsItem(g.getId()));
component.setValue(g1);
assertEquals(g1, testDs.getItem().getGroup());
assertEquals(g1, groupsDs.getItem());
testDs.getItem().setGroup(g2);
assertEquals(g2, component.getValue());
}
use of com.haulmont.cuba.gui.data.impl.DatasourceImpl in project cuba by cuba-platform.
the class LookupPickerFieldTest method testDatasource.
@Test
public void testDatasource() {
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();
g.setName("Group 0");
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();
Group g1 = new Group();
g1.setName("Group 1");
groupsDs.includeItem(g1);
Group g2 = new Group();
g2.setName("Group 2");
groupsDs.includeItem(g2);
component.setOptionsDatasource(groupsDs);
component.setValue(g2);
assertEquals(g2, groupsDs.getItem());
component.setDatasource(testDs, "group");
assertEquals(g, component.getValue());
assertEquals(g, groupsDs.getItem());
// due to #PL-4625
assertFalse(groupsDs.containsItem(g.getId()));
component.setValue(g1);
assertEquals(g1, testDs.getItem().getGroup());
assertEquals(g1, groupsDs.getItem());
testDs.getItem().setGroup(g2);
assertEquals(g2, component.getValue());
}
use of com.haulmont.cuba.gui.data.impl.DatasourceImpl in project cuba by cuba-platform.
the class LookupPickerFieldTest method testValueChangeListener.
@Test
public void testValueChangeListener() {
LookupPickerField component = factory.createComponent(LookupPickerField.class);
final AtomicInteger counter = new AtomicInteger(0);
// 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());
final 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();
groupsDs.includeItem(g1);
Group g2 = new Group();
groupsDs.includeItem(g2);
component.setOptionsDatasource(groupsDs);
Component.ValueChangeListener listener1 = e -> {
assertNull(e.getPrevValue());
assertEquals(g2, e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(listener1);
component.setValue(g2);
component.removeValueChangeListener(listener1);
assertEquals(1, counter.get());
Component.ValueChangeListener listener2 = e -> {
assertEquals(g2, e.getPrevValue());
assertEquals(g, e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(listener2);
component.setDatasource(testDs, "group");
assertEquals(g, component.getValue());
assertEquals(2, counter.get());
component.removeValueChangeListener(listener2);
component.setValue(g1);
assertEquals(g1, testDs.getItem().getGroup());
assertEquals(2, counter.get());
Component.ValueChangeListener listener3 = e -> {
assertEquals(g1, e.getPrevValue());
assertEquals(g2, e.getValue());
counter.addAndGet(1);
};
component.addValueChangeListener(listener3);
testDs.getItem().setGroup(g2);
assertEquals(g2, component.getValue());
assertEquals(3, counter.get());
}
Aggregations