Search in sources :

Example 1 with TextField

use of com.haulmont.cuba.gui.components.TextField in project cuba by cuba-platform.

the class TextFieldDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    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);
    Component.ValueChangeListener listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    textField.addValueChangeListener(listener);
    user.setName("anotherName");
}
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 2 with TextField

use of com.haulmont.cuba.gui.components.TextField 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 3 with TextField

use of com.haulmont.cuba.gui.components.TextField 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 4 with TextField

use of com.haulmont.cuba.gui.components.TextField 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 5 with TextField

use of com.haulmont.cuba.gui.components.TextField 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)

Aggregations

TextField (com.haulmont.cuba.gui.components.TextField)6 User (com.haulmont.cuba.security.entity.User)6 Test (org.junit.Test)6 Component (com.haulmont.cuba.gui.components.Component)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Ignore (org.junit.Ignore)5