Search in sources :

Example 1 with EditorBuilder

use of com.haulmont.cuba.gui.builders.EditorBuilder 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 EditorBuilder

use of com.haulmont.cuba.gui.builders.EditorBuilder 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 3 with EditorBuilder

use of com.haulmont.cuba.gui.builders.EditorBuilder in project cuba by cuba-platform.

the class WebEditorScreenFacet method createEditorBuilder.

@SuppressWarnings("unchecked")
protected EditorBuilder<E> createEditorBuilder(Frame owner, @Nullable E entityToEdit) {
    EditorBuilder<E> builder;
    ScreenBuilders screenBuilders = beanLocator.get(ScreenBuilders.class);
    if (entityClass != null) {
        builder = screenBuilders.editor(entityClass, owner.getFrameOwner());
    } else if (entityToEdit != null) {
        builder = (EditorBuilder<E>) screenBuilders.editor(entityToEdit.getClass(), owner.getFrameOwner());
    } else if (listComponent != null) {
        builder = screenBuilders.editor(listComponent);
    } else if (pickerField != null) {
        builder = screenBuilders.editor(pickerField);
    } else {
        throw new IllegalStateException("Unable to create EditorScreen Facet. At least one of entityClass, listComponent or field must be specified");
    }
    if (editMode == EditMode.CREATE) {
        builder.newEntity(entityToEdit);
    } else {
        if (entityToEdit != null) {
            builder.editEntity(entityToEdit);
        } else {
            throw new DevelopmentException("No entity to edit is passed for EditorScreen");
        }
    }
    if (screenClass != null) {
        builder = builder.withScreenClass(screenClass);
    } else {
        builder.withScreenId(screenId);
    }
    return builder;
}
Also used : EditorBuilder(com.haulmont.cuba.gui.builders.EditorBuilder) ScreenBuilders(com.haulmont.cuba.gui.ScreenBuilders) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 4 with EditorBuilder

use of com.haulmont.cuba.gui.builders.EditorBuilder in project cuba by cuba-platform.

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");
    }
    Entity 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)) {
                Entity committedEntity = ((EditorScreen) editor).getEditedEntity();
                afterCommitHandler.accept((E) committedEntity);
            }
        });
    }
    screenInitializer.initScreen(editor);
    if (editor instanceof ReadOnlyAwareScreen) {
        ((ReadOnlyAwareScreen) editor).setReadOnly(true);
    } else {
        throw new IllegalStateException(String.format("Screen '%s' does not implement ReadOnlyAwareScreen: %s", editor.getId(), editor.getClass()));
    }
    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 EditorBuilder

use of com.haulmont.cuba.gui.builders.EditorBuilder in project cuba by cuba-platform.

the class OpenAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
    if (!checkFieldValue())
        return;
    Entity entity = pickerField.getValue();
    if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
        ScreenContext screenContext = ComponentsHelper.getScreenContext(pickerField);
        Notifications notifications = screenContext.getNotifications();
        notifications.create(NotificationType.HUMANIZED).withDescription(messages.getMainMessage("OpenAction.objectIsDeleted")).show();
        return;
    }
    MetaClass metaClass = pickerField.getMetaClass();
    if (metaClass == null) {
        throw new DevelopmentException("Neither metaClass nor datasource/property is specified " + "for the PickerField", "action ID", getId());
    }
    EditorBuilder builder = screenBuilders.editor(pickerField);
    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) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) MetaClass(com.haulmont.chile.core.model.MetaClass) EditorBuilder(com.haulmont.cuba.gui.builders.EditorBuilder) Notifications(com.haulmont.cuba.gui.Notifications) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Aggregations

EditorBuilder (com.haulmont.cuba.gui.builders.EditorBuilder)5 MetaClass (com.haulmont.chile.core.model.MetaClass)4 Entity (com.haulmont.cuba.core.entity.Entity)4 EntityDataUnit (com.haulmont.cuba.gui.components.data.meta.EntityDataUnit)3 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)2 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)1 Notifications (com.haulmont.cuba.gui.Notifications)1 ScreenBuilders (com.haulmont.cuba.gui.ScreenBuilders)1