Search in sources :

Example 16 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class DatePickerDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    DatePicker datePicker = (DatePicker) factory.createComponent(DatePicker.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setUpdateTs(new Date());
    // listener before datasource
    Boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    datePicker.addValueChangeListener(listener);
    datePicker.setDatasource(userDs, "updateTs");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    datePicker.setDatasource(null, null);
    datePicker.removeValueChangeListener(listener);
    valueWasChanged[0] = false;
    // datasource before listener
    datePicker.setDatasource(userDs, "updateTs");
    datePicker.addValueChangeListener(listener);
    user.setUpdateTs(new Date());
    assertEquals(true, valueWasChanged[0]);
}
Also used : DatePicker(com.haulmont.cuba.gui.components.DatePicker) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Date(java.util.Date) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) User(com.haulmont.cuba.security.entity.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Component(com.haulmont.cuba.gui.components.Component) Date(java.util.Date) Test(org.junit.Test)

Example 17 with Datasource

use of com.haulmont.cuba.gui.data.Datasource 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;
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) CollectionDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

Example 18 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class LabelDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    Label label = (Label) factory.createComponent(Label.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    // listener after datasource
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    label.addValueChangeListener(listener);
    user.setName("anotherName");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    label.removeValueChangeListener(listener);
    label.setDatasource(null, null);
    valueWasChanged[0] = false;
    label.setValue("testName");
    // datasource after listener
    label.addValueChangeListener(listener);
    label.setDatasource(userDs, "name");
    assertEquals(true, valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) User(com.haulmont.cuba.security.entity.User) Label(com.haulmont.cuba.gui.components.Label) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 19 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class LabelDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    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);
    // datasource before listener
    label.setDatasource(userDs, "name");
    assertEquals("testName", label.getValue());
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    label.addValueChangeListener(listener);
    user.setName("anotherName");
    assertEquals(true, valueWasChanged[0]);
    assertEquals("anotherName", label.getValue());
    // reset state
    label.removeValueChangeListener(listener);
    label.setDatasource(null, null);
    valueWasChanged[0] = false;
    label.setValue("testName");
    // listener before datasource
    label.addValueChangeListener(listener);
    label.setDatasource(userDs, "name");
    assertEquals(true, valueWasChanged[0]);
    assertEquals("anotherName", label.getValue());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) User(com.haulmont.cuba.security.entity.User) Label(com.haulmont.cuba.gui.components.Label) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 20 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class LookupFieldDsTest method testOptionsDsUnsubscribe.

@Test
public void testOptionsDsUnsubscribe() {
    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> itemChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    groupsDs.addItemChangeListener(itemChangeListener);
    lookupField.setValue(groups.get(1));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Datasource(com.haulmont.cuba.gui.data.Datasource) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) Group(com.haulmont.cuba.security.entity.Group) List(java.util.List) Ignore(org.junit.Ignore) LookupField(com.haulmont.cuba.gui.components.LookupField) Component(com.haulmont.cuba.gui.components.Component) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

Datasource (com.haulmont.cuba.gui.data.Datasource)111 Ignore (org.junit.Ignore)66 Test (org.junit.Test)66 Component (com.haulmont.cuba.gui.components.Component)61 User (com.haulmont.cuba.security.entity.User)56 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)53 Assert.assertTrue (org.junit.Assert.assertTrue)49 Assert.assertEquals (org.junit.Assert.assertEquals)44 Group (com.haulmont.cuba.security.entity.Group)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 Assert (org.junit.Assert)22 List (java.util.List)20 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 Date (java.util.Date)11 Entity (com.haulmont.cuba.core.entity.Entity)10 Role (com.haulmont.cuba.security.entity.Role)10 MetaClass (com.haulmont.chile.core.model.MetaClass)9 LookupField (com.haulmont.cuba.gui.components.LookupField)9