Search in sources :

Example 11 with DatasourceImpl

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

the class TextFieldTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    TextField component = factory.createComponent(TextField.class);
    AtomicInteger counter = new AtomicInteger(0);
    Component.ValueChangeListener okListener = e -> {
        assertNull(e.getPrevValue());
        assertEquals("OK", e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(okListener);
    component.setValue("OK");
    assertEquals(1, counter.get());
    component.removeValueChangeListener(okListener);
    component.setValue("Test");
    assertEquals(1, counter.get());
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    Component.ValueChangeListener dsLoadListener = e -> {
        assertEquals("Test", e.getPrevValue());
        assertNull(e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(dsLoadListener);
    component.setDatasource(testDs, "login");
    assertEquals(2, counter.get());
    component.removeValueChangeListener(dsLoadListener);
    Component.ValueChangeListener dsListener = e -> {
        assertNull(e.getPrevValue());
        assertEquals("dsValue", e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(dsListener);
    testDs.getItem().setLogin("dsValue");
    assertEquals(3, counter.get());
}
Also used : View(com.haulmont.cuba.core.global.View) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) Datatypes(com.haulmont.chile.core.datatypes.Datatypes) Test(org.junit.Test) Assert(org.junit.Assert) User(com.haulmont.cuba.security.entity.User) User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 12 with DatasourceImpl

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

the class DsApiConsistencyTestCase method getTestRoleDatasource.

protected Datasource<Role> getTestRoleDatasource() {
    // noinspection unchecked
    Datasource<Role> roleDs = (Datasource<Role>) new DsBuilder().setId("roleDs").setJavaClass(Role.class).setView(viewRepository.getView(Role.class, View.LOCAL)).buildDatasource();
    roleDs.refresh();
    Role role = metadata.create(Role.class);
    roleDs.setItem(role);
    ((DatasourceImpl) roleDs).valid();
    return roleDs;
}
Also used : Role(com.haulmont.cuba.security.entity.Role) Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) CollectionDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder)

Example 13 with DatasourceImpl

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

the class BulkEditorWindow method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    String width = themeConstants.get("cuba.gui.BulkEditorWindow.width");
    String height = themeConstants.get("cuba.gui.BulkEditorWindow.height");
    getDialogOptions().setWidth(width).setHeight(height);
    checkNotNullArgument(metaClass);
    checkNotNullArgument(selected);
    if (StringUtils.isNotBlank(exclude)) {
        excludeRegex = Pattern.compile(exclude);
    }
    for (ManagedField managedField : getManagedFields(metaClass)) {
        managedFields.put(managedField.getFqn(), managedField);
    }
    View view = createView(metaClass);
    items = loadItems(view);
    dsContext = new DsContextImpl(dataSupplier);
    dsContext.setFrameContext(getDsContext().getFrameContext());
    setDsContext(dsContext);
    datasource = new DatasourceImpl<>();
    datasource.setup(dsContext, dataSupplier, metaClass.getName() + "Ds", metaClass, view);
    ((DatasourceImpl) datasource).valid();
    dsContext.register(datasource);
    createNestedEmbeddedDatasources(datasource, metaClass, "");
    Entity instance = metadata.create(metaClass);
    if (loadDynamicAttributes && (instance instanceof BaseGenericIdEntity)) {
        ((BaseGenericIdEntity) instance).setDynamicAttributes(new HashMap<>());
    }
    createEmbeddedFields(metaClass, instance, "");
    datasource.setItem(instance);
    datasource.setAllowCommit(false);
    createDataComponents();
}
Also used : BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) Entity(com.haulmont.cuba.core.entity.Entity) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) EmbeddedDatasourceImpl(com.haulmont.cuba.gui.data.impl.EmbeddedDatasourceImpl) BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) DsContextImpl(com.haulmont.cuba.gui.data.impl.DsContextImpl)

Example 14 with DatasourceImpl

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

the class LookupPickerFieldTest method testValueLoadFromOptions.

@Test
public void testValueLoadFromOptions() {
    LookupPickerField component = factory.createComponent(LookupPickerField.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    Group g = new Group();
    testDs.getItem().setGroup(g);
    // noinspection unchecked
    CollectionDatasource<Group, UUID> groupsDs = new DsBuilder().setId("testDs").setJavaClass(Group.class).setView(viewRepository.getView(Group.class, View.LOCAL)).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setAllowCommit(false).buildCollectionDatasource();
    groupsDs.includeItem(g);
    Group g1 = new Group();
    g1.setId(g.getId());
    groupsDs.includeItem(g1);
    Group g2 = new Group();
    groupsDs.includeItem(g2);
    component.setOptionsDatasource(groupsDs);
    component.setDatasource(testDs, "group");
    assertTrue("Value should be from options ds", g1 == component.getValue());
    component.setValue(g2);
    Component.ValueChangeListener listener1 = e -> {
        assertEquals(g2, e.getPrevValue());
        assertEquals(g1, e.getValue());
    };
    component.addValueChangeListener(listener1);
    component.setValue(g);
}
Also used : PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) Arrays(java.util.Arrays) Datasource(com.haulmont.cuba.gui.data.Datasource) NonStrictExpectations(mockit.NonStrictExpectations) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test) PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) UUID(java.util.UUID) AppBeans(com.haulmont.cuba.core.global.AppBeans) User(com.haulmont.cuba.security.entity.User) ArrayList(java.util.ArrayList) Group(com.haulmont.cuba.security.entity.Group) View(com.haulmont.cuba.core.global.View) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) Assert(org.junit.Assert) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Mocked(mockit.Mocked) Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) UUID(java.util.UUID) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Example 15 with DatasourceImpl

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

the class OptionsGroupTest method testDatasource.

@Test
public void testDatasource() {
    OptionsGroup component = factory.createComponent(OptionsGroup.class);
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getView(User.class, View.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    assertNull(component.getValue());
    component.setDatasource(testDs, "group");
    assertNotNull(component.getDatasource());
}
Also used : User(com.haulmont.cuba.security.entity.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Test(org.junit.Test)

Aggregations

DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)19 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)18 User (com.haulmont.cuba.security.entity.User)17 Test (org.junit.Test)16 Group (com.haulmont.cuba.security.entity.Group)10 Datasource (com.haulmont.cuba.gui.data.Datasource)8 UUID (java.util.UUID)8 View (com.haulmont.cuba.core.global.View)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Assert (org.junit.Assert)7 Ignore (org.junit.Ignore)7 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 NonStrictExpectations (mockit.NonStrictExpectations)5 PersistenceManagerClient (com.haulmont.cuba.client.sys.PersistenceManagerClient)4 PersistenceManagerService (com.haulmont.cuba.core.app.PersistenceManagerService)4 AppBeans (com.haulmont.cuba.core.global.AppBeans)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 Mocked (mockit.Mocked)4 CollectionDatasourceImpl (com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl)2