Search in sources :

Example 1 with GridRow

use of org.uberfire.ext.wires.core.grids.client.model.GridRow 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)

Example 2 with GridRow

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

the class AddContextEntryCommandTest method testCanvasCommandExecuteMultipleEntries.

@Test
public void testCanvasCommandExecuteMultipleEntries() {
    makeCommand();
    // first row
    command.newGraphCommand(handler).execute(gce);
    final Command<AbstractCanvasHandler, CanvasViolation> firstEntryCanvasCommand = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, firstEntryCanvasCommand.execute(handler));
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
    // second row
    final ContextEntry secondRowEntry = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    final GridRow uiSecondModelRow = new BaseGridRow();
    command = spy(new AddContextEntryCommand(context, secondRowEntry, uiModel, uiSecondModelRow, context.getContextEntry().size() - 1, uiModelMapper, canvasOperation));
    command.newGraphCommand(handler).execute(gce);
    final Command<AbstractCanvasHandler, CanvasViolation> secondEntryCanvasCommand = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, secondEntryCanvasCommand.execute(handler));
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
    assertEquals(3, uiModel.getRowCount());
    assertEquals(uiModelRow, uiModel.getRows().get(0));
    assertEquals(uiSecondModelRow, uiModel.getRows().get(1));
    assertEquals(uiDefaultResultModelRow, uiModel.getRows().get(2));
    assertEquals(3, uiModel.getColumnCount());
    assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
    assertEquals(uiNameColumn, uiModel.getColumns().get(1));
    assertEquals(uiExpressionEditorColumn, uiModel.getColumns().get(2));
    assertEquals(3, uiModel.getRows().get(0).getCells().size());
    assertEquals(1, uiModel.getCell(0, 0).getValue().getValue());
    assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "1", ((InformationItemCell.HasNameAndDataTypeCell) uiModel.getCell(0, 1).getValue().getValue()).getName().getValue());
    assertTrue(uiModel.getCell(0, 2).getValue() instanceof ExpressionCellValue);
    assertEquals(3, uiModel.getRows().get(1).getCells().size());
    assertEquals(2, uiModel.getCell(1, 0).getValue().getValue());
    assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "2", ((InformationItemCell.HasNameAndDataTypeCell) uiModel.getCell(1, 1).getValue().getValue()).getName().getValue());
    assertTrue(uiModel.getCell(1, 2).getValue() instanceof ExpressionCellValue);
    // Default row
    assertEquals(1, uiModel.getRows().get(2).getCells().size());
    assertTrue(uiModel.getCell(2, 2).getValue() instanceof ExpressionCellValue);
    verify(canvasOperation, times(2)).execute();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Test(org.junit.Test)

Example 3 with GridRow

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

the class DeleteContextEntryCommandTest method testCanvasCommandExecuteWithColumnsMultipleRows.

@Test
public void testCanvasCommandExecuteWithColumnsMultipleRows() {
    addContextEntries(3);
    final GridRow firstRow = uiModel.getRow(0);
    final GridRow lastRow = uiModel.getRow(2);
    makeCommand(1);
    uiModel.appendColumn(uiModelColumn);
    final Command<AbstractCanvasHandler, CanvasViolation> cc = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
    assertEquals(2, uiModel.getRowCount());
    assertEquals(2, uiModel.getColumnCount());
    assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
    assertEquals(uiModelColumn, uiModel.getColumns().get(1));
    assertEquals(firstRow, uiModel.getRow(0));
    assertEquals(lastRow, uiModel.getRow(1));
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
    verify(canvasOperation).execute();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) Test(org.junit.Test)

Example 4 with GridRow

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

the class AddDecisionRuleCommandTest method assertDefaultUiRowValues.

private void assertDefaultUiRowValues(final int uiRowIndex) {
    final GridRow uiGridRow = uiModel.getRow(uiRowIndex);
    assertEquals(uiRowIndex + 1, uiGridRow.getCells().get(0).getValue().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, uiGridRow.getCells().get(1).getValue().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, uiGridRow.getCells().get(2).getValue().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT, uiGridRow.getCells().get(3).getValue().getValue());
}
Also used : BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow)

Example 5 with GridRow

use of org.uberfire.ext.wires.core.grids.client.model.GridRow 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)

Aggregations

GridRow (org.uberfire.ext.wires.core.grids.client.model.GridRow)54 Test (org.junit.Test)31 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)22 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)10 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)10 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)10 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)8 GridCell (org.uberfire.ext.wires.core.grids.client.model.GridCell)6 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)6 BaseGridCell (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCell)6 ArrayList (java.util.ArrayList)4 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)4 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)4 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)3 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)3 HashMap (java.util.HashMap)2 Maps (org.kie.soup.commons.util.Maps)2 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)2 List (org.kie.workbench.common.dmn.api.definition.model.List)2 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)2