Search in sources :

Example 41 with Datasource

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

the class EntityCombinedScreen method initBrowseEditAction.

/**
 * Adds an EditAction that enables controls for editing.
 */
protected void initBrowseEditAction() {
    ListComponent table = getTable();
    table.addAction(new EditAction(table) {

        @Override
        public void actionPerform(Component component) {
            if (table.getSelected().size() == 1) {
                if (lockIfNeeded((Entity) table.getSelected().iterator().next())) {
                    super.actionPerform(component);
                }
            }
        }

        @Override
        protected void internalOpenEditor(CollectionDatasource datasource, Entity existingItem, Datasource parentDs, Map<String, Object> params) {
            refreshOptionsForLookupFields();
            enableEditControls(false);
        }

        @Override
        public void refreshState() {
            if (target != null) {
                CollectionDatasource ds = target.getDatasource();
                if (ds != null && !captionInitialized) {
                    setCaption(messages.getMainMessage("actions.Edit"));
                }
            }
            super.refreshState();
        }

        @Override
        protected boolean isPermitted() {
            CollectionDatasource ownerDatasource = target.getDatasource();
            boolean entityOpPermitted = security.isEntityOpPermitted(ownerDatasource.getMetaClass(), EntityOp.UPDATE);
            if (!entityOpPermitted) {
                return false;
            }
            return super.isPermitted();
        }
    });
}
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) EditAction(com.haulmont.cuba.gui.components.actions.EditAction)

Example 42 with Datasource

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

the class EntityCombinedScreen method releaseLock.

/**
 * Release pessimistic lock if it was applied.
 */
protected void releaseLock() {
    if (justLocked) {
        Datasource ds = getFieldGroup().getDatasource();
        Entity entity = ds.getItem();
        if (entity != null) {
            MetaClass metaClass = getMetaClassForLocking(entity);
            AppBeans.get(LockService.class).unlock(metaClass.getName(), entity.getId().toString());
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(com.haulmont.cuba.core.entity.Entity) MetaClass(com.haulmont.chile.core.model.MetaClass) LockService(com.haulmont.cuba.core.app.LockService)

Example 43 with Datasource

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

the class EntityCombinedScreen method initBrowseRemoveAction.

/**
 * Adds AfterRemoveHandler for table's Remove action to reset the record contained in editDs.
 */
@SuppressWarnings("unchecked")
protected void initBrowseRemoveAction() {
    ListComponent table = getTable();
    Datasource editDs = getFieldGroup().getDatasource();
    RemoveAction removeAction = (RemoveAction) table.getAction(RemoveAction.ACTION_ID);
    if (removeAction != null)
        removeAction.setAfterRemoveHandler(removedItems -> editDs.setItem(null));
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) java.util(java.util) Datasource(com.haulmont.cuba.gui.data.Datasource) LockService(com.haulmont.cuba.core.app.LockService) EditAction(com.haulmont.cuba.gui.components.actions.EditAction) MetaClass(com.haulmont.chile.core.model.MetaClass) RemoveAction(com.haulmont.cuba.gui.components.actions.RemoveAction) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) CreateAction(com.haulmont.cuba.gui.components.actions.CreateAction) EntityOp(com.haulmont.cuba.security.entity.EntityOp) ComponentsHelper(com.haulmont.cuba.gui.ComponentsHelper) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Nullable(javax.annotation.Nullable) Entity(com.haulmont.cuba.core.entity.Entity) RemoveAction(com.haulmont.cuba.gui.components.actions.RemoveAction)

Example 44 with Datasource

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

the class EntityCombinedScreen method cancel.

/**
 * Method that is invoked by clicking Cancel button, discards changes and disables controls for editing.
 */
@SuppressWarnings("unchecked")
public void cancel() {
    CollectionDatasource browseDs = getTable().getDatasource();
    Datasource editDs = getFieldGroup().getDatasource();
    Entity selectedItem = browseDs.getItem();
    if (selectedItem != null) {
        Entity reloadedItem = getDsContext().getDataSupplier().reload(selectedItem, editDs.getView());
        browseDs.setItem(reloadedItem);
    } else {
        editDs.setItem(null);
    }
    releaseLock();
    disableEditControls();
}
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 45 with Datasource

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

the class WindowDelegate method getDatasource.

public Datasource getDatasource() {
    Datasource ds = null;
    Element element = ((Component.HasXmlDescriptor) window).getXmlDescriptor();
    String datasourceName = element.attributeValue("datasource");
    if (!StringUtils.isEmpty(datasourceName)) {
        DsContext context = window.getDsContext();
        if (context != null) {
            ds = context.get(datasourceName);
        }
    }
    if (ds == null) {
        throw new GuiDevelopmentException("Can't find main datasource", window.getId());
    }
    return ds;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) DsContext(com.haulmont.cuba.gui.data.DsContext) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

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