use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupPickerFieldDsTest method testOptionsDsUnsubscribe.
@Test
public void testOptionsDsUnsubscribe() {
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.setOptionsDatasource(null);
Datasource.ItemChangeListener<Group> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
groupsDs.addItemChangeListener(listener);
component.setValue(groups.get(1));
}
use of com.haulmont.cuba.core.model.common.User 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 com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupPickerFieldDsTest method testUnsubscribeDsListener.
@Test
public void testUnsubscribeDsListener() {
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);
userDs.getItem().setGroup(groups.get(0));
component.setDatasource(userDs, "group");
// unbind
component.setDatasource(null, null);
Datasource.ItemPropertyChangeListener<User> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
userDs.addItemPropertyChangeListener(listener);
component.setValue(metadata.create(Group.class));
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupPickerFieldDsTest method testSetValueWithoutOptions.
@Test
public void testSetValueWithoutOptions() {
LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
Datasource<User> userDs = createTestDatasource(User.class);
User user = userDs.getItem();
Group group = metadata.create(Group.class);
group.setName("group #0");
user.setGroup(group);
component.setDatasource(userDs, "group");
assertNotNull(component.getValue());
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class LookupPickerFieldDsTest method testUnsubscribeSubscribeOptions.
@Test
public void testUnsubscribeSubscribeOptions() {
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.setOptionsDatasource(null);
Datasource.ItemChangeListener<Group> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
groupsDs.addItemChangeListener(listener);
component.setValue(groups.get(1));
// bind
component.setOptionsDatasource(groupsDs);
groupsDs.removeItemChangeListener(listener);
boolean[] valueWasChanged = { false };
listener = e -> valueWasChanged[0] = true;
groupsDs.addItemChangeListener(listener);
component.setValue(groups.get(2));
assertTrue(valueWasChanged[0]);
}
Aggregations