Search in sources :

Example 81 with Datasource

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

the class LookupPickerFieldDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    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();
    userDs.getItem().setGroup(groups.get(0));
    component.setDatasource(userDs, "group");
    // unbind
    component.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
    userDs.addItemPropertyChangeListener(listener);
    component.setDatasource(userDs, "group");
    component.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) 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 82 with Datasource

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

the class OptionsGroupDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    OptionsGroup optionsGroup = (OptionsGroup) factory.createComponent(OptionsGroup.NAME);
    // listener before datasource
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    optionsGroup.addValueChangeListener(listener);
    Datasource<Role> roleDs = getTestRoleDatasource();
    roleDs.getItem().setType(RoleType.READONLY);
    optionsGroup.setDatasource(roleDs, "type");
    assertTrue(valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    optionsGroup.removeValueChangeListener(listener);
    optionsGroup.setDatasource(null, null);
    // datasource before listener
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.DENYING);
    assertTrue(valueWasChanged[0]);
}
Also used : 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) Role(com.haulmont.cuba.security.entity.Role) OptionsGroup(com.haulmont.cuba.gui.components.OptionsGroup) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 83 with Datasource

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

the class OptionsGroupDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    OptionsGroup optionsGroup = (OptionsGroup) factory.createComponent(OptionsGroup.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    roleDs.getItem().setType(RoleType.DENYING);
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setDatasource(null, null);
    boolean[] valueWasChanged = { false };
    Datasource.ItemPropertyChangeListener<Role> listener = e -> valueWasChanged[0] = true;
    roleDs.addItemPropertyChangeListener(listener);
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setValue(RoleType.STANDARD);
    assertTrue(valueWasChanged[0]);
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) 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) Test(org.junit.Test)

Example 84 with Datasource

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

the class OptionsGroupDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    OptionsGroup optionsGroup = (OptionsGroup) factory.createComponent(OptionsGroup.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    roleDs.getItem().setType(RoleType.DENYING);
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setDatasource(null, null);
    // datasource before listener
    optionsGroup.setDatasource(roleDs, "type");
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    optionsGroup.addValueChangeListener(listener);
    roleDs.getItem().setType(RoleType.READONLY);
    assertEquals(true, valueWasChanged[0]);
    // reset state
    valueWasChanged[0] = false;
    optionsGroup.removeValueChangeListener(listener);
    optionsGroup.setDatasource(null, null);
    optionsGroup.setValue(null);
    // listener before datasource
    optionsGroup.addValueChangeListener(listener);
    optionsGroup.setDatasource(roleDs, "type");
    assertEquals(true, valueWasChanged[0]);
}
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 85 with Datasource

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

the class OptionsGroupDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    OptionsGroup optionsGroup = (OptionsGroup) factory.createComponent(OptionsGroup.NAME);
    Datasource<Role> roleDs = getTestRoleDatasource();
    optionsGroup.setDatasource(roleDs, "type");
    optionsGroup.setValue(RoleType.STANDARD);
    optionsGroup.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<Role> listener = e -> {
        throw new RuntimeException("");
    };
    roleDs.addItemPropertyChangeListener(listener);
    optionsGroup.setValue(RoleType.DENYING);
    assertEquals(RoleType.STANDARD, roleDs.getItem().getType());
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) 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) 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