Search in sources :

Example 61 with Datasource

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

the class PropertyWrapper method unsubscribe.

@SuppressWarnings("unchecked")
@Override
public void unsubscribe() {
    Datasource datasource = (Datasource) item;
    datasource.removeItemChangeListener(weakItemChangeListener);
    weakItemChangeListener = null;
    datasource.removeItemPropertyChangeListener(weakItemPropertyChangeListener);
    weakItemPropertyChangeListener = null;
    propertyPath = null;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource)

Example 62 with Datasource

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

the class ManagedBeanAttributeDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    data.clear();
    Datasource mbeanDs = getDsContext().get("mbeanDs");
    ManagedBeanInfo mbean = (ManagedBeanInfo) mbeanDs.getItem();
    if (mbean != null) {
        try {
            jmxControlAPI.loadAttributes(mbean);
        } catch (JmxControlException e) {
            log.error("Error loading attributes", e);
        }
        if (mbean.getAttributes() != null) {
            for (ManagedBeanAttribute attr : mbean.getAttributes()) {
                data.put(attr.getId(), attr);
            }
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) ManagedBeanAttribute(com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Example 63 with Datasource

use of com.haulmont.cuba.gui.data.Datasource 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 64 with Datasource

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

the class CheckBoxDsTest method testUnsubscribeSubscribeDsListener.

@Test
public void testUnsubscribeSubscribeDsListener() {
    CheckBox checkBox = (CheckBox) factory.createComponent(CheckBox.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setActive(true);
    checkBox.setDatasource(userDs, "active");
    // unbind
    checkBox.setDatasource(null, null);
    // setup
    boolean[] valueWasChanged = { false };
    Datasource.ItemPropertyChangeListener<User> listener = e -> valueWasChanged[0] = true;
    userDs.addItemPropertyChangeListener(listener);
    checkBox.setDatasource(userDs, "active");
    checkBox.setValue(false);
    assertEquals(true, valueWasChanged[0]);
    assertEquals(false, user.getActive());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CheckBox(com.haulmont.cuba.gui.components.CheckBox) 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) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Test(org.junit.Test)

Example 65 with Datasource

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

the class CheckBoxDsTest method testUnsubscribeComponentListener.

@Test
public void testUnsubscribeComponentListener() {
    CheckBox checkBox = (CheckBox) factory.createComponent(CheckBox.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setActive(true);
    checkBox.setDatasource(userDs, "active");
    // unbind
    checkBox.setDatasource(null, null);
    Component.ValueChangeListener valueChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    checkBox.addValueChangeListener(valueChangeListener);
    user.setActive(false);
    assertEquals(true, checkBox.getValue());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CheckBox(com.haulmont.cuba.gui.components.CheckBox) 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) CheckBox(com.haulmont.cuba.gui.components.CheckBox) 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