use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
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");
}
Entity 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)) {
Entity committedEntity = ((EditorScreen) editor).getEditedEntity();
afterCommitHandler.accept((E) committedEntity);
}
});
}
screenInitializer.initScreen(editor);
editor.show();
}
use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
the class EditAction 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;
}
boolean entityOpPermitted = security.isEntityOpPermitted(metaClass, EntityOp.READ);
if (!entityOpPermitted) {
return false;
}
return super.isPermitted();
}
use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
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;
}
boolean createPermitted = security.isEntityOpPermitted(metaClass, EntityOp.CREATE);
if (!createPermitted) {
return false;
}
return super.isPermitted();
}
use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
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)) {
Entity committedEntity = ((EditorScreen) editor).getEditedEntity();
afterCommitHandler.accept((E) committedEntity);
}
});
}
screenInitializer.initScreen(editor);
editor.show();
}
use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.
the class ScreenBuilders method lookup.
/**
* Creates a screen builder using list component.
* <p>
* Example of building a lookup screen for adding row to table / tree component:
* <pre>{@code
* SomeCustomerListScreen screen = screenBuilders.lookup(customersTable)
* .withScreen(SomeCustomerListScreen.class)
* .build();
* }</pre>
*
* @param listComponent {@link Table}, {@link DataGrid} or another component containing the list of entities
* @param <E> type of entity
* @see #lookup(Class, FrameOwner)
*/
public <E extends Entity> LookupBuilder<E> lookup(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));
}
LookupBuilder<E> builder = new LookupBuilder<>(frameOwner, entityClass, lookupBuilderProcessor::buildLookup);
builder.withListComponent(listComponent);
return builder;
}
Aggregations