use of org.drools.scenariosimulation.api.model.ExpressionIdentifier in project drools-wb by kiegroup.
the class AbstractScesimGridModel method commonAddColumn.
/**
* This method <i>add</i> or <i>insert</i> a new column to the grid <b>and</b> to the underlying model, depending on the index value.
* If index == -1 -> add, otherwise insert.
* @param index
* @param column
* @param ei
*/
protected void commonAddColumn(final int index, final GridColumn<?> column, ExpressionIdentifier ei) {
ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
String instanceTitle = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getTitle();
String propertyTitle = ((ScenarioGridColumn) column).getPropertyHeaderMetaData().getTitle();
final int columnIndex = index == -1 ? getColumnCount() : index;
try {
final FactMapping createdFactMapping = simulationDescriptor.addFactMapping(columnIndex, instanceTitle, ((ScenarioGridColumn) column).getFactIdentifier(), ei);
createdFactMapping.setExpressionAlias(propertyTitle);
if (index == -1) {
// This is actually an append
super.appendColumn(column);
} else {
super.insertColumn(index, column);
}
final Range instanceLimits = getInstanceLimits(columnIndex);
IntStream.range(instanceLimits.getMinRowIndex(), instanceLimits.getMaxRowIndex() + 1).filter(currentIndex -> currentIndex != columnIndex).forEach(currentIndex -> simulationDescriptor.getFactMappingByIndex(currentIndex).setFactAlias(createdFactMapping.getFactAlias()));
} catch (Exception e) {
eventBus.fireEvent(new ScenarioNotificationEvent("Error during column creation: " + e.getMessage(), NotificationEvent.NotificationType.ERROR));
eventBus.fireEvent(new ScenarioGridReloadEvent(getGridWidget()));
return;
}
final List<E> unmodifiableScesimData = abstractScesimModel.getUnmodifiableData();
String placeHolder = ((ScenarioGridColumn) column).getPlaceHolder();
IntStream.range(0, unmodifiableScesimData.size()).forEach(rowIndex -> setCell(rowIndex, columnIndex, () -> new ScenarioGridCell(new ScenarioGridCellValue(null, placeHolder))));
}
use of org.drools.scenariosimulation.api.model.ExpressionIdentifier 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.ExpressionIdentifier 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.ExpressionIdentifier in project drools-wb by kiegroup.
the class ScenarioGridTest method setup.
@Before
public void setup() {
simulation = getSimulation();
when(scenarioGridColumnMock.getPropertyHeaderMetaData()).thenReturn(propertyHeaderMetadataMock);
when(scenarioGridModelMock.getAbstractScesimModel()).thenReturn(Optional.of(simulation));
when(scenarioGridModelMock.getGridWidget()).thenReturn(GridWidget.SIMULATION);
when(scenarioGridModelMock.getScenarioExpressionCellTextAreaSingletonDOMElementFactory()).thenReturn(expressionCellTextAreaSingletonDOMElementFactoryMock);
when(scenarioGridModelMock.getCollectionEditorSingletonDOMElementFactory()).thenReturn(collectionEditorSingletonDOMElementFactory);
factIdentifierGiven = FactIdentifier.create("GIVEN", "GIVEN");
factIdentifierInteger = FactIdentifier.create("Integer", "java.lang.Integer");
factMappingDescription = new FactMapping(EXPRESSION_ALIAS_DESCRIPTION, FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
factMappingGiven = new FactMapping(EXPRESSION_ALIAS_GIVEN, factIdentifierGiven, new ExpressionIdentifier("GIVEN", FactMappingType.GIVEN));
factMappingInteger = new FactMapping(EXPRESSION_ALIAS_INTEGER, factIdentifierInteger, new ExpressionIdentifier("GIVEN", FactMappingType.GIVEN));
scenarioGridSpy = spy(new ScenarioGrid(scenarioGridModelMock, scenarioGridLayerMock, scenarioGridRendererMock, scenarioContextMenuRegistryMock) {
@Override
protected <T extends AbstractScesimData> void appendRow(int rowIndex, T scesimData) {
// do nothing
}
@Override
protected ScenarioSimulationBuilders.HeaderBuilder getHeaderBuilderLocal(String instanceTitle, String propertyTitle, String columnId, String columnGroup, FactMappingType factMappingType) {
return headerBuilderMock;
}
@Override
protected ScenarioGridColumn getScenarioGridColumnLocal(ScenarioSimulationBuilders.HeaderBuilder headerBuilder, String placeHolder) {
return scenarioGridColumnMock;
}
@Override
protected BaseGridRendererHelper getBaseGridRendererHelper() {
return rendererHelperMock;
}
@Override
public Viewport getViewport() {
return viewportMock;
}
@Override
protected ScenarioHeaderMetaData getColumnScenarioHeaderMetaData(final ScenarioGridColumn scenarioGridColumn, final int rowIndex) {
return propertyHeaderMetadataMock;
}
@Override
protected EnableTestToolsEvent getEnableTestToolsEvent(final ScenarioGrid scenarioGrid, final ScenarioGridColumn scenarioGridColumn, final ScenarioHeaderMetaData scenarioHeaderMetaData, int uiColumnIndex, String group) {
return new EnableTestToolsEvent();
}
@Override
public Layer getLayer() {
return scenarioGridLayerMock;
}
});
when(rendererHelperMock.getRenderingInformation()).thenReturn(renderingInformationMock);
when(renderingInformationMock.getHeaderRowsHeight()).thenReturn(HEADER_ROWS_HEIGHT);
when(renderingInformationMock.getFloatingBlockInformation()).thenReturn(floatingBlockInformationMock);
when(propertyHeaderMetadataMock.getColumnGroup()).thenReturn(GRID_COLUMN_GROUP);
scenarioGridSpy.setEventBus(eventBusMock);
}
Aggregations