Search in sources :

Example 1 with EntityDataUnit

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();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) MetaClass(com.haulmont.chile.core.model.MetaClass) EditorBuilder(com.haulmont.cuba.gui.builders.EditorBuilder) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit)

Example 2 with EntityDataUnit

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();
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit)

Example 3 with EntityDataUnit

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();
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit)

Example 4 with EntityDataUnit

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();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) MetaClass(com.haulmont.chile.core.model.MetaClass) EditorBuilder(com.haulmont.cuba.gui.builders.EditorBuilder) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit)

Example 5 with EntityDataUnit

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;
}
Also used : DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit)

Aggregations

EntityDataUnit (com.haulmont.cuba.gui.components.data.meta.EntityDataUnit)10 MetaClass (com.haulmont.chile.core.model.MetaClass)8 Entity (com.haulmont.cuba.core.entity.Entity)3 EditorBuilder (com.haulmont.cuba.gui.builders.EditorBuilder)3 DataUnit (com.haulmont.cuba.gui.components.data.DataUnit)2 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)2 BulkEditors (com.haulmont.cuba.gui.BulkEditors)1 Notifications (com.haulmont.cuba.gui.Notifications)1 Screens (com.haulmont.cuba.gui.Screens)1 MapScreenOptions (com.haulmont.cuba.gui.screen.MapScreenOptions)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1