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]);
}
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]);
}
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]);
}
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]);
}
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]);
}
Aggregations