Search in sources :

Example 6 with SearchField

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

the class SearchFieldDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    SearchField searchField = factory.createComponent(SearchField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    searchField.setOptionsDatasource(groupsDs);
    Datasource<User> userDs = getTestUserDatasource();
    Group group = groupsDs.getItems().iterator().next();
    User user = userDs.getItem();
    user.setGroup(group);
    searchField.setDatasource(userDs, "group");
    // unbind
    searchField.setDatasource(null, null);
    Component.ValueChangeListener listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    searchField.addValueChangeListener(listener);
    user.setGroup(metadata.create(Group.class));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Assert.assertTrue(org.junit.Assert.assertTrue) SearchField(com.haulmont.cuba.gui.components.SearchField) Test(org.junit.Test) UUID(java.util.UUID) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) Group(com.haulmont.cuba.security.entity.Group) List(java.util.List) Ignore(org.junit.Ignore) Component(com.haulmont.cuba.gui.components.Component) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.security.entity.Group) SearchField(com.haulmont.cuba.gui.components.SearchField) User(com.haulmont.cuba.security.entity.User) UUID(java.util.UUID) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 7 with SearchField

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

the class SearchFieldDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    SearchField searchField = factory.createComponent(SearchField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    searchField.setOptionsDatasource(groupsDs);
    Datasource<User> userDs = getTestUserDatasource();
    Group group = groupsDs.getItems().iterator().next();
    userDs.getItem().setGroup(group);
    searchField.setDatasource(userDs, "group");
    // unbind
    searchField.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
    userDs.addItemPropertyChangeListener(listener);
    searchField.setDatasource(userDs, "group");
    searchField.setValue(null);
    assertEquals(true, valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Datasource(com.haulmont.cuba.gui.data.Datasource) Assert.assertTrue(org.junit.Assert.assertTrue) SearchField(com.haulmont.cuba.gui.components.SearchField) Test(org.junit.Test) UUID(java.util.UUID) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) Group(com.haulmont.cuba.security.entity.Group) List(java.util.List) Ignore(org.junit.Ignore) Component(com.haulmont.cuba.gui.components.Component) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.security.entity.Group) SearchField(com.haulmont.cuba.gui.components.SearchField) User(com.haulmont.cuba.security.entity.User) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

SearchField (com.haulmont.cuba.gui.components.SearchField)7 User (com.haulmont.cuba.security.entity.User)6 Test (org.junit.Test)6 Component (com.haulmont.cuba.gui.components.Component)5 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 Group (com.haulmont.cuba.security.entity.Group)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 UUID (java.util.UUID)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Ignore (org.junit.Ignore)5 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1