Search in sources :

Example 1 with Subscription

use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.

the class CheckBoxDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    CheckBox checkBox = uiComponents.create(CheckBox.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setActive(true);
    // listener before datasource
    Boolean[] valueWasChanged = { false };
    Consumer listener = e -> valueWasChanged[0] = true;
    Subscription valueChangeListenerSub = checkBox.addValueChangeListener(listener);
    checkBox.setDatasource(userDs, "active");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    checkBox.setDatasource(null, null);
    valueChangeListenerSub.remove();
    valueWasChanged[0] = false;
    // datasource before listener
    checkBox.setDatasource(userDs, "active");
    checkBox.addValueChangeListener(listener);
    user.setActive(false);
    assertEquals(true, valueWasChanged[0]);
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) Consumer(java.util.function.Consumer) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 2 with Subscription

use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.

the class DateFieldDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    DateField dateField = uiComponents.create(DateField.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setUpdateTs(new Date());
    // listener before datasource
    Boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = dateField.addValueChangeListener(listener);
    dateField.setDatasource(userDs, "updateTs");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    dateField.setDatasource(null, null);
    subscription.remove();
    valueWasChanged[0] = false;
    // datasource before listener
    dateField.setDatasource(userDs, "updateTs");
    dateField.addValueChangeListener(listener);
    user.setUpdateTs(new Date());
    assertEquals(true, valueWasChanged[0]);
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) Datasource(com.haulmont.cuba.gui.data.Datasource) DateField(com.haulmont.cuba.gui.components.DateField) Subscription(io.jmix.core.common.event.Subscription) Date(java.util.Date) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) DateField(com.haulmont.cuba.gui.components.DateField) Subscription(io.jmix.core.common.event.Subscription) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with Subscription

use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.

the class DatePickerDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    DatePicker datePicker = uiComponents.create(DatePicker.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    Date updateTs = new Date();
    user.setUpdateTs(updateTs);
    datePicker.setDatasource(userDs, "updateTs");
    // unbind
    datePicker.setDatasource(null, null);
    // datasource before listener
    datePicker.setDatasource(userDs, "updateTs");
    assertEquals(updateTs, datePicker.getValue());
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = datePicker.addValueChangeListener(listener);
    Date updateTs2 = new Date();
    user.setUpdateTs(updateTs2);
    assertTrue(valueWasChanged[0]);
    assertEquals(updateTs2, datePicker.getValue());
    // reset state
    subscription.remove();
    datePicker.setDatasource(null, null);
    valueWasChanged[0] = false;
    datePicker.setValue(updateTs);
    // listener before datasource
    datePicker.addValueChangeListener(listener);
    datePicker.setDatasource(userDs, "updateTs");
    assertTrue(valueWasChanged[0]);
    assertEquals(updateTs2, datePicker.getValue());
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Date(java.util.Date) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Subscription(io.jmix.core.common.event.Subscription) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with Subscription

use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.

the class DatePickerDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    DatePicker datePicker = uiComponents.create(DatePicker.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setUpdateTs(new Date());
    // listener before datasource
    Boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = datePicker.addValueChangeListener(listener);
    datePicker.setDatasource(userDs, "updateTs");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    datePicker.setDatasource(null, null);
    subscription.remove();
    valueWasChanged[0] = false;
    // datasource before listener
    datePicker.setDatasource(userDs, "updateTs");
    datePicker.addValueChangeListener(listener);
    user.setUpdateTs(new Date());
    assertEquals(true, valueWasChanged[0]);
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Date(java.util.Date) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) DatePicker(com.haulmont.cuba.gui.components.DatePicker) Subscription(io.jmix.core.common.event.Subscription) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with Subscription

use of io.jmix.core.common.event.Subscription in project jmix by jmix-framework.

the class LabelDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    Label label = uiComponents.create(Label.NAME);
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    // listener after datasource
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = label.addValueChangeListener(listener);
    user.setName("anotherName");
    assertTrue(valueWasChanged[0]);
    // reset state
    subscription.remove();
    label.setDatasource(null, null);
    valueWasChanged[0] = false;
    label.setValue("testName");
    // datasource after listener
    label.addValueChangeListener(listener);
    label.setDatasource(userDs, "name");
    assertTrue(valueWasChanged[0]);
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Assertions(org.junit.jupiter.api.Assertions) Label(com.haulmont.cuba.gui.components.Label) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) Label(com.haulmont.cuba.gui.components.Label) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Aggregations

Subscription (io.jmix.core.common.event.Subscription)26 Datasource (com.haulmont.cuba.gui.data.Datasource)24 Consumer (java.util.function.Consumer)24 Disabled (org.junit.jupiter.api.Disabled)24 Test (org.junit.jupiter.api.Test)24 HasValue (io.jmix.ui.component.HasValue)22 User (com.haulmont.cuba.core.model.common.User)20 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)18 Assertions (org.junit.jupiter.api.Assertions)10 Group (com.haulmont.cuba.core.model.common.Group)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)7 UUID (java.util.UUID)7 ArrayList (java.util.ArrayList)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)6 UiComponents (com.haulmont.cuba.gui.UiComponents)5 Date (java.util.Date)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Role (com.haulmont.cuba.core.model.common.Role)4