use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class BulkEditAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings("unchecked")
@Override
public void execute() {
if (!(target.getItems() instanceof EntityDataUnit)) {
throw new IllegalStateException("BulkEditAction target Items is null " + "or does not implement EntityDataUnit");
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
throw new IllegalStateException("Target is not bound to entity");
}
UiBulkEditContext context = new UiBulkEditContext();
accessManager.applyRegisteredConstraints(context);
if (!context.isPermitted()) {
if (target.getFrame() != null) {
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("accessDenied.message")).show();
}
return;
}
if (target.getSelected().isEmpty() && target.getFrame() != null) {
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("actions.BulkEdit.emptySelection")).show();
return;
}
Window window = ComponentsHelper.getWindowNN(target);
BulkEditorBuilder<?> builder = bulkEditors.builder(metaClass, target.getSelected(), window.getFrameOwner()).withListComponent(target);
if (columnsMode != null) {
builder = builder.withColumnsMode(columnsMode);
}
if (exclude != null) {
builder = builder.withExclude(exclude);
}
if (fieldSorter != null) {
builder = builder.withFieldSorter(fieldSorter);
}
if (includeProperties != null) {
builder = builder.withIncludeProperties(includeProperties);
}
if (openMode != null) {
builder = builder.withOpenMode(openMode);
}
if (useConfirmDialog != null) {
builder = builder.withUseConfirmDialog(useConfirmDialog);
}
builder.create().show();
}
use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class CreateAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings("unchecked")
@Override
public void execute() {
if (target == null) {
throw new IllegalStateException("CreateAction target is not set");
}
if (!(target.getItems() instanceof EntityDataUnit)) {
throw new IllegalStateException("CreateAction target items is null or does not implement EntityDataUnit");
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
throw new IllegalStateException("Target is not bound to entity");
}
EditorBuilder builder = screenBuilders.editor(target);
if (newEntitySupplier != null) {
E entity = newEntitySupplier.get();
builder = builder.newEntity(entity);
} else {
builder = builder.newEntity();
}
if (initializer != null) {
builder = builder.withInitializer(initializer);
}
builder = screenInitializer.initBuilder(builder);
if (transformation != null) {
builder.withTransformation(transformation);
}
Screen editor = builder.build();
if (afterCommitHandler != null) {
editor.addAfterCloseListener(afterCloseEvent -> {
CloseAction closeAction = afterCloseEvent.getCloseAction();
if (closeAction.equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
Object committedEntity = ((EditorScreen) editor).getEditedEntity();
afterCommitHandler.accept((E) committedEntity);
}
});
}
screenInitializer.initScreen(editor);
editor.show();
}
use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class CreateAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || !(target.getItems() instanceof EntityDataUnit)) {
return false;
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
return true;
}
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isCreatePermitted()) {
return false;
}
return super.isPermitted();
}
use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class EditAction method isDisabledWhenScreenReadOnly.
@Override
public boolean isDisabledWhenScreenReadOnly() {
if (!(target.getItems() instanceof EntityDataUnit)) {
return true;
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass != null) {
// Even though the screen is read-only, this edit action may remain active
// because the related entity cannot be edited and the corresponding edit screen
// will be opened in read-only mode either.
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
return entityContext.isEditPermitted();
}
return true;
}
use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class ViewAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
if (target == null) {
throw new IllegalStateException("ViewAction target is not set");
}
if (!(target.getItems() instanceof EntityDataUnit)) {
throw new IllegalStateException("ViewAction target dataSource is null or does not implement EntityDataUnit");
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
throw new IllegalStateException("Target is not bound to entity");
}
Object editedEntity = target.getSingleSelected();
if (editedEntity == null) {
throw new IllegalStateException("There is not selected item in ViewAction target");
}
EditorBuilder builder = screenBuilders.editor(target).editEntity(editedEntity);
builder = screenInitializer.initBuilder(builder);
if (transformation != null) {
builder.withTransformation(transformation);
}
Screen editor = builder.build();
if (afterCommitHandler != null) {
editor.addAfterCloseListener(afterCloseEvent -> {
CloseAction closeAction = afterCloseEvent.getCloseAction();
if (closeAction.equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
Object committedEntity = ((EditorScreen) editor).getEditedEntity();
afterCommitHandler.accept((E) committedEntity);
}
});
}
screenInitializer.initScreen(editor);
if (editor instanceof ReadOnlyAwareScreen) {
((ReadOnlyAwareScreen) editor).setReadOnly(true);
if (isReadOnlyCompositionEditor(editor)) {
readOnlyScreensSupport.setScreenReadOnly(editor, true, false);
}
} else {
throw new IllegalStateException(String.format("Screen '%s' does not implement ReadOnlyAwareScreen: %s", editor.getId(), editor.getClass()));
}
editor.show();
}
Aggregations