use of com.haulmont.cuba.gui.components.LookupPickerField in project cuba by cuba-platform.
the class LookupPickerFieldDsTest method testUnsubscribeSubscribeDsListener.
@Test
public void testUnsubscribeSubscribeDsListener() {
LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
component.setOptionsDatasource(groupsDs);
List<Group> groups = new ArrayList<>(groupsDs.getItems());
Datasource<User> userDs = getTestUserDatasource();
userDs.getItem().setGroup(groups.get(0));
component.setDatasource(userDs, "group");
// unbind
component.setDatasource(null, null);
// setup
boolean[] valueWasChanged = { false };
Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
userDs.addItemPropertyChangeListener(listener);
component.setDatasource(userDs, "group");
component.setValue(null);
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.LookupPickerField in project cuba by cuba-platform.
the class LookupPickerFieldDsTest method testUnsubscribeComponentListener.
@Test
public void testUnsubscribeComponentListener() {
LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
component.setOptionsDatasource(groupsDs);
List<Group> groups = new ArrayList<>(groupsDs.getItems());
Datasource<User> userDs = getTestUserDatasource();
User user = userDs.getItem();
user.setGroup(groups.get(0));
component.setDatasource(userDs, "group");
// unbind
component.setDatasource(null, null);
Consumer<HasValue.ValueChangeEvent> listener = e -> {
throw new RuntimeException("Value was changed externally");
};
component.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
}
use of com.haulmont.cuba.gui.components.LookupPickerField in project cuba by cuba-platform.
the class LookupPickerFieldDsTest method testSetValueWithoutOptions.
@Test
public void testSetValueWithoutOptions() {
LookupPickerField component = uiComponents.create(LookupPickerField.NAME);
Datasource<User> userDs = getTestUserDatasource();
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.gui.components.LookupPickerField in project cuba by cuba-platform.
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 = getTestUserDatasource();
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");
component.addValueChangeListener(listener);
user.setGroup(metadata.create(Group.class));
assertEquals(true, valueWasChanged[0]);
// reset state
component.setDatasource(null, null);
component.removeValueChangeListener(listener);
valueWasChanged[0] = false;
component.setValue(null);
// listener before datasource
component.addValueChangeListener(listener);
component.setDatasource(userDs, "group");
assertEquals(true, valueWasChanged[0]);
}
use of com.haulmont.cuba.gui.components.LookupPickerField in project cuba by cuba-platform.
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 = getTestUserDatasource();
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));
}
Aggregations