use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class AbstractScesimGridModel method getInstanceLimits.
/**
* This methods returns the <code>Range</code> of a <b>single</b> block of columns of the same instance/data object.
* A <code>single</code> block is made of all the columns immediately to the left and right of the selected one with the same "label".
* If there is another column with the same "label" but separated by a different column, it is not part of the group.
* @param columnIndex
* @param columnIndexStart the leftmost index to consider when evaluating the range
* @return
*/
protected Range getInstanceLimits(int columnIndex, int columnIndexStart) {
final ScenarioGridColumn column = (ScenarioGridColumn) columns.get(columnIndex);
final String originalColumnGroup = column.getInformationHeaderMetaData().getColumnGroup();
final ScenarioHeaderMetaData selectedInformationHeaderMetaData = column.getInformationHeaderMetaData();
String originalColumnTitle = selectedInformationHeaderMetaData.getTitle();
int leftPosition = columnIndex;
while (leftPosition > columnIndexStart && ((ScenarioGridColumn) columns.get(leftPosition - 1)).getInformationHeaderMetaData().getColumnGroup().equals(originalColumnGroup) && ((ScenarioGridColumn) columns.get(leftPosition - 1)).getInformationHeaderMetaData().getTitle().equals(originalColumnTitle)) {
leftPosition--;
}
int rightPosition = columnIndex;
while (rightPosition < columns.size() - 1 && ((ScenarioGridColumn) columns.get(rightPosition + 1)).getInformationHeaderMetaData().getColumnGroup().equals(originalColumnGroup) && ((ScenarioGridColumn) columns.get(rightPosition + 1)).getInformationHeaderMetaData().getTitle().equals(originalColumnTitle)) {
rightPosition++;
}
return new Range(leftPosition, rightPosition);
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn 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.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn 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.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class ScenarioContextMenuRegistry method manageRightClick.
public boolean manageRightClick(final ScenarioGrid scenarioGrid, final int clientXPosition, final int clientYPosition, final Integer uiRowIndex, final Integer uiColumnIndex, final boolean isHeader) {
scenarioGrid.clearSelections();
ScenarioGridColumn scenarioGridColumn = (ScenarioGridColumn) scenarioGrid.getModel().getColumns().get(uiColumnIndex);
if (scenarioGridColumn == null) {
return false;
}
if (isHeader) {
return manageHeaderRightClick(scenarioGrid, clientXPosition, clientYPosition, uiRowIndex, uiColumnIndex);
} else {
return manageBodyRightClickLocal(scenarioGrid, clientXPosition, clientYPosition, uiRowIndex, uiColumnIndex);
}
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn 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");
}
});
}
Aggregations