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;
}
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();
}
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());
}
}
}
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();
}
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);
}
});
}
Aggregations