use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.
the class EditorWindowDelegate method validateAdditionalRules.
public void validateAdditionalRules(ValidationErrors errors) {
// all previous validations return no errors
if (crossFieldValidate && errors.isEmpty()) {
BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
Validator validator = beanValidation.getValidator();
Set<ConstraintViolation<Entity>> violations = validator.validate(getItem(), UiCrossFieldChecks.class);
violations.stream().filter(violation -> {
Path propertyPath = violation.getPropertyPath();
Path.Node lastNode = Iterables.getLast(propertyPath);
return lastNode.getKind() == ElementKind.BEAN;
}).forEach(violation -> errors.add(violation.getMessage()));
}
}
use of com.haulmont.cuba.core.entity.Entity 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();
}
});
}
use of com.haulmont.cuba.core.entity.Entity 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());
}
}
}
use of com.haulmont.cuba.core.entity.Entity 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();
}
use of com.haulmont.cuba.core.entity.Entity in project cuba by cuba-platform.
the class EditAction method internalOpenEditor.
protected void internalOpenEditor(CollectionDatasource datasource, Entity existingItem, Datasource parentDs, Map<String, Object> params) {
Window.Editor window = target.getFrame().openEditor(getWindowId(), existingItem, getOpenType(), params, parentDs);
if (editorCloseListener == null) {
window.addCloseListener(actionId -> {
// move focus to owner
target.requestFocus();
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
Entity editedItem = window.getItem();
if (editedItem != null) {
if (parentDs == null) {
if (editedItem instanceof BaseGenericIdEntity) {
BaseGenericIdEntity genericEditedEntity = (BaseGenericIdEntity) editedItem;
if (datasource.getLoadDynamicAttributes() && genericEditedEntity.getDynamicAttributes() == null) {
DynamicAttributesGuiTools dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.class);
dynamicAttributesGuiTools.reloadDynamicAttributes(genericEditedEntity);
}
}
// noinspection unchecked
datasource.updateItem(editedItem);
}
afterCommit(editedItem);
if (afterCommitHandler != null) {
afterCommitHandler.handle(editedItem);
}
}
}
afterWindowClosed(window);
if (afterWindowClosedHandler != null) {
afterWindowClosedHandler.handle(window, actionId);
}
});
} else {
window.addCloseListener(editorCloseListener);
}
}
Aggregations