Search in sources :

Example 1 with DataUnit

use of io.jmix.ui.component.data.DataUnit in project jmix by jmix-framework.

the class ViewAction method isReadOnlyCompositionEditor.

/**
 * In case of composition relation, editor for nested entities should be in read-only mode with hidden
 * "enableEditing" action if master editor is in read-only mode too.
 *
 * @param editor editor to check
 * @return {@code true} if the relation between entities is a composition
 */
protected boolean isReadOnlyCompositionEditor(Screen editor) {
    Frame frame = target.getFrame();
    if (frame == null) {
        throw new IllegalStateException("Component is not attached to the Frame");
    }
    FrameOwner origin = target.getFrame().getFrameOwner();
    if (!(origin instanceof ReadOnlyAwareScreen) || !((ReadOnlyAwareScreen) origin).isReadOnly() || !(editor instanceof StandardEditor)) {
        return false;
    }
    DataUnit items = target.getItems();
    if (!(items instanceof ContainerDataUnit)) {
        return false;
    }
    CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
    if (!(container instanceof CollectionPropertyContainer)) {
        return false;
    }
    InstanceContainer masterContainer = ((CollectionPropertyContainer) container).getMaster();
    String property = ((CollectionPropertyContainer) container).getProperty();
    MetaClass metaClass = masterContainer.getEntityMetaClass();
    MetaProperty metaProperty = metaClass.getProperty(property);
    return metaProperty.getType() == MetaProperty.Type.COMPOSITION;
}
Also used : Frame(io.jmix.ui.component.Frame) CollectionContainer(io.jmix.ui.model.CollectionContainer) InstanceContainer(io.jmix.ui.model.InstanceContainer) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) MetaClass(io.jmix.core.metamodel.model.MetaClass) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) CollectionPropertyContainer(io.jmix.ui.model.CollectionPropertyContainer)

Example 2 with DataUnit

use of io.jmix.ui.component.data.DataUnit in project jmix by jmix-framework.

the class AbstractDataGrid method setupPaginationDataSourceProvider.

public void setupPaginationDataSourceProvider() {
    if (pagination == null) {
        return;
    }
    DataUnit items = getItems();
    PaginationDataBinder provider;
    if (items instanceof ContainerDataUnit) {
        provider = applicationContext.getBean(PaginationDataUnitBinder.class, items);
    } else if (items instanceof EmptyDataUnit && items instanceof EntityDataUnit) {
        provider = new PaginationEmptyBinder(((EntityDataUnit) items).getEntityMetaClass());
    } else {
        throw new IllegalStateException("Unsupported data unit type: " + items);
    }
    pagination.setDataBinder(provider);
}
Also used : PaginationDataUnitBinder(io.jmix.ui.component.pagination.data.PaginationDataUnitBinder) PaginationEmptyBinder(io.jmix.ui.component.pagination.data.PaginationEmptyBinder) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) PaginationDataBinder(io.jmix.ui.component.pagination.data.PaginationDataBinder) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 3 with DataUnit

use of io.jmix.ui.component.data.DataUnit in project jmix by jmix-framework.

the class RemoveOperation method builder.

/**
 * Creates a remove builder using list component, e.g. {@link Table} or {@link DataGrid}.
 *
 * @param listComponent list component
 * @param <E>           type of entity
 */
public <E> RemoveBuilder<E> builder(ListComponent<E> listComponent) {
    checkNotNullArgument(listComponent);
    checkNotNullArgument(listComponent.getFrame());
    FrameOwner frameOwner = listComponent.getFrame().getFrameOwner();
    Class<E> entityClass;
    DataUnit items = listComponent.getItems();
    if (items instanceof ContainerDataUnit) {
        entityClass = ((ContainerDataUnit) items).getEntityMetaClass().getJavaClass();
    } else {
        throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent));
    }
    return builder(entityClass, frameOwner).withListComponent(listComponent);
}
Also used : ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) FrameOwner(io.jmix.ui.screen.FrameOwner) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 4 with DataUnit

use of io.jmix.ui.component.data.DataUnit in project jmix by jmix-framework.

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> 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 : EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) FrameOwner(io.jmix.ui.screen.FrameOwner) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 5 with DataUnit

use of io.jmix.ui.component.data.DataUnit in project jmix by jmix-framework.

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> 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 : EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) FrameOwner(io.jmix.ui.screen.FrameOwner) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Aggregations

DataUnit (io.jmix.ui.component.data.DataUnit)10 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)6 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)6 FrameOwner (io.jmix.ui.screen.FrameOwner)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 EmptyDataUnit (io.jmix.ui.component.data.meta.EmptyDataUnit)2 PaginationDataBinder (io.jmix.ui.component.pagination.data.PaginationDataBinder)2 PaginationDataUnitBinder (io.jmix.ui.component.pagination.data.PaginationDataUnitBinder)2 PaginationEmptyBinder (io.jmix.ui.component.pagination.data.PaginationEmptyBinder)2 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 Widget (io.jmix.dashboards.model.Widget)1 ItemsSelectedEvent (io.jmix.dashboardsui.event.ItemsSelectedEvent)1 LookupWidget (io.jmix.dashboardsui.widget.LookupWidget)1 RefreshableWidget (io.jmix.dashboardsui.widget.RefreshableWidget)1 OrderableEntity (io.jmix.reports.entity.wizard.OrderableEntity)1 Screens (io.jmix.ui.Screens)1 io.jmix.ui.component (io.jmix.ui.component)1 Component (io.jmix.ui.component.Component)1 Frame (io.jmix.ui.component.Frame)1 HasValueSource (io.jmix.ui.component.data.HasValueSource)1