Search in sources :

Example 26 with Datasource

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

the class OptionsGroupDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    OptionsGroup optionsGroup = (OptionsGroup) factory.createComponent(OptionsGroup.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setValue(RoleType.STANDARD);
    optionsGroup.setDatasource(null, null);
    Component.ValueChangeListener listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    optionsGroup.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.DENYING);
    assertEquals(RoleType.STANDARD, optionsGroup.getValue());
}
Also used : Role(com.haulmont.cuba.security.entity.Role) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Role(com.haulmont.cuba.security.entity.Role) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) RoleType(com.haulmont.cuba.security.entity.RoleType) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 27 with Datasource

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

the class PickerFieldDsTest method testUnsubscribeWithComponentListener.

@Test
public void testUnsubscribeWithComponentListener() {
    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);
    Component.ValueChangeListener listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    pickerField.addValueChangeListener(listener);
    userDs.getItem().setGroup(metadata.create(Group.class));
}
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)

Example 28 with Datasource

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

the class PickerFieldDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    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);
    // datasource before listener
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    pickerField.addValueChangeListener(listener);
    pickerField.setDatasource(userDs, "group");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    pickerField.setDatasource(null, null);
    pickerField.removeValueChangeListener(listener);
    valueWasChanged[0] = false;
    pickerField.setValue(null);
    // 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)

Example 29 with Datasource

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

the class SearchFieldDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    SearchField searchField = factory.createComponent(SearchField.class);
    CollectionDatasource<Group, UUID> groupsDs = getTestCollectionDatasource();
    searchField.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;
    searchField.addValueChangeListener(listener);
    searchField.setDatasource(userDs, "group");
    assertEquals(true, valueWasChanged[0]);
}
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) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 30 with Datasource

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

the class TextFieldDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    TextField textField = (TextField) factory.createComponent(TextField.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    textField.setDatasource(userDs, "name");
    // unbind
    textField.setDatasource(null, null);
    Component.ValueChangeListener listener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    textField.addValueChangeListener(listener);
    user.setName("anotherName");
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) TextField(com.haulmont.cuba.gui.components.TextField) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) User(com.haulmont.cuba.security.entity.User) TextField(com.haulmont.cuba.gui.components.TextField) Component(com.haulmont.cuba.gui.components.Component) 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