Search in sources :

Example 6 with EntityDataUnit

use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.

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 extends Entity> 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;
}
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)

Example 7 with EntityDataUnit

use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.

the class ViewAction 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 8 with EntityDataUnit

use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit 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 9 with EntityDataUnit

use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.

the class BulkEditAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    if (!(target.getItems() instanceof EntityDataUnit)) {
        throw new IllegalStateException("BulkEditAction 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");
    }
    if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
        Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
        notifications.create(NotificationType.ERROR).withCaption(messages.getMainMessage("accessDenied.message")).show();
        return;
    }
    if (target.getSelected().isEmpty()) {
        Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
        notifications.create(NotificationType.ERROR).withCaption(messages.getMainMessage("actions.BulkEdit.emptySelection")).show();
        return;
    }
    Window window = ComponentsHelper.getWindowNN(target);
    BulkEditors.EditorBuilder builder = bulkEditors.builder(metaClass, target.getSelected(), window.getFrameOwner()).withListComponent(target);
    if (columnsMode != null) {
        builder = builder.withColumnsMode(columnsMode);
    }
    if (exclude != null) {
        builder = builder.withExclude(exclude);
    }
    if (fieldSorter != null) {
        builder = builder.withFieldSorter(fieldSorter);
    }
    if (includeProperties != null) {
        builder = builder.withIncludeProperties(includeProperties);
    }
    if (openMode != null) {
        builder = builder.withLaunchMode(openMode);
    }
    if (loadDynamicAttributes != null) {
        builder = builder.withLoadDynamicAttributes(loadDynamicAttributes);
    }
    if (useConfirmDialog != null) {
        builder = builder.withUseConfirmDialog(useConfirmDialog);
    }
    builder.create().show();
}
Also used : BulkEditors(com.haulmont.cuba.gui.BulkEditors) MetaClass(com.haulmont.chile.core.model.MetaClass) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit) Notifications(com.haulmont.cuba.gui.Notifications)

Example 10 with EntityDataUnit

use of com.haulmont.cuba.gui.components.data.meta.EntityDataUnit in project cuba by cuba-platform.

the class AddToSetAction method actionPerform.

@Override
public void actionPerform(Component component) {
    MetaClass entityMetaClass;
    if (target.getItems() instanceof EntityDataUnit) {
        entityMetaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
    } else {
        throw new UnsupportedOperationException("Unsupported data unit " + target.getItems());
    }
    String query;
    if (filter.getDatasource() != null) {
        query = filter.getDatasource().getQuery();
    } else {
        query = filter.getDataLoader().getQuery();
    }
    String[] strings = ValuePathHelper.parse(ComponentsHelper.getFilterComponentPath(filter));
    String componentId = ValuePathHelper.pathSuffix(strings);
    Set ownerSelection = target.getSelected();
    Map<String, Object> params = new HashMap<>();
    params.put("entityType", entityMetaClass.getName());
    params.put("items", ownerSelection);
    params.put("componentPath", ComponentsHelper.getFilterComponentPath(filter));
    params.put("componentId", componentId);
    params.put("foldersPane", filterHelper.getFoldersPane());
    params.put("entityClass", entityMetaClass.getJavaClass().getName());
    params.put("query", query);
    Screens screens = ComponentsHelper.getScreenContext(filter).getScreens();
    screens.create("saveSetInFolder", OpenMode.DIALOG, new MapScreenOptions(params)).show();
}
Also used : Set(java.util.Set) MetaClass(com.haulmont.chile.core.model.MetaClass) HashMap(java.util.HashMap) EntityDataUnit(com.haulmont.cuba.gui.components.data.meta.EntityDataUnit) MapScreenOptions(com.haulmont.cuba.gui.screen.MapScreenOptions) Screens(com.haulmont.cuba.gui.Screens)

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