use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class ScreenBuilders method editor.
/**
* Creates a screen builder using list component.
* <p>
* Example of building a screen for editing a currently selected entity:
* <pre>{@code
* SomeCustomerEditor screen = screenBuilders.editor(customersTable)
* .withScreen(SomeCustomerEditor.class)
* .build();
* }</pre>
* <p>
* Example of building a screen for creating a new entity instance:
* <pre>{@code
* SomeCustomerEditor screen = screenBuilders.editor(customersTable)
* .withScreen(SomeCustomerEditor.class)
* .newEntity()
* .build();
* }</pre>
*
* @param listComponent {@link Table}, {@link DataGrid} or another component containing the list of entities
* @see #editor(Class, FrameOwner)
*/
public <E> EditorBuilder<E> editor(ListComponent<E> listComponent) {
checkNotNullArgument(listComponent);
checkNotNullArgument(listComponent.getFrame());
FrameOwner frameOwner = listComponent.getFrame().getFrameOwner();
Class<E> entityClass;
DataUnit items = listComponent.getItems();
if (items instanceof EntityDataUnit) {
entityClass = ((EntityDataUnit) items).getEntityMetaClass().getJavaClass();
} else {
throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent));
}
EditorBuilder<E> builder = new EditorBuilder<>(frameOwner, entityClass, editorBuilderProcessor::buildEditor);
builder.withListComponent(listComponent);
builder.editEntity(listComponent.getSingleSelected());
return builder;
}
use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class ExecutionHistoryAction method actionPerform.
@Override
public void actionPerform(Component component) {
if (target != null && target.getFrame() != null) {
MetaClass metaClass = null;
DataUnit items = target.getItems();
if (items instanceof EntityDataUnit) {
metaClass = ((EntityDataUnit) items).getEntityMetaClass();
}
openLookup(target.getFrame().getFrameOwner(), metaClass);
} else if (component instanceof Component.BelongToFrame) {
FrameOwner screen = ComponentsHelper.getWindowNN((Component.BelongToFrame) component).getFrameOwner();
openLookup(screen, null);
} else {
throw new IllegalStateException("No target screen or component found for 'ExecutionHistoryAction'");
}
}
use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class ResetPasswordAction 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.isEditPermitted()) {
return false;
}
return super.isPermitted();
}
use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class EditAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
if (target == null) {
throw new IllegalStateException("EditAction target is not set");
}
if (!(target.getItems() instanceof EntityDataUnit)) {
throw new IllegalStateException("EditAction 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 EditAction 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);
editor.show();
}
use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.
the class EditAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || target.getSingleSelected() == 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);
InMemoryCrudEntityContext inMemoryCrudEntityContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
accessManager.applyRegisteredConstraints(inMemoryCrudEntityContext);
if (!entityContext.isViewPermitted() && !entityContext.isEditPermitted()) {
return false;
}
if (inMemoryCrudEntityContext.updatePredicate() != null) {
return true;
}
return super.isPermitted();
}
Aggregations