Search in sources :

Example 36 with CollectionDatasource

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

the class EntityCombinedScreen method initBrowseItemChangeListener.

/**
 * Adds a listener that reloads the selected record with the specified view and sets it to editDs.
 */
@SuppressWarnings("unchecked")
protected void initBrowseItemChangeListener() {
    CollectionDatasource browseDs = getTable().getDatasource();
    Datasource editDs = getFieldGroup().getDatasource();
    browseDs.addItemChangeListener(e -> {
        if (e.getItem() != null) {
            Entity reloadedItem = getDsContext().getDataSupplier().reload(e.getDs().getItem(), editDs.getView());
            editDs.setItem(reloadedItem);
        }
    });
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 37 with CollectionDatasource

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

the class EntityCombinedScreen method save.

/**
 * Method that is invoked by clicking Ok button after editing an existing or creating a new record.
 */
@SuppressWarnings("unchecked")
public void save() {
    if (!editing)
        return;
    FieldGroup fieldGroup = getFieldGroup();
    List<Validatable> components = new ArrayList<>();
    for (Component component : fieldGroup.getComponents()) {
        if (component instanceof Validatable) {
            components.add((Validatable) component);
        }
    }
    if (!validate(components)) {
        return;
    }
    getDsContext().commit();
    ListComponent table = getTable();
    CollectionDatasource browseDs = table.getDatasource();
    Entity editedItem = fieldGroup.getDatasource().getItem();
    if (creating) {
        browseDs.includeItem(editedItem);
    } else {
        browseDs.updateItem(editedItem);
    }
    table.setSelected(editedItem);
    releaseLock();
    disableEditControls();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 38 with CollectionDatasource

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

the class EntityCombinedScreen method initBrowseCreateAction.

/**
 * Adds a CreateAction that removes selection in table, sets a newly created item to editDs
 * and enables controls for record editing.
 */
protected void initBrowseCreateAction() {
    ListComponent table = getTable();
    table.addAction(new CreateAction(table) {

        @SuppressWarnings("unchecked")
        @Override
        protected void internalOpenEditor(CollectionDatasource datasource, Entity newItem, Datasource parentDs, Map<String, Object> params) {
            initNewItem(newItem);
            table.setSelected(Collections.emptyList());
            getFieldGroup().getDatasource().setItem(newItem);
            refreshOptionsForLookupFields();
            enableEditControls(true);
        }
    });
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) CreateAction(com.haulmont.cuba.gui.components.actions.CreateAction)

Example 39 with CollectionDatasource

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

the class AddAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null || target.getDatasource() == null) {
        return false;
    }
    CollectionDatasource ownerDs = target.getDatasource();
    if (ownerDs instanceof PropertyDatasource) {
        PropertyDatasource datasource = (PropertyDatasource) ownerDs;
        MetaClass parentMetaClass = datasource.getMaster().getMetaClass();
        MetaProperty metaProperty = datasource.getProperty();
        boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
        if (!attrPermitted) {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 40 with CollectionDatasource

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

the class RefreshAction method actionPerform.

/**
 * This method is invoked by action owner component. Don't override it, there are special methods to
 * customize behaviour below.
 *
 * @param component component invoking action
 */
@Override
public void actionPerform(Component component) {
    if (beforeRefreshHandler != null) {
        beforeRefreshHandler.run();
    }
    CollectionDatasource datasource = owner.getDatasource();
    Map<String, Object> refreshParams = getRefreshParams();
    Map<String, Object> supplierParams = null;
    if (refreshParamsSupplier != null) {
        supplierParams = refreshParamsSupplier.get();
    }
    Map<String, Object> params = null;
    if (supplierParams != null || refreshParams != null) {
        params = new HashMap<>();
        params.putAll(refreshParams != null ? refreshParams : Collections.emptyMap());
        params.putAll(supplierParams != null ? supplierParams : Collections.emptyMap());
    }
    if (params != null) {
        datasource.refresh(params);
    } else {
        datasource.refresh();
    }
    if (afterRefreshHandler != null) {
        afterRefreshHandler.run();
    }
}
Also used : CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Aggregations

CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)67 Datasource (com.haulmont.cuba.gui.data.Datasource)39 UUID (java.util.UUID)24 Group (com.haulmont.cuba.security.entity.Group)23 User (com.haulmont.cuba.security.entity.User)23 ArrayList (java.util.ArrayList)23 Ignore (org.junit.Ignore)23 Test (org.junit.Test)23 Component (com.haulmont.cuba.gui.components.Component)20 List (java.util.List)19 Assert.assertEquals (org.junit.Assert.assertEquals)19 Assert.assertTrue (org.junit.Assert.assertTrue)19 Entity (com.haulmont.cuba.core.entity.Entity)15 MetaClass (com.haulmont.chile.core.model.MetaClass)10 MetaProperty (com.haulmont.chile.core.model.MetaProperty)10 LookupField (com.haulmont.cuba.gui.components.LookupField)8 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)7 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)7 Element (org.dom4j.Element)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7