Search in sources :

Example 11 with LookupPickerField

use of com.haulmont.cuba.gui.components.LookupPickerField in project cuba by cuba-platform.

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 = getTestUserDatasource();
    User user = userDs.getItem();
    user.setGroup(groups.get(0));
    // listener before datasource
    boolean[] valueWasChanged = { false };
    Consumer<HasValue.ValueChangeEvent> listener = e -> valueWasChanged[0] = true;
    component.addValueChangeListener(listener);
    component.setDatasource(userDs, "group");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    component.removeValueChangeListener(listener);
    component.setDatasource(null, null);
    // datasource before listener
    component.setDatasource(userDs, "group");
    component.addValueChangeListener(listener);
    user.setGroup(null);
    assertEquals(true, valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) UUID(java.util.UUID) Disabled(org.junit.jupiter.api.Disabled) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Group(com.haulmont.cuba.security.entity.Group) List(java.util.List) HasValue(com.haulmont.cuba.gui.components.HasValue) Assertions(org.junit.jupiter.api.Assertions) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)11 Group (com.haulmont.cuba.security.entity.Group)9 User (com.haulmont.cuba.security.entity.User)9 Test (org.junit.jupiter.api.Test)9 HasValue (com.haulmont.cuba.gui.components.HasValue)7 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)7 Datasource (com.haulmont.cuba.gui.data.Datasource)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 UUID (java.util.UUID)7 Consumer (java.util.function.Consumer)7 Assertions (org.junit.jupiter.api.Assertions)7 Disabled (org.junit.jupiter.api.Disabled)7 Entity (com.haulmont.cuba.core.entity.Entity)1 Actions (com.haulmont.cuba.gui.components.Actions)1 SupportsUserAction (com.haulmont.cuba.gui.components.SupportsUserAction)1 GuiActionSupport (com.haulmont.cuba.gui.components.actions.GuiActionSupport)1 Options (com.haulmont.cuba.gui.components.data.Options)1 EntityOptions (com.haulmont.cuba.gui.components.data.meta.EntityOptions)1