Search in sources :

Example 6 with InstanceContainer

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

the class WebDataLoadCoordinator method configureAutomatically.

private void configureAutomatically(DataLoader loader, FrameOwner frameOwner) {
    List<String> queryParameters = DataLoadersHelper.getQueryParameters(loader);
    List<String> allParameters = new ArrayList<>(queryParameters);
    allParameters.addAll(getConditionParameters(loader));
    // add triggers on container/component events
    for (String parameter : allParameters) {
        if (parameter.startsWith(containerPrefix)) {
            InstanceContainer container = UiControllerUtils.getScreenData(frameOwner).getContainer(parameter.substring(containerPrefix.length()));
            addOnContainerItemChangedLoadTrigger(loader, container, parameter);
        } else if (parameter.startsWith(componentPrefix)) {
            String componentId = parameter.substring(componentPrefix.length());
            Component component = frameOwner instanceof Screen ? ((Screen) frameOwner).getWindow().getComponentNN(componentId) : ((ScreenFragment) frameOwner).getFragment().getComponentNN(componentId);
            LikeClause likeClause = findLikeClause(loader, parameter);
            addOnComponentValueChangedLoadTrigger(loader, component, parameter, likeClause);
        }
    }
    // if the loader has no parameters in query, add trigger on BeforeShowEvent/AttachEvent
    if (queryParameters.isEmpty()) {
        Class eventClass = frameOwner instanceof Screen ? Screen.BeforeShowEvent.class : ScreenFragment.AttachEvent.class;
        addOnFrameOwnerEventLoadTrigger(loader, eventClass);
    }
}
Also used : ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) Screen(com.haulmont.cuba.gui.screen.Screen) ArrayList(java.util.ArrayList) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) Component(com.haulmont.cuba.gui.components.Component)

Example 7 with InstanceContainer

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

the class DynamicAttributesGuiTools method getValueChangeEventListener.

/**
 * Returns {@code ValueChangeEventListener} for dynamic attribute that has one or more dependent attributes.
 * This listener recalculates values for all dependent dynamic attributes hierarchically. The listener uses
 * {@code recalculationInProgress} ThreadLocal variable to avoid unnecessary calculation.
 */
@SuppressWarnings("unchecked")
public Consumer<HasValue.ValueChangeEvent> getValueChangeEventListener(final CategoryAttribute attribute) {
    if (attribute.getConfiguration().getDependentAttributes() != null && !attribute.getConfiguration().getDependentAttributes().isEmpty()) {
        return valueChangeEvent -> {
            if (Boolean.TRUE.equals(recalculationInProgress.get())) {
                return;
            }
            try {
                recalculationInProgress.set(true);
                com.haulmont.cuba.gui.components.Component component = valueChangeEvent.getComponent();
                if (component instanceof HasValueSource) {
                    {
                        BaseGenericIdEntity entity = null;
                        String attributeCode = DynamicAttributesUtils.encodeAttributeCode(attribute.getCode());
                        if (((HasValueSource) component).getValueSource() instanceof ContainerValueSource) {
                            ContainerValueSource valueSource = (ContainerValueSource) ((HasValueSource) component).getValueSource();
                            InstanceContainer container = valueSource.getContainer();
                            if (container.getItem() instanceof BaseGenericIdEntity) {
                                entity = (BaseGenericIdEntity) container.getItem();
                            }
                        } else if (((HasValueSource) component).getValueSource() instanceof DatasourceValueSource) {
                            DatasourceValueSource valueSource = (DatasourceValueSource) ((HasValueSource) component).getValueSource();
                            if (valueSource.getItem() instanceof BaseGenericIdEntity) {
                                entity = (BaseGenericIdEntity) valueSource.getItem();
                            } else if (valueSource.getItem() instanceof DynamicAttributesEntity) {
                                entity = ((DynamicAttributesEntity) valueSource.getItem()).getMainItem();
                            }
                        }
                        entity.setValue(attributeCode, valueChangeEvent.getValue());
                        recalculationTools.recalculateDynamicAttributes(entity, attribute);
                    }
                }
            } finally {
                recalculationInProgress.remove();
            }
        };
    }
    return null;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) com.haulmont.cuba.gui.components.validation(com.haulmont.cuba.gui.components.validation) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) DynamicAttributesEntity(com.haulmont.cuba.gui.data.DynamicAttributesEntity) DecimalFormatSymbols(java.text.DecimalFormatSymbols) ZonedDateTime(java.time.ZonedDateTime) DatatypeRegistry(com.haulmont.chile.core.datatypes.DatatypeRegistry) AdaptiveNumberDatatype(com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype) StringUtils(org.apache.commons.lang3.StringUtils) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) BigDecimal(java.math.BigDecimal) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) PickerField(com.haulmont.cuba.gui.components.PickerField) OpenMode(com.haulmont.cuba.gui.screen.OpenMode) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) GuiActionSupport(com.haulmont.cuba.gui.components.actions.GuiActionSupport) WindowParams(com.haulmont.cuba.gui.WindowParams) EntityOp(com.haulmont.cuba.security.entity.EntityOp) java.util(java.util) DatasourceValueSource(com.haulmont.cuba.gui.components.data.value.DatasourceValueSource) ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) ParamsMap(com.haulmont.bali.util.ParamsMap) DynamicAttributesUtils(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils) BooleanUtils(org.apache.commons.lang3.BooleanUtils) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) MetaClass(com.haulmont.chile.core.model.MetaClass) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Datatype(com.haulmont.chile.core.datatypes.Datatype) HasValue(com.haulmont.cuba.gui.components.HasValue) com.haulmont.cuba.core.entity(com.haulmont.cuba.core.entity) MapScreenOptions(com.haulmont.cuba.gui.screen.MapScreenOptions) Nullable(javax.annotation.Nullable) DynamicAttributesRecalculationTools(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesRecalculationTools) CommonLookupController(com.haulmont.cuba.gui.commonlookup.CommonLookupController) DecimalFormat(java.text.DecimalFormat) ScreensHelper(com.haulmont.cuba.gui.sys.ScreensHelper) Preconditions(com.haulmont.bali.util.Preconditions) Consumer(java.util.function.Consumer) Component(org.springframework.stereotype.Component) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) PropertyType(com.haulmont.cuba.core.app.dynamicattributes.PropertyType) Action(com.haulmont.cuba.gui.components.Action) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) DatasourceValueSource(com.haulmont.cuba.gui.components.data.value.DatasourceValueSource) DynamicAttributesEntity(com.haulmont.cuba.gui.data.DynamicAttributesEntity) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) Component(org.springframework.stereotype.Component) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource)

Example 8 with InstanceContainer

use of com.haulmont.cuba.gui.model.InstanceContainer 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 9 with InstanceContainer

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

the class WebTableFieldFactory method createField.

@SuppressWarnings("unchecked")
@Override
public com.vaadin.v7.ui.Field<?> createField(com.vaadin.v7.data.Container container, Object itemId, Object propertyId, Component uiContext) {
    String fieldPropertyId = String.valueOf(propertyId);
    Table.Column columnConf = webTable.getColumnsInternal().get(propertyId);
    TableDataContainer tableDataContainer = (TableDataContainer) container;
    Entity entity = (Entity) tableDataContainer.getInternalItem(itemId);
    InstanceContainer instanceContainer = webTable.getInstanceContainer((E) entity);
    com.haulmont.cuba.gui.components.Component columnComponent = createField(new ContainerValueSource(instanceContainer, fieldPropertyId), fieldPropertyId, columnConf.getXmlDescriptor());
    if (columnComponent instanceof Field) {
        Field cubaField = (Field) columnComponent;
        Map<Table.Column, String> requiredColumns = webTable.getRequiredColumnsInternal();
        if (requiredColumns != null && requiredColumns.containsKey(columnConf)) {
            cubaField.setRequired(true);
            cubaField.setRequiredMessage(requiredColumns.get(columnConf));
        }
    }
    if (!(columnComponent instanceof CheckBox)) {
        // todo get rid of concrete CheckBox class !
        columnComponent.setWidthFull();
    }
    if (columnComponent instanceof BelongToFrame) {
        BelongToFrame belongToFrame = (BelongToFrame) columnComponent;
        if (belongToFrame.getFrame() == null) {
            belongToFrame.setFrame(webTable.getFrame());
        }
    }
    applyPermissions(columnComponent);
    columnComponent.setParent(webTable);
    Component componentImpl = getComponentImplementation(columnComponent);
    if (componentImpl instanceof com.vaadin.v7.ui.Field) {
        return (com.vaadin.v7.ui.Field<?>) componentImpl;
    }
    return new EditableColumnFieldWrapper(componentImpl, columnComponent);
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Table(com.haulmont.cuba.gui.components.Table) WebAbstractTable(com.haulmont.cuba.web.gui.components.WebAbstractTable) BelongToFrame(com.haulmont.cuba.gui.components.Component.BelongToFrame) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) Field(com.haulmont.cuba.gui.components.Field) CheckBox(com.haulmont.cuba.gui.components.CheckBox) Component(com.vaadin.ui.Component)

Example 10 with InstanceContainer

use of com.haulmont.cuba.gui.model.InstanceContainer 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

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