Search in sources :

Example 1 with ScenarioGridCell

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell in project drools-wb by kiegroup.

the class AbstractScesimGridModel method commonAddRow.

protected void commonAddRow(int rowIndex, int columnIndexStart) {
    E scesimData = abstractScesimModel.addData(rowIndex);
    final ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    IntStream.range(columnIndexStart, getColumnCount()).forEach(columnIndex -> {
        final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex);
        scesimData.addMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier(), null);
        ScenarioGridColumn column = ((ScenarioGridColumn) columns.get(columnIndex));
        String placeHolder = ScenarioSimulationUtils.getPlaceHolder(column.isInstanceAssigned(), column.isPropertyAssigned(), factMappingByIndex.getFactMappingValueType(), factMappingByIndex.getClassName());
        setCell(rowIndex, columnIndex, () -> {
            ScenarioGridCell newCell = new ScenarioGridCell(new ScenarioGridCellValue(null, placeHolder));
            if (ScenarioSimulationSharedUtils.isCollectionOrMap((factMappingByIndex.getClassName()))) {
                newCell.setListMap(ScenarioSimulationSharedUtils.isList((factMappingByIndex.getClassName())));
            }
            return newCell;
        });
    });
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 2 with ScenarioGridCell

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell in project drools-wb by kiegroup.

the class AbstractScesimGridModel method refreshErrorsRow.

protected void refreshErrorsRow(int rowIndex) {
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    E scesimDataByIndex = abstractScesimModel.getDataByIndex(rowIndex);
    IntStream.range(0, getColumnCount()).forEach(columnIndex -> {
        ScenarioGridCell cell = (ScenarioGridCell) getCell(rowIndex, columnIndex);
        if (cell == null) {
            return;
        }
        final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex);
        Optional<FactMappingValue> factMappingValue = scesimDataByIndex.getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier());
        if (factMappingValue.isPresent()) {
            cell.setErrorMode(FactMappingValueStatus.SUCCESS != factMappingValue.get().getStatus());
        } else {
            cell.setErrorMode(false);
        }
    });
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue)

Example 3 with ScenarioGridCell

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell in project drools-wb by kiegroup.

the class ScenarioGridColumnRendererTest method getValueToShow.

@Test
public void getValueToShow() {
    ScenarioGridCell cell = new ScenarioGridCell(null);
    commonGetValueToShow(cell, true, null, false);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(null));
    commonGetValueToShow(cell, true, null, false);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(MULTIPART_VALUE));
    commonGetValueToShow(cell, false, null, false);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(LIST_VALUE));
    cell.setListMap(true);
    commonGetValueToShow(cell, false, LIST_VALUE, true);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(MAP_VALUE));
    cell.setListMap(false);
    commonGetValueToShow(cell, false, MAP_VALUE, false);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(EXPRESSION_VALUE));
    cell.setListMap(true);
    commonGetValueToShow(cell, false, EXPRESSION_VALUE, true);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(EXPRESSION_VALUE));
    cell.setListMap(false);
    commonGetValueToShow(cell, false, EXPRESSION_VALUE, false);
}
Also used : ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue) Test(org.junit.Test)

Example 4 with ScenarioGridCell

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell in project drools-wb by kiegroup.

the class ScenarioGridColumnRendererTest method renderCell.

@Test
public void renderCell() {
    GridCell<String> cell = null;
    Group retrieved = scenarioGridColumnRenderer.renderCell(cell, contextMock);
    assertNull(retrieved);
    verify(scenarioGridColumnRenderer, never()).internalRenderCell(any(), eq(contextMock), any(), anyString());
    verify(scenarioGridColumnRenderer, never()).getCollectionString(anyString(), anyBoolean());
    cell = new ScenarioGridCell(null);
    retrieved = scenarioGridColumnRenderer.renderCell(cell, contextMock);
    assertNull(retrieved);
    verify(scenarioGridColumnRenderer, never()).getCollectionString(anyString(), anyBoolean());
    verify(scenarioGridColumnRenderer, never()).internalRenderCell(any(), eq(contextMock), eq(textMock), eq(null));
    reset(scenarioGridColumnRenderer);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(null));
    retrieved = scenarioGridColumnRenderer.renderCell(cell, contextMock);
    assertNull(retrieved);
    verify(scenarioGridColumnRenderer, never()).getCollectionString(anyString(), anyBoolean());
    verify(scenarioGridColumnRenderer, never()).internalRenderCell(any(), eq(contextMock), eq(textMock), eq(null));
    reset(scenarioGridColumnRenderer);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(MULTIPART_VALUE));
    retrieved = scenarioGridColumnRenderer.renderCell(cell, contextMock);
    assertNotNull(retrieved);
    verify(scenarioGridColumnRenderer, never()).getCollectionString(anyString(), anyBoolean());
    verify(scenarioGridColumnRenderer, times(1)).internalRenderCell(any(), eq(contextMock), eq(textMock), eq(MULTIPART_VALUE));
    reset(scenarioGridColumnRenderer);
    ScenarioGridCell scenarioGridCell = new ScenarioGridCell(new ScenarioGridCellValue(MULTIPART_VALUE, PLACEHOLDER));
    retrieved = scenarioGridColumnRenderer.renderCell(scenarioGridCell, contextMock);
    assertNotNull(retrieved);
    verify(scenarioGridColumnRenderer, never()).getCollectionString(anyString(), anyBoolean());
    verify(scenarioGridColumnRenderer, times(1)).internalRenderCell(any(), eq(contextMock), eq(textMock), eq(MULTIPART_VALUE));
    reset(scenarioGridColumnRenderer);
    scenarioGridCell = new ScenarioGridCell(new ScenarioGridCellValue(null, PLACEHOLDER));
    retrieved = scenarioGridColumnRenderer.renderCell(scenarioGridCell, contextMock);
    assertNotNull(retrieved);
    verify(scenarioGridColumnRenderer, times(1)).internalRenderCell(any(), eq(contextMock), eq(placeholderMock), eq(PLACEHOLDER));
    verify(scenarioGridColumnRenderer, never()).getCollectionString(anyString(), anyBoolean());
    reset(scenarioGridColumnRenderer);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(LIST_VALUE));
    ((ScenarioGridCell) cell).setListMap(true);
    retrieved = scenarioGridColumnRenderer.renderCell(cell, contextMock);
    assertNotNull(retrieved);
    verify(scenarioGridColumnRenderer, times(1)).internalRenderCell(any(), eq(contextMock), eq(textMock), eq(LIST_VALUE));
    verify(scenarioGridColumnRenderer, times(1)).getCollectionString(eq(LIST_VALUE), eq(true));
    reset(scenarioGridColumnRenderer);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(MAP_VALUE));
    ((ScenarioGridCell) cell).setListMap(false);
    retrieved = scenarioGridColumnRenderer.renderCell(cell, contextMock);
    assertNotNull(retrieved);
    verify(scenarioGridColumnRenderer, times(1)).internalRenderCell(any(), eq(contextMock), eq(textMock), eq(MAP_VALUE));
    verify(scenarioGridColumnRenderer, times(1)).getCollectionString(eq(MAP_VALUE), eq(false));
    reset(scenarioGridColumnRenderer);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(EXPRESSION_VALUE));
    ((ScenarioGridCell) cell).setListMap(true);
    retrieved = scenarioGridColumnRenderer.renderCell(cell, contextMock);
    assertNotNull(retrieved);
    verify(scenarioGridColumnRenderer, times(1)).internalRenderCell(any(), eq(contextMock), eq(textMock), eq(EXPRESSION_VALUE));
    verify(scenarioGridColumnRenderer, times(1)).getCollectionString(eq(EXPRESSION_VALUE), eq(true));
    reset(scenarioGridColumnRenderer);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(EXPRESSION_VALUE));
    ((ScenarioGridCell) cell).setListMap(false);
    retrieved = scenarioGridColumnRenderer.renderCell(cell, contextMock);
    assertNotNull(retrieved);
    verify(scenarioGridColumnRenderer, times(1)).internalRenderCell(any(), eq(contextMock), eq(textMock), eq(EXPRESSION_VALUE));
    verify(scenarioGridColumnRenderer, times(1)).getCollectionString(eq(EXPRESSION_VALUE), eq(false));
    reset(scenarioGridColumnRenderer);
    cell = new ScenarioGridCell(new ScenarioGridCellValue(MULTIPART_VALUE));
    ((ScenarioGridCell) cell).setErrorMode(true);
    retrieved = scenarioGridColumnRenderer.renderCell(cell, contextMock);
    assertNotNull(retrieved);
    verify(scenarioGridColumnRenderer, never()).getCollectionString(anyString(), anyBoolean());
    verify(scenarioGridColumnRenderer, times(1)).internalRenderCell(any(), eq(contextMock), eq(errorTextMock), eq(MULTIPART_VALUE));
    reset(scenarioGridColumnRenderer);
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) Matchers.anyString(org.mockito.Matchers.anyString) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue) Test(org.junit.Test)

Example 5 with ScenarioGridCell

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell in project drools-wb by kiegroup.

the class AbstractScesimGridModel method setCellValue.

@Override
public Range setCellValue(int rowIndex, int columnIndex, GridCellValue<?> value) {
    return setCell(rowIndex, columnIndex, () -> {
        ScenarioGridCell newCell = new ScenarioGridCell((ScenarioGridCellValue) value);
        FactMapping factMappingByIndex = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
        if (ScenarioSimulationSharedUtils.isCollectionOrMap((factMappingByIndex.getClassName()))) {
            newCell.setListMap(ScenarioSimulationSharedUtils.isList((factMappingByIndex.getClassName())));
        }
        return newCell;
    });
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)

Aggregations

ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)9 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)6 ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)6 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)4 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)3 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)3 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)3 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)2 Test (org.junit.Test)2 Group (com.ait.lienzo.client.core.shape.Group)1 Text (com.ait.lienzo.client.core.shape.Text)1 EventBus (com.google.gwt.event.shared.EventBus)1 JSONString (com.google.gwt.json.client.JSONString)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1