use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn 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;
});
});
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class AbstractScesimGridModel method updateIndexColumn.
protected void updateIndexColumn() {
final Optional<GridColumn<?>> indexColumn = // Retrieving the column list
this.getColumns().stream().filter(// filtering by group name
gridColumn -> ((ScenarioGridColumn) gridColumn).getInformationHeaderMetaData().getTitle().equals(FactIdentifier.INDEX.getName())).findFirst();
indexColumn.ifPresent(column -> {
int indexOfColumn = getColumns().indexOf(column);
IntStream.range(0, getRowCount()).forEach(rowIndex -> {
String value = String.valueOf(rowIndex + 1);
setCellValue(rowIndex, indexOfColumn, new ScenarioGridCellValue(value));
});
});
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class AbstractScesimGridModel method checkValidAndUniqueInstanceHeaderTitle.
/**
* Verify the given value is not already used as instance header name <b>between different groups</b>
* @param instanceHeaderCellValue
* @param columnIndex
* @throws IllegalArgumentException if the given <b>instanceHeaderCellValue</b> contains a <i>dot</i> <b>OR</b>
* it has already been used inside the <b>group (GIVEN/EXPECT)</b> of the given column
*/
protected void checkValidAndUniqueInstanceHeaderTitle(String instanceHeaderCellValue, int columnIndex) {
if (instanceHeaderCellValue.contains(".")) {
throw new IllegalArgumentException(ScenarioSimulationEditorConstants.INSTANCE.instanceTitleWithPeriodsError());
}
Range instanceLimits = getInstanceLimits(columnIndex);
ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier();
if (IntStream.range(0, getColumnCount()).filter(index -> index < instanceLimits.getMinRowIndex() || index > instanceLimits.getMaxRowIndex()).filter(index -> !Objects.equals(factIdentifier, simulationDescriptor.getFactMappingByIndex(index).getFactIdentifier())).mapToObj(index -> (ScenarioGridColumn) getColumns().get(index)).filter(elem -> elem.getInformationHeaderMetaData() != null).map(ScenarioGridColumn::getInformationHeaderMetaData).anyMatch(elem -> Objects.equals(elem.getTitle(), instanceHeaderCellValue))) {
throw new IllegalArgumentException(ScenarioSimulationEditorConstants.INSTANCE.instanceTitleAssignedError(instanceHeaderCellValue));
}
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class AbstractScesimGridModel method checkUniquePropertyHeaderTitle.
/**
* Verify if the given value is not already used as property header name <b>inside the same instance</b>
* @param propertyHeaderCellValue
* @param columnIndex
* @throws IllegalArgumentException if the given <b>propertyHeaderCellValue</b> has already been used
* inside the <b>instance</b> of the given column
*/
protected void checkUniquePropertyHeaderTitle(String propertyHeaderCellValue, int columnIndex) {
ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier();
if (IntStream.range(0, getColumnCount()).filter(index -> index != columnIndex).filter(index -> Objects.equals(factIdentifier, simulationDescriptor.getFactMappingByIndex(index).getFactIdentifier())).mapToObj(index -> (ScenarioGridColumn) getColumns().get(index)).filter(elem -> elem.getPropertyHeaderMetaData() != null).map(ScenarioGridColumn::getPropertyHeaderMetaData).anyMatch(elem -> Objects.equals(elem.getTitle(), propertyHeaderCellValue))) {
throw new IllegalArgumentException(ScenarioSimulationEditorConstants.INSTANCE.propertyTitleAssignedError(propertyHeaderCellValue));
}
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class AbstractScenarioSimulationGridPanelHandler method manageCoordinates.
/**
* It calculates the cell related to the given canvas coordinates. These coordinates will be handled by
* <code>manageHeaderCoordinates</code> if found cell is an HEADER or <code>manageBodyCoordinates</code> otherwise.
* @param canvasX
* @param canvasY
* @return
*/
protected boolean manageCoordinates(final int canvasX, final int canvasY) {
final Point2D gridClickPoint = convertDOMToGridCoordinateLocal(canvasX, canvasY);
Integer uiRowIndex = getUiHeaderRowIndexLocal(gridClickPoint);
boolean isHeader = true;
if (uiRowIndex == null) {
uiRowIndex = getUiRowIndexLocal(gridClickPoint.getY());
isHeader = false;
}
final Integer uiColumnIndex = getUiColumnIndexLocal(gridClickPoint.getX());
ScenarioGridColumn scenarioGridColumn = uiColumnIndex != null ? (ScenarioGridColumn) scenarioGrid.getModel().getColumns().get(uiColumnIndex) : null;
if (isHeader) {
return manageHeaderCoordinates(uiColumnIndex, scenarioGridColumn, gridClickPoint);
} else {
return (uiRowIndex == null || uiColumnIndex == null) ? manageBodyCoordinates(-1, -1) : manageBodyCoordinates(uiRowIndex, uiColumnIndex);
}
}
Aggregations