Search in sources :

Example 6 with ScenarioGridColumn

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;
        });
    });
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 7 with ScenarioGridColumn

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));
        });
    });
}
Also used : Arrays(java.util.Arrays) ScenarioNotificationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) FactMappingValueType(org.drools.scenariosimulation.api.model.FactMappingValueType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationUtils(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils) BaseSingletonDOMElementFactory(org.uberfire.ext.wires.core.grids.client.widget.dom.single.impl.BaseSingletonDOMElementFactory) EventBus(com.google.gwt.event.shared.EventBus) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) ScenarioHeaderTextBoxSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioHeaderTextBoxSingletonDOMElementFactory) Optional(java.util.Optional) ScenarioSimulationEditorConstants(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants) ReloadTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.ReloadTestToolsEvent) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridReloadEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioGridReloadEvent) IntStream(java.util.stream.IntStream) ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias) CollectionEditorSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.CollectionEditorSingletonDOMElementFactory) FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) OptionalDouble(java.util.OptionalDouble) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) ScenarioCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioCellTextAreaSingletonDOMElementFactory) ScenarioExpressionCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioExpressionCellTextAreaSingletonDOMElementFactory) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) AbstractMap(java.util.AbstractMap) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Collections(java.util.Collections) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 8 with ScenarioGridColumn

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));
    }
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Arrays(java.util.Arrays) ScenarioNotificationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) FactMappingValueType(org.drools.scenariosimulation.api.model.FactMappingValueType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationUtils(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils) BaseSingletonDOMElementFactory(org.uberfire.ext.wires.core.grids.client.widget.dom.single.impl.BaseSingletonDOMElementFactory) EventBus(com.google.gwt.event.shared.EventBus) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) ScenarioHeaderTextBoxSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioHeaderTextBoxSingletonDOMElementFactory) Optional(java.util.Optional) ScenarioSimulationEditorConstants(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants) ReloadTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.ReloadTestToolsEvent) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridReloadEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioGridReloadEvent) IntStream(java.util.stream.IntStream) ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias) CollectionEditorSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.CollectionEditorSingletonDOMElementFactory) FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) OptionalDouble(java.util.OptionalDouble) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) ScenarioCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioCellTextAreaSingletonDOMElementFactory) ScenarioExpressionCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioExpressionCellTextAreaSingletonDOMElementFactory) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) AbstractMap(java.util.AbstractMap) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Collections(java.util.Collections) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 9 with ScenarioGridColumn

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));
    }
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Arrays(java.util.Arrays) ScenarioNotificationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) FactMappingValueType(org.drools.scenariosimulation.api.model.FactMappingValueType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationUtils(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils) BaseSingletonDOMElementFactory(org.uberfire.ext.wires.core.grids.client.widget.dom.single.impl.BaseSingletonDOMElementFactory) EventBus(com.google.gwt.event.shared.EventBus) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) ScenarioHeaderTextBoxSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioHeaderTextBoxSingletonDOMElementFactory) Optional(java.util.Optional) ScenarioSimulationEditorConstants(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants) ReloadTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.ReloadTestToolsEvent) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridReloadEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioGridReloadEvent) IntStream(java.util.stream.IntStream) ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias) CollectionEditorSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.CollectionEditorSingletonDOMElementFactory) FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) OptionalDouble(java.util.OptionalDouble) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) ScenarioCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioCellTextAreaSingletonDOMElementFactory) ScenarioExpressionCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioExpressionCellTextAreaSingletonDOMElementFactory) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) AbstractMap(java.util.AbstractMap) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Collections(java.util.Collections) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 10 with ScenarioGridColumn

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);
    }
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Aggregations

ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)32 ScenarioHeaderMetaData (org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData)10 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)9 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)8 ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)7 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)7 List (java.util.List)6 Objects (java.util.Objects)6 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 ExpressionElement (org.drools.scenariosimulation.api.model.ExpressionElement)6 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)6 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)6 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)6 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)6 Collections (java.util.Collections)5 Optional (java.util.Optional)5 Set (java.util.Set)5