Search in sources :

Example 1 with EditorBuilder

use of io.jmix.ui.builder.EditorBuilder in project jmix by jmix-framework.

the class EditorScreenFacetImpl method createEditorBuilder.

@SuppressWarnings("unchecked")
protected EditorBuilder<E> createEditorBuilder(Frame owner, @Nullable E entityToEdit) {
    EditorBuilder<E> builder;
    ScreenBuilders screenBuilders = applicationContext.getBean(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 (entityPicker != null) {
        builder = screenBuilders.editor(entityPicker);
    } else {
        throw new IllegalStateException("Unable to create EditorScreenFacet. At least one of entityClass," + "listComponent or field must be specified");
    }
    if (editMode == EditMode.CREATE) {
        builder.newEntity(entityProvider != null ? entityToEdit : null);
    } 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(io.jmix.ui.builder.EditorBuilder) ScreenBuilders(io.jmix.ui.ScreenBuilders) DevelopmentException(io.jmix.core.DevelopmentException)

Example 2 with EditorBuilder

use of io.jmix.ui.builder.EditorBuilder 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();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EditorBuilder(io.jmix.ui.builder.EditorBuilder) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 3 with EditorBuilder

use of io.jmix.ui.builder.EditorBuilder 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();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EditorBuilder(io.jmix.ui.builder.EditorBuilder) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 4 with EditorBuilder

use of io.jmix.ui.builder.EditorBuilder in project jmix by jmix-framework.

the class EntityOpenAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
    if (!checkFieldValue())
        return;
    Object entity = entityPicker.getValue();
    if (entity != null && EntityValues.isSoftDeleted(entity)) {
        ScreenContext screenContext = ComponentsHelper.getScreenContext(entityPicker);
        Notifications notifications = screenContext.getNotifications();
        notifications.create(Notifications.NotificationType.HUMANIZED).withDescription(messages.getMessage("OpenAction.objectIsDeleted")).show();
        return;
    }
    MetaClass metaClass = entityPicker.getMetaClass();
    if (metaClass == null) {
        throw new DevelopmentException("Neither metaClass nor dataContainer/property is specified " + "for the EntityPicker", "action ID", getId());
    }
    EditorBuilder builder = screenBuilders.editor(entityPicker);
    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();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EditorBuilder(io.jmix.ui.builder.EditorBuilder) Notifications(io.jmix.ui.Notifications) DevelopmentException(io.jmix.core.DevelopmentException)

Example 5 with EditorBuilder

use of io.jmix.ui.builder.EditorBuilder 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();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EditorBuilder(io.jmix.ui.builder.EditorBuilder) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Aggregations

EditorBuilder (io.jmix.ui.builder.EditorBuilder)5 MetaClass (io.jmix.core.metamodel.model.MetaClass)4 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)3 DevelopmentException (io.jmix.core.DevelopmentException)2 Notifications (io.jmix.ui.Notifications)1 ScreenBuilders (io.jmix.ui.ScreenBuilders)1