Search in sources :

Example 1 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.

the class ContextGridTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    when(parent.getGridWidget()).thenReturn(parentGridWidget);
    when(parentGridWidget.getModel()).thenReturn(parentGridData);
    when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentGridColumn));
    when(sessionManager.getCurrentSession()).thenReturn(session);
    when(session.getGridPanel()).thenReturn(gridPanel);
    when(session.getGridLayer()).thenReturn(gridLayer);
    when(session.getCellEditorControls()).thenReturn(cellEditorControls);
    tupleWithoutValue = new GridCellTuple(0, 1, gridWidget);
    tupleWithValue = new GridCellValueTuple<>(0, 1, gridWidget, new BaseGridCellValue<>("value"));
    definition = new ContextEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, expressionEditorDefinitionsSupplier, headerEditor, readOnlyProvider);
    final Decision decision = new Decision();
    decision.setName(new Name(NAME));
    hasName = Optional.of(decision);
    expression = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, expression);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add((ExpressionEditorDefinition) definition);
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditor.getParentInformation()).thenReturn(parent);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    when(undefinedExpressionEditor.getParentInformation()).thenReturn(parent);
    when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
    when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
    when(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
    when(gridLayer.getDomElementContainer()).thenReturn(gridLayerDomElementContainer);
    when(gridLayerDomElementContainer.iterator()).thenReturn(mock(Iterator.class));
    when(gridLayer.getVisibleBounds()).thenReturn(new BaseBounds(0, 0, 100, 200));
    when(gridLayer.getViewport()).thenReturn(viewport);
    when(viewport.getTransform()).thenReturn(transform);
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.singletonList(node));
    when(canvasHandler.getGraphIndex()).thenReturn(index);
    when(index.get(Mockito.<String>any())).thenReturn(element);
    when(element.getContent()).thenReturn(mock(Definition.class));
    when(definitionUtils.getNameIdentifier(any())).thenReturn("name");
    when(canvasCommandFactory.updatePropertyValue(any(Element.class), Mockito.<String>any(), any())).thenReturn(mock(UpdateElementPropertyCommand.class));
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(Mockito.<String>any());
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).getTranslation(Mockito.<String>any());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Optional(java.util.Optional) Element(org.kie.workbench.common.stunner.core.graph.Element) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) UndefinedExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionEditorDefinition) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) BaseBounds(org.uberfire.ext.wires.core.grids.client.model.impl.BaseBounds) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Iterator(java.util.Iterator) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) Before(org.junit.Before)

Example 2 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.

the class DecisionTableUIModelMapper method fromDMNModel.

@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
    dmnModel.get().ifPresent(dtable -> {
        final DecisionRule rule = dtable.getRule().get(rowIndex);
        final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, columnIndex);
        switch(section) {
            case ROW_INDEX:
                uiModel.get().setCell(rowIndex, columnIndex, () -> new DecisionTableGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector, lineHeight));
                uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
                break;
            case INPUT_CLAUSES:
                final int iei = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, columnIndex);
                uiModel.get().setCell(rowIndex, columnIndex, () -> new DecisionTableGridCell<>(new BaseGridCellValue<>(rule.getInputEntry().get(iei).getText().getValue()), listSelector, lineHeight));
                break;
            case OUTPUT_CLAUSES:
                final int oei = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, columnIndex);
                uiModel.get().setCell(rowIndex, columnIndex, () -> new DecisionTableGridCell<>(new BaseGridCellValue<>(rule.getOutputEntry().get(oei).getText().getValue()), listSelector, lineHeight));
                break;
            case ANNOTATION_CLAUSES:
                final int annotationIndex = DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, columnIndex);
                final String textValue = rule.getAnnotationEntry().get(annotationIndex).getText().getValue();
                uiModel.get().setCell(rowIndex, columnIndex, () -> new DecisionTableGridCell<>(new BaseGridCellValue<>(textValue), listSelector, lineHeight));
                break;
        }
    });
}
Also used : DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 3 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.

the class DecisionTableUIModelMapper method toDMNModel.

@Override
public void toDMNModel(final int rowIndex, final int columnIndex, final Supplier<Optional<GridCellValue<?>>> cell) {
    dmnModel.get().ifPresent(dtable -> {
        final DecisionRule rule = dtable.getRule().get(rowIndex);
        final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, columnIndex);
        switch(section) {
            case ROW_INDEX:
                break;
            case INPUT_CLAUSES:
                final int iei = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, columnIndex);
                rule.getInputEntry().get(iei).getText().setValue(cell.get().orElse(new BaseGridCellValue<>("")).getValue().toString());
                break;
            case OUTPUT_CLAUSES:
                final int oei = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, columnIndex);
                rule.getOutputEntry().get(oei).getText().setValue(cell.get().orElse(new BaseGridCellValue<>("")).getValue().toString());
                break;
            case ANNOTATION_CLAUSES:
                final int annotationIndex = DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, columnIndex);
                rule.getAnnotationEntry().get(annotationIndex).getText().setValue(cell.get().orElse(new BaseGridCellValue<>("")).getValue().toString());
                break;
        }
    });
}
Also used : DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 4 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue 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 InformationItemCell(() -> InformationItemCell.HasNameAndDataTypeCell.wrap(variable), listSelector));
                break;
            case BINDING_EXPRESSION_COLUMN_INDEX:
                final Binding binding = invocation.getBinding().get(rowIndex);
                final Optional<Expression> expression = Optional.ofNullable(binding.getExpression());
                final boolean isOnlyVisualChangeAllowed = this.isOnlyVisualChangeAllowedSupplier.get();
                final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
                expressionEditorDefinition.ifPresent(ed -> {
                    final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ed.getEditor(new GridCellTuple(rowIndex, columnIndex, gridWidget), Optional.empty(), binding, Optional.ofNullable(binding.getParameter()), isOnlyVisualChangeAllowed, nesting + 1);
                    uiModel.get().setCell(rowIndex, columnIndex, () -> new InvocationGridCell<>(new ExpressionCellValue(editor), listSelector));
                });
        }
    });
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) InformationItemCell(org.kie.workbench.common.dmn.client.editors.expressions.types.context.InformationItemCell) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) 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) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 5 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.

the class LiteralExpressionPMMLDocumentEditorDefinition method getEditor.

@Override
public Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> getEditor(final GridCellTuple parent, final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<HasName> hasName, final boolean isOnlyVisualChangeAllowed, final int nesting) {
    return Optional.of(new LiteralExpressionPMMLGrid(parent, nodeUUID, hasExpression, hasName, getGridPanel(), getGridLayer(), makeGridData(() -> Optional.ofNullable((LiteralExpressionPMMLDocument) hasExpression.getExpression())), definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, getCellEditorControls(), listSelector, translationService, isOnlyVisualChangeAllowed, nesting, headerEditor, readOnlyProvider) {

        @Override
        protected String getPlaceHolder() {
            return translationService.getTranslation(DMNEditorConstants.LiteralExpressionPMMLDocumentEditorDefinition_Placeholder);
        }

        @Override
        protected void loadValues(final Consumer<List<String>> consumer) {
            consumer.accept(pmmlDocumentMetadataProvider.getPMMLDocumentNames());
        }

        @Override
        @SuppressWarnings("unchecked")
        public Function<GridCellValueTuple, Command> newCellHasValueCommand() {
            return (gridCellValueTuple) -> {
                final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<>();
                // Command to set the PMMLDocument value
                builder.addCommand(new SetCellValueCommand(gridCellValueTuple, () -> uiModelMapper, gridLayer::batch));
                // Command to clear the PMMLDocumentModel value. Unfortunately we need to reset the cells' placeholder too.
                getExpressionPMMLValueEditor(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL).ifPresent(editor -> {
                    if (editor instanceof LiteralExpressionPMMLGrid) {
                        final LiteralExpressionPMMLGrid pmmlModelEditor = (LiteralExpressionPMMLGrid) editor;
                        builder.addCommand(pmmlModelEditor.newCellHasValueCommand().apply(new GridCellValueTuple(0, 0, pmmlModelEditor, new BaseGridCellValue("", translationService.getTranslation(DMNEditorConstants.LiteralExpressionPMMLDocumentModelEditorDefinition_Placeholder)))));
                    }
                });
                return builder.build();
            };
        }
    });
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) LiteralExpressionPMMLGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.pmml.LiteralExpressionPMMLGrid) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple) Function(java.util.function.Function) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) SetCellValueCommand(org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand) List(java.util.List) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Aggregations

BaseGridCellValue (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)23 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)11 Before (org.junit.Before)7 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)7 Test (org.junit.Test)6 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)5 HasName (org.kie.workbench.common.dmn.api.definition.HasName)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 ExpressionEditorDefinition (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition)5 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)5 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)5 Optional (java.util.Optional)4 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)4 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)4 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)4 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)4 UpdateElementPropertyCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)4 Iterator (java.util.Iterator)3