use of org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent in project drools-wb by kiegroup.
the class ScenarioSimulationEventHandler method onEvent.
@Override
public void onEvent(SetPropertyHeaderEvent event) {
if (context.getAbstractScesimGridModelByGridWidget(event.getGridWidget()).getSelectedColumn() == null) {
return;
}
if (context.getAbstractScesimGridModelByGridWidget(event.getGridWidget()).isAlreadyAssignedProperty(event.getPropertyNameElements())) {
String value;
if (Objects.equals(FactMappingValueType.EXPRESSION, event.getFactMappingValueType())) {
value = ConstantHolder.EXPRESSION;
} else {
value = String.join(".", event.getPropertyNameElements());
}
onEvent(new ScenarioNotificationEvent("Property \"" + value + "\" already assigned", NotificationEvent.NotificationType.ERROR));
return;
}
context.getStatus().setFullPackage(event.getFullPackage());
context.getStatus().setClassName(event.getFactType());
context.getStatus().setPropertyNameElements(event.getPropertyNameElements());
context.getStatus().setValueClassName(event.getValueClassName());
context.getStatus().setImportPrefix(event.getImportPrefix());
if (isSameFactProperty(event.getGridWidget(), event.getPropertyNameElements(), event.getFactMappingValueType()) && isSameSelectedColumnType(event.getGridWidget(), event.getValueClassName())) {
return;
} else {
if (isSelectedColumnEmpty(event.getGridWidget())) {
commonExecution(new SetPropertyHeaderCommand(event.getGridWidget(), event.getFactMappingValueType()), true);
} else {
if (isSameSelectedColumnType(event.getGridWidget(), event.getValueClassName()) && !ScenarioSimulationSharedUtils.isCollectionOrMap(event.getValueClassName())) {
showPreserveDeletePopup(event);
} else {
showDeletePopup(event);
}
}
}
}
use of org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent 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))));
}
Aggregations