Search in sources :

Example 21 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class LookupFieldDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    LookupField lookupField = factory.createComponent(LookupField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    lookupField.setOptionsDatasource(groupsDs);
    Datasource<User> userDs = getTestUserDatasource();
    Group group = groupsDs.getItems().iterator().next();
    userDs.getItem().setGroup(group);
    lookupField.setDatasource(userDs, "group");
    // unbind
    lookupField.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(propertyChangeListener);
    lookupField.setValue(metadata.create(Group.class));
}
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) 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) LookupField(com.haulmont.cuba.gui.components.LookupField) 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) User(com.haulmont.cuba.security.entity.User) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) Test(org.junit.Test)

Example 22 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class LookupFieldDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    LookupField lookupField = factory.createComponent(LookupField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    lookupField.setOptionsDatasource(groupsDs);
    List<Group> groups = new ArrayList<>(groupsDs.getItems());
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setGroup(groups.get(0));
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    lookupField.addValueChangeListener(listener);
    lookupField.setDatasource(userDs, "group");
    assertEquals(true, valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Assert.assertTrue(org.junit.Assert.assertTrue) 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) LookupField(com.haulmont.cuba.gui.components.LookupField) 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) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 23 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class LookupFieldDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    LookupField lookupField = factory.createComponent(LookupField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    lookupField.setOptionsDatasource(groupsDs);
    Datasource<User> userDs = getTestUserDatasource();
    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 };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    // datasource before listener
    lookupField.setDatasource(userDs, "group");
    lookupField.addValueChangeListener(listener);
    user.setGroup(metadata.create(Group.class));
    assertEquals(true, valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    lookupField.setDatasource(null, null);
    lookupField.removeValueChangeListener(listener);
    lookupField.setValue(null);
    // listener before datasource
    lookupField.addValueChangeListener(listener);
    lookupField.setDatasource(userDs, "group");
    assertEquals(true, valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Assert.assertTrue(org.junit.Assert.assertTrue) 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) LookupField(com.haulmont.cuba.gui.components.LookupField) 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) User(com.haulmont.cuba.security.entity.User) LookupField(com.haulmont.cuba.gui.components.LookupField) UUID(java.util.UUID) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 24 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class LookupPickerFieldDsTest method testUnsubscribeSubscribeOptions.

@Test
public void testUnsubscribeSubscribeOptions() {
    LookupPickerField component = (LookupPickerField) factory.createComponent(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.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));
    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) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) 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) 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.Test)

Example 25 with Datasource

use of com.haulmont.cuba.gui.data.Datasource in project cuba by cuba-platform.

the class LookupPickerFieldDsTest method testOptionsDsUnsubscribe.

@Test
public void testOptionsDsUnsubscribe() {
    LookupPickerField component = (LookupPickerField) factory.createComponent(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.setOptionsDatasource(null);
    Datasource.ItemChangeListener<Group> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    groupsDs.addItemChangeListener(listener);
    component.setValue(groups.get(1));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Datasource(com.haulmont.cuba.gui.data.Datasource) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) 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) 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.Test)

Aggregations

Datasource (com.haulmont.cuba.gui.data.Datasource)111 Ignore (org.junit.Ignore)66 Test (org.junit.Test)66 Component (com.haulmont.cuba.gui.components.Component)61 User (com.haulmont.cuba.security.entity.User)56 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)53 Assert.assertTrue (org.junit.Assert.assertTrue)49 Assert.assertEquals (org.junit.Assert.assertEquals)44 Group (com.haulmont.cuba.security.entity.Group)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 Assert (org.junit.Assert)22 List (java.util.List)20 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 Date (java.util.Date)11 Entity (com.haulmont.cuba.core.entity.Entity)10 Role (com.haulmont.cuba.security.entity.Role)10 MetaClass (com.haulmont.chile.core.model.MetaClass)9 LookupField (com.haulmont.cuba.gui.components.LookupField)9