Search in sources :

Example 1 with CollectionContainer

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

the class InputDialog method createEntityField.

@SuppressWarnings("unchecked")
protected Field createEntityField(InputParameter parameter) {
    MetaClass metaClass = metadata.getClassNN(parameter.getEntityClass());
    Action lookupAction = actions.create(LookupAction.ID);
    Action clearAction = actions.create(ClearAction.ID);
    if (persistenceManagerService.useLookupScreen(metaClass.getName())) {
        PickerField pickerField = uiComponents.create(PickerField.NAME);
        pickerField.setMetaClass(metadata.getClass(parameter.getEntityClass()));
        pickerField.addAction(lookupAction);
        pickerField.addAction(clearAction);
        pickerField.setWidthFull();
        return pickerField;
    } else {
        LookupPickerField lookupPickerField = uiComponents.create(LookupPickerField.NAME);
        lookupPickerField.addAction(lookupAction);
        lookupPickerField.addAction(clearAction);
        lookupPickerField.setWidthFull();
        CollectionContainer container = dataComponents.createCollectionContainer(parameter.getEntityClass());
        CollectionLoader loader = dataComponents.createCollectionLoader();
        loader.setQuery("select e from " + metaClass.getName() + " e");
        loader.setView(View.MINIMAL);
        loader.setContainer(container);
        loader.load();
        lookupPickerField.setOptions(new ContainerOptions(container));
        return lookupPickerField;
    }
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) ClearAction(com.haulmont.cuba.gui.actions.picker.ClearAction) InputDialogAction(com.haulmont.cuba.gui.components.inputdialog.InputDialogAction) CollectionLoader(com.haulmont.cuba.gui.model.CollectionLoader) MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer)

Example 2 with CollectionContainer

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

the class RefreshAction method execute.

/**
 * Executes the action.
 */
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("RefreshAction target is not set");
    }
    if (target.getItems() instanceof EmptyDataUnit) {
        return;
    }
    if (!(target.getItems() instanceof ContainerDataUnit)) {
        throw new IllegalStateException("RefreshAction target is null or does not implement SupportsContainerBinding");
    }
    CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
    if (container == null) {
        throw new IllegalStateException("RefreshAction target is not bound to CollectionContainer");
    }
    DataLoader loader = null;
    if (container instanceof HasLoader) {
        loader = ((HasLoader) container).getLoader();
    }
    if (loader != null) {
        DataContext dataContext = loader.getDataContext();
        if (dataContext != null) {
            for (Object entity : container.getItems()) {
                dataContext.evict((Entity) entity);
            }
        }
        loader.load();
    } else {
        log.warn("RefreshAction '{}' target container has no loader, refresh is impossible", getId());
    }
}
Also used : DataLoader(com.haulmont.cuba.gui.model.DataLoader) DataContext(com.haulmont.cuba.gui.model.DataContext) EmptyDataUnit(com.haulmont.cuba.gui.components.data.meta.EmptyDataUnit) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) HasLoader(com.haulmont.cuba.gui.model.HasLoader) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 3 with CollectionContainer

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

the class RemoveOperation method commitIfNeeded.

protected void commitIfNeeded(Collection<? extends Entity> entitiesToRemove, CollectionContainer container, ScreenData screenData) {
    List<? extends Entity> entitiesToCommit = entitiesToRemove.stream().filter(entity -> !entityStates.isNew(entity)).collect(Collectors.toList());
    boolean needCommit = !entitiesToCommit.isEmpty();
    if (container instanceof Nested) {
        InstanceContainer masterContainer = ((Nested) container).getMaster();
        String property = ((Nested) container).getProperty();
        MetaClass masterMetaClass = masterContainer.getEntityMetaClass();
        MetaProperty metaProperty = masterMetaClass.getPropertyNN(property);
        needCommit = needCommit && (metaProperty.getType() != MetaProperty.Type.COMPOSITION);
    }
    if (needCommit) {
        CommitContext commitContext = new CommitContext();
        for (Entity entity : entitiesToCommit) {
            commitContext.addInstanceToRemove(entity);
        }
        dataManager.commit(commitContext);
        for (Entity entity : entitiesToRemove) {
            screenData.getDataContext().evict(entity);
        }
    } else {
        for (Entity entity : entitiesToRemove) {
            screenData.getDataContext().remove(entity);
        }
    }
}
Also used : ListComponent(com.haulmont.cuba.gui.components.ListComponent) UiControllerUtils.getScreenContext(com.haulmont.cuba.gui.screen.UiControllerUtils.getScreenContext) java.util(java.util) DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Table(com.haulmont.cuba.gui.components.Table) ScreenData(com.haulmont.cuba.gui.model.ScreenData) Focusable(com.haulmont.cuba.gui.components.Component.Focusable) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) Collectors(java.util.stream.Collectors) MetaClass(com.haulmont.chile.core.model.MetaClass) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) Component(org.springframework.stereotype.Component) Nested(com.haulmont.cuba.gui.model.Nested) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) com.haulmont.cuba.gui.screen(com.haulmont.cuba.gui.screen) DataGrid(com.haulmont.cuba.gui.components.DataGrid) DialogAction(com.haulmont.cuba.gui.components.DialogAction) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) Entity(com.haulmont.cuba.core.entity.Entity) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) Entity(com.haulmont.cuba.core.entity.Entity) MetaClass(com.haulmont.chile.core.model.MetaClass) Nested(com.haulmont.cuba.gui.model.Nested) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 4 with CollectionContainer

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

the class TwinColumnLoader method loadOptionsContainer.

protected void loadOptionsContainer(TwinColumn component, 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);
        }
        // noinspection unchecked
        component.setOptions(new ContainerOptions((CollectionContainer) container));
    }
}
Also used : ContainerOptions(com.haulmont.cuba.gui.components.data.options.ContainerOptions) 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 5 with CollectionContainer

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

the class WebTableFieldFactory method findOptionsContainer.

@Nullable
protected CollectionContainer findOptionsContainer(Table.Column columnConf) {
    String optDcName = columnConf.getXmlDescriptor() != null ? columnConf.getXmlDescriptor().attributeValue("optionsContainer") : null;
    if (Strings.isNullOrEmpty(optDcName)) {
        return null;
    } else {
        ScreenData screenData = UiControllerUtils.getScreenData(webTable.getFrame().getFrameOwner());
        InstanceContainer container = screenData.getContainer(optDcName);
        if (container instanceof CollectionContainer) {
            return (CollectionContainer) container;
        }
        throw new IllegalStateException(String.format("'%s' is not an instance of CollectionContainer", optDcName));
    }
}
Also used : InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData) Nullable(javax.annotation.Nullable)

Aggregations

CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)13 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)8 ScreenData (com.haulmont.cuba.gui.model.ScreenData)8 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)6 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)6 ContainerOptions (com.haulmont.cuba.gui.components.data.options.ContainerOptions)5 MetaClass (com.haulmont.chile.core.model.MetaClass)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)3 ContainerDataUnit (com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)3 Nullable (javax.annotation.Nullable)3 Entity (com.haulmont.cuba.core.entity.Entity)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 Table (com.haulmont.cuba.gui.components.Table)2 Element (org.dom4j.Element)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 EventHub (com.haulmont.bali.events.EventHub)1 Subscription (com.haulmont.bali.events.Subscription)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1