use of org.drools.scenariosimulation.api.model.FactMapping 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();
}
use of org.drools.scenariosimulation.api.model.FactMapping 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");
}
});
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class ScenarioSimulationMainGridPanelMouseMoveHandler method manageBodyCoordinates.
@Override
protected boolean manageBodyCoordinates(Integer uiRowIndex, Integer uiColumnIndex) {
/* In this case, the mouse is out ot the GridLayer, then return false, without perform any action */
if (uiColumnIndex == -1 || uiRowIndex == -1) {
return false;
}
/* If the mouse position is the same of the previous one and the popover is already open, it does nothing.
* It returns true because the click happened on an column of a grid row */
if (uiRowIndex.equals(currentlyShownBodyRowIndex) && uiColumnIndex.equals(currentlyShownBodyColumnIndex) && errorReportPopupPresenter.isShown()) {
return true;
}
/* It updates the coordinates of the current shown cell */
currentlyShownBodyRowIndex = uiRowIndex;
currentlyShownBodyColumnIndex = uiColumnIndex;
final Optional<AbstractScesimModel<? extends AbstractScesimData>> optionalAbstractScesimModel = scenarioGrid.getModel().getAbstractScesimModel();
final AbstractScesimModel<? extends AbstractScesimData> scesimModel = optionalAbstractScesimModel.orElseThrow(IllegalStateException::new);
final AbstractScesimData scenarioByIndex = scesimModel.getDataByIndex(uiRowIndex);
final FactMapping factMapping = scesimModel.getScesimModelDescriptor().getFactMappingByIndex(uiColumnIndex);
final Optional<FactMappingValue> factMappingValueOptional = scenarioByIndex.getFactMappingValue(factMapping);
factMappingValueOptional.ifPresent(factMappingValue -> manageFactMappingValue(factMappingValue, uiRowIndex, uiColumnIndex));
return true;
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class SimulationGridModelTest method insertRowGridOnly.
@Test
public void insertRowGridOnly() {
int setCellInvocations = scenarioMock.getUnmodifiableFactMappingValues().size();
scenarioGridModelSpy.insertRowGridOnly(ROW_INDEX, gridRowMock, scenarioMock);
verify(scenarioGridModelSpy, atLeast(1)).checkSimulation();
verify(scenarioGridModelSpy, never()).insertRow(eq(ROW_INDEX), eq(gridRowMock));
verify(scenarioGridModelSpy, times(1)).updateIndexColumn();
verify(scenarioGridModelSpy, times(setCellInvocations)).setCell(anyInt(), anyInt(), isA(Supplier.class));
reset(scenarioGridModelSpy);
FactMapping factMappingByIndexMock = mock(FactMapping.class);
when(factMappingByIndexMock.getClassName()).thenReturn(List.class.getName());
when(simulationDescriptorMock.getFactMappingByIndex(2)).thenReturn(factMappingByIndexMock);
scenarioGridModelSpy.insertRowGridOnly(ROW_INDEX, gridRowMock, scenarioMock);
verify(scenarioGridModelSpy, atLeast(1)).checkSimulation();
verify(scenarioGridModelSpy, never()).insertRow(eq(ROW_INDEX), eq(gridRowMock));
verify(scenarioGridModelSpy, times(1)).updateIndexColumn();
verify(scenarioGridModelSpy, times(setCellInvocations)).setCell(anyInt(), anyInt(), isA(Supplier.class));
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class ScenarioSimulationEditorPresenterTest method cleanReadOnlyColumn.
@Test
public void cleanReadOnlyColumn() {
Simulation simulation = new Simulation();
ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
FactMapping test1 = simulationDescriptor.addFactMapping(FactIdentifier.create("test1", String.class.getCanonicalName()), ExpressionIdentifier.create("", FactMappingType.GIVEN));
FactMapping test2 = simulationDescriptor.addFactMapping(FactIdentifier.create("test2", String.class.getCanonicalName()), ExpressionIdentifier.create("", FactMappingType.GIVEN));
test1.addExpressionElement("test", String.class.getCanonicalName());
Scenario scenario = simulation.addData();
scenario.addMappingValue(test1.getFactIdentifier(), test1.getExpressionIdentifier(), LOWER_CASE_VALUE);
scenario.addMappingValue(test2.getFactIdentifier(), test2.getExpressionIdentifier(), LOWER_CASE_VALUE);
presenterSpy.cleanReadOnlyColumn(simulation);
assertNotNull(scenario.getFactMappingValue(test1.getFactIdentifier(), test1.getExpressionIdentifier()).get().getRawValue());
assertNull(scenario.getFactMappingValue(test2.getFactIdentifier(), test2.getExpressionIdentifier()).get().getRawValue());
}
Aggregations