Search in sources :

Example 6 with ScenarioGridCellValue

use of org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue in project drools-wb by kiegroup.

the class ScenarioGridModel method insertRowGridOnly.

/**
 * This method <i>insert</i> a row to the grid and populate it with values taken from given <code>Scenario</code>
 * @param row
 */
@Override
public void insertRowGridOnly(final int rowIndex, final GridRow row, final Scenario scenario) {
    insertRowGridOnly(rowIndex, row);
    scenario.getUnmodifiableFactMappingValues().forEach(value -> {
        FactIdentifier factIdentifier = value.getFactIdentifier();
        ExpressionIdentifier expressionIdentifier = value.getExpressionIdentifier();
        if (value.getRawValue() == null || value.getRawValue() instanceof String) {
            // Let' put a placeholder
            String stringValue = (String) value.getRawValue();
            int columnIndex = abstractScesimModel.getScesimModelDescriptor().getIndexByIdentifier(factIdentifier, expressionIdentifier);
            final FactMapping factMappingByIndex = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
            String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).getPlaceHolder();
            setCell(rowIndex, columnIndex, () -> {
                ScenarioGridCell newCell = new ScenarioGridCell(new ScenarioGridCellValue(stringValue, placeHolder));
                if (ScenarioSimulationSharedUtils.isCollectionOrMap((factMappingByIndex.getClassName()))) {
                    newCell.setListMap(ScenarioSimulationSharedUtils.isList((factMappingByIndex.getClassName())));
                }
                return newCell;
            });
        } else {
            throw new UnsupportedOperationException("Only string is supported at the moment");
        }
    });
    updateIndexColumn();
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 7 with ScenarioGridCellValue

use of org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue in project drools-wb by kiegroup.

the class BackgroundGridModel method insertRowGridOnly.

/**
 * This method <i>insert</i> a row to the grid and populate it with values taken from given <code>Scenario</code>
 * @param row
 */
@Override
public void insertRowGridOnly(final int rowIndex, final GridRow row, final BackgroundData abstractScesimData) {
    insertRowGridOnly(rowIndex, row);
    abstractScesimData.getUnmodifiableFactMappingValues().forEach(value -> {
        FactIdentifier factIdentifier = value.getFactIdentifier();
        ExpressionIdentifier expressionIdentifier = value.getExpressionIdentifier();
        if (value.getRawValue() == null || value.getRawValue() instanceof String) {
            String stringValue = (String) value.getRawValue();
            int columnIndex = abstractScesimModel.getScesimModelDescriptor().getIndexByIdentifier(factIdentifier, expressionIdentifier);
            final FactMapping factMappingByIndex = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
            String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).getPlaceHolder();
            setCell(rowIndex, columnIndex, () -> {
                ScenarioGridCell newCell = new ScenarioGridCell(new ScenarioGridCellValue(stringValue, placeHolder));
                if (ScenarioSimulationSharedUtils.isCollectionOrMap((factMappingByIndex.getClassName()))) {
                    newCell.setListMap(ScenarioSimulationSharedUtils.isList((factMappingByIndex.getClassName())));
                }
                return newCell;
            });
        } else {
            throw new UnsupportedOperationException("Only string is supported at the moment");
        }
    });
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 8 with ScenarioGridCellValue

use of org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue in project drools-wb by kiegroup.

the class SetGridCellValueCommand method internalExecute.

@Override
protected void internalExecute(ScenarioSimulationContext context) {
    final ScenarioSimulationContext.Status status = context.getStatus();
    AbstractScesimModel<AbstractScesimData> abstractScesimModel = context.getAbstractScesimModelByGridWidget(gridWidget);
    int columnIndex = status.getColumnIndex();
    FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
    ScenarioGridColumn selectedColumn = (ScenarioGridColumn) context.getAbstractScesimGridModelByGridWidget(gridWidget).getColumns().get(columnIndex);
    String placeholder = ScenarioSimulationUtils.getPlaceHolder(selectedColumn.isInstanceAssigned(), selectedColumn.isPropertyAssigned(), factMapping.getFactMappingValueType(), factMapping.getClassName());
    context.getAbstractScesimGridModelByGridWidget(gridWidget).setCellValue(status.getRowIndex(), columnIndex, new ScenarioGridCellValue(status.getGridCellValue(), placeholder));
    context.getAbstractScesimGridModelByGridWidget(gridWidget).resetError(status.getRowIndex(), columnIndex);
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Aggregations

ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)8 ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)7 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)6 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)6 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)4 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)4 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)3 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)3 EventBus (com.google.gwt.event.shared.EventBus)2 AbstractMap (java.util.AbstractMap)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 OptionalDouble (java.util.OptionalDouble)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2