use of com.haulmont.cuba.core.entity.SoftDelete in project cuba by cuba-platform.
the class EntityRestoreServiceBean method restoreEntities.
@Override
public void restoreEntities(Collection<Entity> entities) {
for (Entity entity : entities) {
if (!(entity instanceof SoftDelete))
continue;
String storeName = metadata.getTools().getStoreName(metadata.getClassNN(entity.getClass()));
if (storeName == null) {
log.warn("Unable to restore entity {}: cannot determine data store", entity);
continue;
}
Transaction tx = persistence.createTransaction(storeName);
try {
persistence.getEntityManager(storeName).setSoftDeletion(false);
restoreEntity(entity, storeName);
tx.commit();
} finally {
tx.end();
}
}
}
use of com.haulmont.cuba.core.entity.SoftDelete in project cuba by cuba-platform.
the class WebEntityLinkField method openEntityEditor.
protected void openEntityEditor() {
Object value = getValue();
Entity entity;
if (value instanceof Entity) {
entity = (Entity) value;
} else {
entity = datasource.getItem();
}
if (entity == null) {
return;
}
WindowManager wm;
Window window = ComponentsHelper.getWindow(this);
if (window == null) {
throw new IllegalStateException("Please specify Frame for EntityLinkField");
} else {
wm = window.getWindowManager();
}
if (screenOpenType.getOpenMode() == OpenMode.DIALOG && screenDialogParams != null) {
wm.getDialogParams().copyFrom(screenDialogParams);
}
if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
Messages messages = AppBeans.get(Messages.NAME);
wm.showNotification(messages.getMainMessage("OpenAction.objectIsDeleted"), Frame.NotificationType.HUMANIZED);
return;
}
DataSupplier dataSupplier = window.getDsContext().getDataSupplier();
entity = dataSupplier.reload(entity, View.MINIMAL);
String windowAlias = screen;
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
if (windowAlias == null) {
windowAlias = windowConfig.getEditorScreenId(entity.getMetaClass());
}
final Window.Editor editor = wm.openEditor(windowConfig.getWindowInfo(windowAlias), entity, screenOpenType, screenParams != null ? screenParams : Collections.<String, Object>emptyMap());
editor.addCloseListener(actionId -> {
// move focus to component
component.focus();
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
Entity item = editor.getItem();
afterCommitOpenedEntity(item);
}
if (screenCloseListener != null) {
screenCloseListener.windowClosed(editor, actionId);
}
});
}
Aggregations