Search in sources :

Example 6 with Subscription

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

the class LookupFieldDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    LookupField lookupField = uiComponents.create(LookupField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    lookupField.setOptionsDatasource(groupsDs);
    Datasource<User> userDs = createTestDatasource(User.class);
    Group group = groupsDs.getItems().iterator().next();
    User user = userDs.getItem();
    user.setGroup(group);
    lookupField.setDatasource(userDs, "group");
    // unbind
    lookupField.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    // datasource before listener
    lookupField.setDatasource(userDs, "group");
    Subscription subscription = lookupField.addValueChangeListener(listener);
    user.setGroup(metadata.create(Group.class));
    assertTrue(valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    lookupField.setDatasource(null, null);
    subscription.remove();
    lookupField.setValue(null);
    // listener before datasource
    lookupField.addValueChangeListener(listener);
    lookupField.setDatasource(userDs, "group");
    assertTrue(valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LookupField(com.haulmont.cuba.gui.components.LookupField) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 7 with Subscription

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

the class LookupPickerFieldDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    component.setOptionsDatasource(groupsDs);
    List<Group> groups = new ArrayList<>(groupsDs.getItems());
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setGroup(groups.get(0));
    // listener before datasource
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = component.addValueChangeListener(listener);
    component.setDatasource(userDs, "group");
    assertTrue(valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    subscription.remove();
    component.setDatasource(null, null);
    // datasource before listener
    component.setDatasource(userDs, "group");
    component.addValueChangeListener(listener);
    user.setGroup(null);
    assertTrue(valueWasChanged[0]);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 8 with Subscription

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

the class LookupPickerFieldDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    component.setOptionsDatasource(groupsDs);
    List<Group> groups = new ArrayList<>(groupsDs.getItems());
    Datasource<User> userDs = createTestDatasource(User.class);
    User user = userDs.getItem();
    user.setGroup(groups.get(0));
    component.setDatasource(userDs, "group");
    // unbind
    component.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    // datasource before listener
    component.setDatasource(userDs, "group");
    Subscription subscription = component.addValueChangeListener(listener);
    user.setGroup(metadata.create(Group.class));
    assertTrue(valueWasChanged[0]);
    // reset state
    component.setDatasource(null, null);
    subscription.remove();
    valueWasChanged[0] = false;
    component.setValue(null);
    // listener before datasource
    component.addValueChangeListener(listener);
    component.setDatasource(userDs, "group");
    assertTrue(valueWasChanged[0]);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Subscription(io.jmix.core.common.event.Subscription) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) Group(com.haulmont.cuba.core.model.common.Group) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) User(com.haulmont.cuba.core.model.common.User) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 9 with Subscription

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

the class OptionsGroupDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    OptionsGroup optionsGroup = uiComponents.create(OptionsGroup.NAME);
    Datasource<Role> roleDs = createTestDatasource(Role.class);
    roleDs.getItem().setType(RoleType.DENYING);
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setDatasource(null, null);
    // datasource before listener
    optionsGroup.setDatasource(roleDs, "type");
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = optionsGroup.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.READONLY);
    assertTrue(valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    subscription.remove();
    optionsGroup.setDatasource(null, null);
    optionsGroup.setValue(null);
    // listener before datasource
    optionsGroup.addValueChangeListener(listener);
    optionsGroup.setDatasource(roleDs, "type");
    assertTrue(valueWasChanged[0]);
}
Also used : Role(com.haulmont.cuba.core.model.common.Role) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Disabled(org.junit.jupiter.api.Disabled) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) RoleType(com.haulmont.cuba.core.model.common.RoleType) Role(com.haulmont.cuba.core.model.common.Role) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Assert.assertEquals(org.junit.Assert.assertEquals) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Subscription(io.jmix.core.common.event.Subscription) Test(org.junit.jupiter.api.Test)

Example 10 with Subscription

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

the class OptionsListDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    OptionsList optionsList = uiComponents.create(OptionsList.NAME);
    // listener before datasource
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    Subscription subscription = optionsList.addValueChangeListener(listener);
    Datasource<Role> roleDs = createTestDatasource(Role.class);
    roleDs.getItem().setType(RoleType.READONLY);
    optionsList.setDatasource(roleDs, "type");
    assertTrue(valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    subscription.remove();
    optionsList.setDatasource(null, null);
    // datasource before listener
    optionsList.setDatasource(roleDs, "type");
    optionsList.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.DENYING);
    assertTrue(valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) Autowired(org.springframework.beans.factory.annotation.Autowired) Disabled(org.junit.jupiter.api.Disabled) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) HasValue(io.jmix.ui.component.HasValue) RoleType(com.haulmont.cuba.core.model.common.RoleType) OptionsList(com.haulmont.cuba.gui.components.OptionsList) Role(com.haulmont.cuba.core.model.common.Role) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) UiComponents(com.haulmont.cuba.gui.UiComponents) Assert.assertEquals(org.junit.Assert.assertEquals) Role(com.haulmont.cuba.core.model.common.Role) Subscription(io.jmix.core.common.event.Subscription) OptionsList(com.haulmont.cuba.gui.components.OptionsList) 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