Search in sources :

Example 36 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class ExpressionContainerGrid method spyHasExpression.

/**
 * Proxy {@link HasExpression} to be able intercept interactions with the original
 * to update the expression label in {@link ExpressionEditorView} when the {@link Expression} changes.
 * @param hasExpression A {@link HasExpression} to be proxied.
 * @return A proxy that intercepts interactions with the wrapped {@link HasExpression}
 */
HasExpression spyHasExpression(final HasExpression hasExpression) {
    final HasExpression spy = new HasExpression() {

        @Override
        public Expression getExpression() {
            return hasExpression.getExpression();
        }

        @Override
        public void setExpression(final Expression expression) {
            hasExpression.setExpression(expression);
            onHasExpressionChanged.execute(Optional.ofNullable(expression));
        }

        @Override
        public DMNModelInstrumentedBase asDMNModelInstrumentedBase() {
            return hasExpression.asDMNModelInstrumentedBase();
        }

        @Override
        public boolean isClearSupported() {
            return hasExpression.isClearSupported();
        }
    };
    return spy;
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression)

Example 37 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class ExpressionEditorColumn method getMinimumWidth.

@Override
public Double getMinimumWidth() {
    double minimumWidth = super.getMinimumWidth();
    final GridData model = gridWidget.getModel();
    final int columnIndex = getLogicalColumnIndex(model);
    if (columnIndex != -1) {
        for (GridRow row : model.getRows()) {
            final GridCell<?> cell = row.getCells().get(columnIndex);
            if (cell != null) {
                final GridCellValue<?> value = cell.getValue();
                if (value instanceof ExpressionCellValue) {
                    final ExpressionCellValue ecv = (ExpressionCellValue) value;
                    final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ecv.getValue();
                    final double padding = editor.map(BaseExpressionGrid::getPadding).orElse(0.0);
                    minimumWidth = Math.max(minimumWidth, ecv.getMinimumWidth().orElse(0.0) + padding * 2);
                }
            }
        }
    }
    return minimumWidth;
}
Also used : BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow)

Example 38 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class ExpressionEditorColumn method updateWidthOfChildren.

protected void updateWidthOfChildren() {
    final double columnWidth = getWidth();
    final GridData model = gridWidget.getModel();
    final int columnIndex = getLogicalColumnIndex(model);
    if (columnIndex != -1) {
        for (GridRow row : model.getRows()) {
            final GridCell<?> cell = row.getCells().get(columnIndex);
            if (cell != null) {
                final GridCellValue<?> value = cell.getValue();
                if (value instanceof ExpressionCellValue) {
                    final ExpressionCellValue ecv = (ExpressionCellValue) value;
                    final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ecv.getValue();
                    if (editor.isPresent()) {
                        final BaseExpressionGrid beg = editor.get();
                        updateWidthOfLastColumn(beg, columnWidth);
                    }
                }
            }
        }
    }
}
Also used : BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow)

Example 39 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class FunctionGrid method doSetKind.

void doSetKind(final FunctionDefinition.Kind kind, final FunctionDefinition function, final Optional<ExpressionEditorDefinition<Expression>> oDefinition) {
    oDefinition.ifPresent(definition -> {
        final GridCellTuple parent = new GridCellTuple(0, 1, FunctionGrid.this);
        final Optional<Expression> expression = definition.getModelClass();
        definition.enrich(nodeUUID, hasExpression, expression);
        sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new SetKindCommand(parent, function, kind, expression, (editor) -> {
            editor.ifPresent(e -> {
                e.resize(BaseExpressionGrid.RESIZE_EXISTING);
                e.selectFirstCell();
            });
        }, () -> {
            resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
            selectFirstCell();
        }, () -> {
            Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = Optional.empty();
            editor = definition.getEditor(parent, Optional.empty(), getExpression().get().get(), hasName, isOnlyVisualChangeAllowed, nesting + 1);
            return editor;
        }));
    });
}
Also used : CellEditorControlsView(org.kie.workbench.common.dmn.client.widgets.grid.controls.container.CellEditorControlsView) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) UpdateParameterNameCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.UpdateParameterNameCommand) RemoveParameterCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.RemoveParameterCommand) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) ListSelectorView(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelectorView) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) DMNGridLayer(org.kie.workbench.common.dmn.client.widgets.layer.DMNGridLayer) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) UndefinedExpressionGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionGrid) ClearExpressionTypeCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.ClearExpressionTypeCommand) EventPropagationMode(com.ait.lienzo.shared.core.types.EventPropagationMode) KindPopoverView(org.kie.workbench.common.dmn.client.editors.expressions.types.function.kindselector.KindPopoverView) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) HasParametersControl(org.kie.workbench.common.dmn.client.editors.expressions.types.function.parameters.HasParametersControl) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AddParameterCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.AddParameterCommand) DomainObject(org.kie.workbench.common.stunner.core.domainobject.DomainObject) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) List(java.util.List) ParametersPopoverView(org.kie.workbench.common.dmn.client.editors.expressions.types.function.parameters.ParametersPopoverView) DefaultCanvasCommandFactory(org.kie.workbench.common.dmn.client.commands.factory.DefaultCanvasCommandFactory) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) Optional(java.util.Optional) ValueAndDataTypePopoverView(org.kie.workbench.common.dmn.client.editors.types.ValueAndDataTypePopoverView) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) HasListSelectorControl(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl) ExpressionType(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionType) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionEditorChanged(org.kie.workbench.common.dmn.client.widgets.grid.model.ExpressionEditorChanged) RefreshFormPropertiesEvent(org.kie.workbench.common.stunner.forms.client.event.RefreshFormPropertiesEvent) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) ReadOnlyProvider(org.kie.workbench.common.stunner.core.client.ReadOnlyProvider) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasKindSelectControl(org.kie.workbench.common.dmn.client.editors.expressions.types.function.kindselector.HasKindSelectControl) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) Command(org.uberfire.mvp.Command) Event(javax.enterprise.event.Event) SetKindCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetKindCommand) DMNEditorConstants(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants) DMNGridPanel(org.kie.workbench.common.dmn.client.widgets.panel.DMNGridPanel) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) UndefinedExpressionColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionColumn) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) DomainObjectSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.DomainObjectSelectionEvent) UpdateParameterTypeRefCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.UpdateParameterTypeRefCommand) ExpressionEditorGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.ExpressionEditorGridRow) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) SetKindCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetKindCommand) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Optional(java.util.Optional) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression)

Example 40 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class FunctionUIModelMapper method setUiModelEditor.

private void setUiModelEditor(final int rowIndex, final int columnIndex, final FunctionDefinition function, final ExpressionEditorDefinition<Expression> ed) {
    final GridCellTuple expressionParent = new GridCellTuple(rowIndex, columnIndex, gridWidget);
    final boolean isOnlyVisualChangeAllowed = this.isOnlyVisualChangeAllowedSupplier.get();
    final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ed.getEditor(expressionParent, Optional.empty(), function, Optional.empty(), isOnlyVisualChangeAllowed, nesting);
    uiModel.get().setCell(rowIndex, columnIndex, () -> new FunctionGridCell<>(new ExpressionCellValue(editor), listSelector));
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Aggregations

Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)75 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)41 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)29 Test (org.junit.Test)27 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)26 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)26 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)14 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)11 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)10 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)9 ArrayList (java.util.ArrayList)8 Context (org.kie.workbench.common.dmn.api.definition.model.Context)8 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)8 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)7 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)7 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)7