Search in sources :

Example 16 with InstanceContainer

use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.

the class RemoveOperation method excludeItems.

@SuppressWarnings("unchecked")
protected <E extends Entity> void excludeItems(RemoveBuilder<E> builder, List<E> selectedItems) {
    CollectionContainer<E> container = getCollectionContainer(builder);
    if (!(container instanceof Nested)) {
        throw new IllegalArgumentException("Exclude action supports only Nested containers");
    }
    InstanceContainer masterDc = ((Nested) container).getMaster();
    String property = ((Nested) container).getProperty();
    Entity masterItem = masterDc.getItem();
    MetaProperty metaProperty = masterItem.getMetaClass().getPropertyNN(property);
    MetaProperty inverseMetaProperty = metaProperty.getInverse();
    if (inverseMetaProperty != null && !inverseMetaProperty.getRange().getCardinality().isMany()) {
        Class inversePropClass = extendedEntities.getEffectiveClass(inverseMetaProperty.getDomain());
        Class dcClass = extendedEntities.getEffectiveClass(container.getEntityMetaClass());
        if (inversePropClass.isAssignableFrom(dcClass)) {
            // update reference for One-To-Many
            for (Entity item : selectedItems) {
                item.setValue(inverseMetaProperty.getName(), null);
            }
        }
    }
    container.getMutableItems().removeAll(selectedItems);
    focusListComponent(builder);
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Nested(com.haulmont.cuba.gui.model.Nested) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 17 with InstanceContainer

use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.

the class CalendarLoader method loadDataContainer.

@SuppressWarnings("unchecked")
protected void loadDataContainer(Calendar component, Element element) {
    String containerId = element.attributeValue("dataContainer");
    FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
    ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
    InstanceContainer container = screenData.getContainer(containerId);
    if (!(container instanceof CollectionContainer)) {
        throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
    }
    component.setEventProvider(new ContainerCalendarEventProvider<>(((CollectionContainer) container)));
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Example 18 with InstanceContainer

use of com.haulmont.cuba.gui.model.InstanceContainer in project cuba by cuba-platform.

the class AbstractComponentLoader method loadOptionsContainer.

protected Optional<CollectionContainer> loadOptionsContainer(Element element) {
    String containerId = element.attributeValue("optionsContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        if (!(container instanceof CollectionContainer)) {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        return Optional.of((CollectionContainer) container);
    }
    return Optional.empty();
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData)

Aggregations

InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)18 ScreenData (com.haulmont.cuba.gui.model.ScreenData)9 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)8 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)8 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)7 MetaProperty (com.haulmont.chile.core.model.MetaProperty)6 MetaClass (com.haulmont.chile.core.model.MetaClass)5 Nested (com.haulmont.cuba.gui.model.Nested)5 Nullable (javax.annotation.Nullable)5 Entity (com.haulmont.cuba.core.entity.Entity)4 ContainerValueSource (com.haulmont.cuba.gui.components.data.value.ContainerValueSource)4 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 Datatype (com.haulmont.chile.core.datatypes.Datatype)2 com.haulmont.cuba.core.entity (com.haulmont.cuba.core.entity)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)2 Table (com.haulmont.cuba.gui.components.Table)2 GuiActionSupport (com.haulmont.cuba.gui.components.actions.GuiActionSupport)2