Search in sources :

Example 6 with PickerField

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

the class PickerFieldDsTest method testUnsubscribeWithDsListener.

@Test
public void testUnsubscribeWithDsListener() {
    PickerField pickerField = (PickerField) factory.createComponent(PickerField.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    Group group = metadata.create(Group.class);
    group.setName("Test group");
    userDs.getItem().setGroup(group);
    pickerField.setDatasource(userDs, "group");
    // unbind
    pickerField.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<User> listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(listener);
    pickerField.setValue(null);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Group(com.haulmont.cuba.security.entity.Group) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) PickerField(com.haulmont.cuba.gui.components.PickerField) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) PickerField(com.haulmont.cuba.gui.components.PickerField) Test(org.junit.Test)

Example 7 with PickerField

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

the class PickerFieldDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    PickerField pickerField = (PickerField) factory.createComponent(PickerField.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    Group group = metadata.create(Group.class);
    group.setName("Test group");
    user.setGroup(group);
    pickerField.setDatasource(userDs, "group");
    // unbind
    pickerField.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    // datasource before listener
    pickerField.setDatasource(userDs, "group");
    pickerField.addValueChangeListener(listener);
    user.setGroup(null);
    assertEquals(true, valueWasChanged[0]);
    // reset state
    pickerField.setDatasource(null, null);
    pickerField.removeValueChangeListener(listener);
    valueWasChanged[0] = false;
    user.setGroup(metadata.create(Group.class));
    // listener before datasource
    pickerField.addValueChangeListener(listener);
    pickerField.setDatasource(userDs, "group");
    assertEquals(true, valueWasChanged[0]);
}
Also used : Group(com.haulmont.cuba.security.entity.Group) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) PickerField(com.haulmont.cuba.gui.components.PickerField) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) PickerField(com.haulmont.cuba.gui.components.PickerField) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Aggregations

PickerField (com.haulmont.cuba.gui.components.PickerField)7 Group (com.haulmont.cuba.security.entity.Group)6 User (com.haulmont.cuba.security.entity.User)6 Test (org.junit.Test)6 Component (com.haulmont.cuba.gui.components.Component)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertNotNull (org.junit.Assert.assertNotNull)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Ignore (org.junit.Ignore)5 MetaClass (com.haulmont.chile.core.model.MetaClass)1