Search in sources :

Example 46 with HasExpression

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

the class InvocationGrid method clearExpressionType.

void clearExpressionType(final int uiRowIndex) {
    final GridCellTuple gc = new GridCellTuple(uiRowIndex, InvocationUIModelMapper.BINDING_EXPRESSION_COLUMN_INDEX, this);
    getExpression().get().ifPresent(invocation -> {
        final HasExpression hasExpression = invocation.getBinding().get(uiRowIndex);
        sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new ClearExpressionTypeCommand(gc, hasExpression, uiModelMapper, () -> {
            resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
            selectExpressionEditorFirstCell(uiRowIndex, InvocationUIModelMapper.BINDING_EXPRESSION_COLUMN_INDEX);
        }, () -> {
            resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
            selectExpressionEditorFirstCell(uiRowIndex, InvocationUIModelMapper.BINDING_EXPRESSION_COLUMN_INDEX);
        }));
    });
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) ClearExpressionTypeCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.invocation.ClearExpressionTypeCommand)

Example 47 with HasExpression

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

the class ListGrid method doAfterSelectionChange.

@Override
public void doAfterSelectionChange(final int uiRowIndex, final int uiColumnIndex) {
    if (hasAnyHeaderCellSelected() || hasMultipleCellsSelected()) {
        super.doAfterSelectionChange(uiRowIndex, uiColumnIndex);
        return;
    }
    if (getExpression().get().isPresent()) {
        final List list = getExpression().get().get();
        final ListUIModelMapperHelper.ListSection section = ListUIModelMapperHelper.getSection(uiColumnIndex);
        if (section == ListUIModelMapperHelper.ListSection.EXPRESSION) {
            final HasExpression hasExpression = list.getExpression().get(uiRowIndex);
            final Expression expression = hasExpression.getExpression();
            if (expression instanceof DomainObject) {
                final DomainObject domainObject = (DomainObject) expression;
                fireDomainObjectSelectionEvent(domainObject);
                return;
            }
        }
    }
    super.doAfterSelectionChange(uiRowIndex, uiColumnIndex);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) DomainObject(org.kie.workbench.common.stunner.core.domainobject.DomainObject) List(org.kie.workbench.common.dmn.api.definition.model.List) ArrayList(java.util.ArrayList)

Example 48 with HasExpression

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

the class ListGrid method clearExpressionType.

void clearExpressionType(final int uiRowIndex) {
    final GridCellTuple gc = new GridCellTuple(uiRowIndex, ListUIModelMapperHelper.EXPRESSION_COLUMN_INDEX, this);
    getExpression().get().ifPresent(list -> {
        final HasExpression hasExpression = list.getExpression().get(uiRowIndex);
        sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new ClearExpressionTypeCommand(gc, hasExpression, uiModelMapper, () -> {
            resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
            selectExpressionEditorFirstCell(uiRowIndex, ListUIModelMapperHelper.EXPRESSION_COLUMN_INDEX);
        }, () -> {
            resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
            selectExpressionEditorFirstCell(uiRowIndex, ListUIModelMapperHelper.EXPRESSION_COLUMN_INDEX);
        }));
    });
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) ClearExpressionTypeCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.list.ClearExpressionTypeCommand)

Example 49 with HasExpression

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

the class ListUIModelMapper method fromDMNModel.

@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
    dmnModel.get().ifPresent(list -> {
        final ListUIModelMapperHelper.ListSection section = ListUIModelMapperHelper.getSection(columnIndex);
        switch(section) {
            case ROW_INDEX:
                uiModel.get().setCell(rowIndex, columnIndex, () -> new ContextGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector));
                uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
                break;
            case EXPRESSION:
                final HasExpression hasExpression = list.getExpression().get(rowIndex);
                final Optional<Expression> expression = Optional.ofNullable(hasExpression.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(), hasExpression, Optional.empty(), isOnlyVisualChangeAllowed, nesting + 1);
                    uiModel.get().setCell(rowIndex, columnIndex, () -> new ContextGridCell<>(new ExpressionCellValue(editor), listSelector));
                });
        }
    });
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) 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.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 50 with HasExpression

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

the class ListPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final List wb = new List();
    final LiteralExpression literalExpression = new LiteralExpression();
    final HasExpression hasExpression = HasExpression.wrap(wb, literalExpression);
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    wb.getId().setValue(LIST_UUID);
    wb.getDescription().setValue(LIST_DESCRIPTION);
    wb.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(org.kie.workbench.common.dmn.api.property.dmn.QName.NULL_NS_URI, LIST_QNAME_LOCALPART));
    wb.getExpression().add(hasExpression);
    final org.kie.dmn.model.api.List dmn = ListPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(LIST_UUID);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(LIST_DESCRIPTION);
    assertThat(dmn.getTypeRef()).isNotNull();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(LIST_QNAME_LOCALPART);
    assertThat(dmn.getExpression()).isNotNull();
    assertThat(dmn.getExpression().size()).isEqualTo(1);
    assertThat(dmn.getExpression().get(0).getId()).isEqualTo(EXPRESSION_UUID);
    verify(componentWidthsConsumer).accept(componentWidthsCaptor.capture());
    final ComponentWidths componentWidths = componentWidthsCaptor.getValue();
    assertThat(componentWidths).isNotNull();
    assertThat(componentWidths.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
    assertThat(componentWidths.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
    assertThat(componentWidths.getWidths().get(0)).isEqualTo(200.0);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) List(org.kie.workbench.common.dmn.api.definition.model.List) TList(org.kie.dmn.model.v1_2.TList) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) Test(org.junit.Test)

Aggregations

HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)78 Test (org.junit.Test)41 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)30 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)24 HasName (org.kie.workbench.common.dmn.api.definition.HasName)18 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)15 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)15 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)15 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)15 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)13 Optional (java.util.Optional)12 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)10 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)10 ExpressionEditorDefinition (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition)8 ExpressionEditorDefinitions (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions)8 ArrayList (java.util.ArrayList)7 EditExpressionEvent (org.kie.workbench.common.dmn.client.events.EditExpressionEvent)6 Before (org.junit.Before)5