Search in sources :

Example 1 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid 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 expressionParent = new GridCellTuple(0, 0, this);
        final Optional<Expression> expression = definition.getModelClass();
        final Optional<BaseExpressionGrid> gridWidget = definition.getEditor(expressionParent, Optional.empty(), hasExpression, expression, hasName, nesting);
        doSetKind(kind, function, expression, gridWidget);
    });
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)

Example 2 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.

the class FunctionGrid method getItems.

@Override
@SuppressWarnings("unused")
public List<ListSelectorItem> getItems(final int uiRowIndex, final int uiColumnIndex) {
    final List<ListSelectorItem> items = new ArrayList<>();
    final FunctionDefinition.Kind kind = KindUtilities.getKind(expression.get());
    items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.FunctionEditor_FEEL), !FunctionDefinition.Kind.FEEL.equals(kind), () -> {
        cellEditorControls.hide();
        expression.ifPresent(e -> setKind(FunctionDefinition.Kind.FEEL));
    }));
    items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.FunctionEditor_JAVA), !FunctionDefinition.Kind.JAVA.equals(kind), () -> {
        cellEditorControls.hide();
        expression.ifPresent(e -> setKind(FunctionDefinition.Kind.JAVA));
    }));
    items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.FunctionEditor_PMML), !FunctionDefinition.Kind.PMML.equals(kind), () -> {
        cellEditorControls.hide();
        expression.ifPresent(e -> setKind(FunctionDefinition.Kind.PMML));
    }));
    // If cell editor is UndefinedExpressionGrid don't add extra items
    final GridCell<?> cell = model.getCell(uiRowIndex, uiColumnIndex);
    final ExpressionCellValue ecv = (ExpressionCellValue) cell.getValue();
    if (!ecv.getValue().isPresent()) {
        return items;
    }
    final BaseExpressionGrid grid = ecv.getValue().get();
    if (grid instanceof UndefinedExpressionGrid) {
        return items;
    }
    items.add(new ListSelectorDividerItem());
    items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ExpressionEditor_Clear), true, () -> {
        cellEditorControls.hide();
        clearExpressionType();
    }));
    return items;
}
Also used : CellEditorControlsView(org.kie.workbench.common.dmn.client.widgets.grid.controls.container.CellEditorControlsView) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) Arrays(java.util.Arrays) 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) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.v1_1.FunctionDefinition) HasListSelectorControl(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl) 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) ExpressionType(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionType) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ParametersEditorView(org.kie.workbench.common.dmn.client.editors.expressions.types.function.parameters.ParametersEditorView) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) UndefinedExpressionGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionGrid) ClearExpressionTypeCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.ClearExpressionTypeCommand) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) Command(org.uberfire.mvp.Command) 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) EventPropagationMode(com.ait.lienzo.shared.core.types.EventPropagationMode) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) CanvasCommandFactory(org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) HasParametersControl(org.kie.workbench.common.dmn.client.editors.expressions.types.function.parameters.HasParametersControl) GridDataCache(org.kie.workbench.common.dmn.client.widgets.grid.model.GridDataCache) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AddParameterCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.AddParameterCommand) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) HasName(org.kie.workbench.common.dmn.api.definition.HasName) List(java.util.List) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) Optional(java.util.Optional) ExpressionEditorColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionEditorColumn) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) UndefinedExpressionGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionGrid) ArrayList(java.util.ArrayList) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.v1_1.FunctionDefinition) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Example 3 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid 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(0, 0, gridWidget);
    final Optional<Expression> expression = Optional.ofNullable(function.getExpression());
    final Optional<BaseExpressionGrid> editor = ed.getEditor(expressionParent, Optional.empty(), function, expression, Optional.empty(), nesting + 1);
    uiModel.get().setCell(rowIndex, columnIndex, () -> new FunctionGridCell<>(new ExpressionCellValue(editor), listSelector));
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Example 4 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.

the class InvocationUIModelMapper method fromDMNModel.

@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
    dmnModel.get().ifPresent(invocation -> {
        switch(columnIndex) {
            case ROW_NUMBER_COLUMN_INDEX:
                uiModel.get().setCell(rowIndex, columnIndex, () -> new InvocationGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector));
                uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
                break;
            case BINDING_PARAMETER_COLUMN_INDEX:
                final InformationItem variable = invocation.getBinding().get(rowIndex).getParameter();
                uiModel.get().setCell(rowIndex, columnIndex, () -> new InformationItemNameCell(() -> variable, listSelector));
                break;
            case BINDING_EXPRESSION_COLUMN_INDEX:
                final Binding binding = invocation.getBinding().get(rowIndex);
                final Optional<Expression> expression = Optional.ofNullable(binding.getExpression());
                final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
                expressionEditorDefinition.ifPresent(ed -> {
                    final Optional<BaseExpressionGrid> editor = ed.getEditor(new GridCellTuple(rowIndex, columnIndex, gridWidget), Optional.empty(), binding, expression, Optional.ofNullable(binding.getParameter()), nesting + 1);
                    uiModel.get().setCell(rowIndex, columnIndex, () -> new InvocationGridCell<>(new ExpressionCellValue(editor), listSelector));
                });
        }
    });
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.v1_1.Binding) InformationItemNameCell(org.kie.workbench.common.dmn.client.editors.expressions.types.context.InformationItemNameCell) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 5 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.

the class RelationColumn method getMinimumWidthOfPeers.

private double getMinimumWidthOfPeers() {
    final GridCellTuple parent = gridWidget.getParentInformation();
    final GridData parentUiModel = parent.getGridWidget().getModel();
    final int parentUiRowIndex = parent.getRowIndex();
    final int parentUiColumnIndex = parent.getColumnIndex();
    double minimumWidth = super.getMinimumWidth();
    for (int uiRowIndex = 0; uiRowIndex < parentUiModel.getRowCount(); uiRowIndex++) {
        if (uiRowIndex != parentUiRowIndex) {
            final GridRow row = parentUiModel.getRow(uiRowIndex);
            final GridCell<?> cell = row.getCells().get(parentUiColumnIndex);
            if (cell != null) {
                final GridCellValue<?> value = cell.getValue();
                if (value instanceof ExpressionCellValue) {
                    final ExpressionCellValue ecv = (ExpressionCellValue) value;
                    final Optional<BaseExpressionGrid> editor = ecv.getValue();
                    final double padding = editor.map(BaseExpressionGrid::getPadding).get();
                    minimumWidth = Math.max(minimumWidth, ecv.getMinimumWidth().orElse(0.0) + padding * 2);
                }
            }
        }
    }
    return minimumWidth;
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow)

Aggregations

BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)32 Test (org.junit.Test)15 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)13 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)13 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)11 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)11 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)8 List (java.util.List)7 Optional (java.util.Optional)7 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)7 Expression (org.kie.workbench.common.dmn.api.definition.v1_1.Expression)7 GridCell (org.uberfire.ext.wires.core.grids.client.model.GridCell)7 ArrayList (java.util.ArrayList)6 HasName (org.kie.workbench.common.dmn.api.definition.HasName)6 HasListSelectorControl (org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl)6 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)6 DMNGridLayer (org.kie.workbench.common.dmn.client.widgets.layer.DMNGridLayer)6 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)5 ExpressionEditorDefinition (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition)5 ExpressionEditorColumn (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionEditorColumn)5