Search in sources :

Example 31 with Datasource

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]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) TextField(com.haulmont.cuba.gui.components.TextField) 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) TextField(com.haulmont.cuba.gui.components.TextField) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 32 with Datasource

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]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) TextField(com.haulmont.cuba.gui.components.TextField) 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) TextField(com.haulmont.cuba.gui.components.TextField) Test(org.junit.Test)

Example 33 with Datasource

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");
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) TextField(com.haulmont.cuba.gui.components.TextField) 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) TextField(com.haulmont.cuba.gui.components.TextField) Test(org.junit.Test)

Example 34 with Datasource

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]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) TextField(com.haulmont.cuba.gui.components.TextField) 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) TextField(com.haulmont.cuba.gui.components.TextField) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 35 with Datasource

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();
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) TestDetailEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity) TestEmbeddableEntity(com.haulmont.cuba.gui.data.impl.testmodel1.TestEmbeddableEntity) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

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