Search in sources :

Example 16 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class AbstractEditor method postCommit.

/**
 * Hook to be implemented in subclasses. Called by the framework after committing datasources.
 * The default implementation notifies about commit and calls {@link #postInit()} if the window is not closing.
 *
 * @param committed whether any data were actually changed and committed
 * @param close     whether the window is going to be closed
 * @return true to continue, false to abort
 */
protected boolean postCommit(boolean committed, boolean close) {
    if (committed && !close) {
        if (showSaveNotification) {
            Entity entity = getItem();
            MetadataTools metadataTools = getApplicationContext().getBean(MetadataTools.class);
            showNotification(messages.formatMessage("", "info.EntitySave", messageTools.getEntityCaption(metadata.getClass(entity)), metadataTools.getInstanceName(entity)), NotificationType.TRAY);
        }
        postInit();
        afterWindowApplyPostInit();
    }
    return true;
}
Also used : Entity(io.jmix.core.Entity) MetadataTools(io.jmix.core.MetadataTools)

Example 17 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

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;
    if (!validateEditor()) {
        return;
    }
    getDsContext().commit();
    ListComponent table = getTable();
    CollectionDatasource browseDs = table.getDatasource();
    Entity editedItem = getFieldGroup().getDatasource().getItem();
    if (creating) {
        browseDs.includeItem(editedItem);
    } else {
        browseDs.updateItem(editedItem);
    }
    table.setSelected(editedItem);
    releaseLock();
    disableEditControls();
}
Also used : Entity(io.jmix.core.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 18 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

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);
            getApplicationContext().getBean(LockService.class).unlock(metaClass.getName(), EntityValues.getId(entity).toString());
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) AbstractDatasource(com.haulmont.cuba.gui.data.impl.AbstractDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(io.jmix.core.Entity) MetaClass(io.jmix.core.metamodel.model.MetaClass) LockService(com.haulmont.cuba.core.app.LockService)

Example 19 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

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(), null, editDs.getLoadDynamicAttributes());
        browseDs.setItem(reloadedItem);
    } else {
        editDs.setItem(null);
    }
    for (Datasource dataSource : getDsContext().getAll()) {
        if (AbstractDatasource.class.isAssignableFrom(dataSource.getClass())) {
            ((AbstractDatasource) dataSource).clearCommitLists();
        }
    }
    releaseLock();
    disableEditControls();
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) AbstractDatasource(com.haulmont.cuba.gui.data.impl.AbstractDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(io.jmix.core.Entity) AbstractDatasource(com.haulmont.cuba.gui.data.impl.AbstractDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 20 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

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(), null, e.getDs().getLoadDynamicAttributes());
            editDs.setItem(reloadedItem);
        }
    });
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) AbstractDatasource(com.haulmont.cuba.gui.data.impl.AbstractDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(io.jmix.core.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Aggregations

Entity (io.jmix.core.Entity)94 MetaClass (io.jmix.core.metamodel.model.MetaClass)20 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)18 CommitContext (com.haulmont.cuba.core.global.CommitContext)10 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)10 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 Test (org.junit.jupiter.api.Test)10 Server (com.haulmont.cuba.core.model.common.Server)8 Datasource (com.haulmont.cuba.gui.data.Datasource)8 Collectors (java.util.stream.Collectors)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 FetchPlan (io.jmix.core.FetchPlan)7 Logger (org.slf4j.Logger)7 Metadata (io.jmix.core.Metadata)6 MetadataTools (io.jmix.core.MetadataTools)6 EntityValues (io.jmix.core.entity.EntityValues)6 java.util (java.util)6 ArrayList (java.util.ArrayList)6 Nullable (javax.annotation.Nullable)6 LoggerFactory (org.slf4j.LoggerFactory)6