Search in sources :

Example 11 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.

the class ScenarioInvokeContextMenuForSelectedCell method perform.

@Override
public boolean perform(final GridWidget gridWidget, final boolean isShiftKeyDown, final boolean isControlKeyDown) {
    final GridData model = gridWidget.getModel();
    if (!model.getSelectedHeaderCells().isEmpty() && !model.getSelectedCells().isEmpty()) {
        return false;
    }
    GridData.SelectedCell origin = null;
    boolean isHeader = false;
    if (!model.getSelectedHeaderCells().isEmpty()) {
        origin = model.getSelectedHeaderCells().get(0);
        isHeader = true;
    } else if (model.getSelectedCells().size() == 1) {
        origin = model.getSelectedCellsOrigin();
    }
    if (origin == null) {
        return false;
    }
    final int uiRowIndex = origin.getRowIndex();
    final int uiColumnIndex = ColumnIndexUtilities.findUiColumnIndex(model.getColumns(), origin.getColumnIndex());
    final GridColumn<?> column = model.getColumns().get(uiColumnIndex);
    if (column instanceof ScenarioGridColumn) {
        final Point2D middleXYCell = this.getMiddleXYCell(gridWidget, column, isHeader, uiRowIndex, gridLayer);
        return scenarioContextMenuRegistry.manageRightClick((ScenarioGrid) gridWidget, (int) middleXYCell.getX(), (int) middleXYCell.getY(), uiRowIndex, uiColumnIndex, isHeader);
    }
    return false;
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 12 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.

the class ScenarioSimulationGridWidgetMouseEventHandler method handleHeaderCell.

@Override
public boolean handleHeaderCell(final GridWidget gridWidget, final Point2D relativeLocation, final int uiHeaderRowIndex, final int uiHeaderColumnIndex, final AbstractNodeMouseEvent event) {
    // Get column information
    final double cx = relativeLocation.getX();
    final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper();
    final BaseGridRendererHelper.ColumnInformation ci = rendererHelper.getColumnInformation(cx);
    final GridColumn<?> column = ci.getColumn();
    if (column == null) {
        return false;
    }
    final ScenarioHeaderMetaData headerMetaData = (ScenarioHeaderMetaData) column.getHeaderMetaData().get(uiHeaderRowIndex);
    final GridData gridData = gridWidget.getModel();
    if (!gridData.getSelectedHeaderCells().isEmpty() && editSupportedLocal(headerMetaData.getSupportedEditAction(), event)) {
        final GridData.SelectedCell firstSelectedHeaderCell = gridData.getSelectedHeaderCells().get(0);
        final Optional<GridColumn<?>> firstSelectedColumnOptional = gridData.getColumns().stream().filter(col -> col.getIndex() == firstSelectedHeaderCell.getColumnIndex()).findFirst();
        final int firstSelectedColumnPosition = gridData.getColumns().indexOf(firstSelectedColumnOptional.orElseThrow(IllegalStateException::new));
        return startEditLocal((ScenarioGrid) gridWidget, firstSelectedColumnPosition, (ScenarioGridColumn) column, uiHeaderRowIndex, true);
    }
    return true;
}
Also used : GridCellEditAction(org.uberfire.ext.wires.core.grids.client.model.GridCellEditAction) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) DefaultGridWidgetEditCellMouseEventHandler(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.DefaultGridWidgetEditCellMouseEventHandler) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) AbstractNodeMouseEvent(com.ait.lienzo.client.core.event.AbstractNodeMouseEvent) GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) Objects(java.util.Objects) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) BaseGridRendererHelper(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.impl.BaseGridRendererHelper) Point2D(com.ait.lienzo.client.core.types.Point2D) Optional(java.util.Optional) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) BaseGridRendererHelper(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.impl.BaseGridRendererHelper)

Example 13 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.

the class ScenarioSimulationKeyboardEditHandler method perform.

@Override
public boolean perform(final GridWidget gridWidget, final boolean isShiftKeyDown, final boolean isControlKeyDown) {
    ScenarioGrid scenarioGrid = (ScenarioGrid) gridWidget;
    final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> scenarioGridModel = scenarioGrid.getModel();
    // Allows editing only if a single cell is selected
    if (!scenarioGridModel.getSelectedHeaderCells().isEmpty() && !scenarioGridModel.getSelectedCells().isEmpty()) {
        return false;
    }
    GridData.SelectedCell selectedCell = null;
    boolean isHeader = true;
    if (!scenarioGridModel.getSelectedHeaderCells().isEmpty()) {
        selectedCell = scenarioGridModel.getSelectedHeaderCells().get(0);
    } else if (scenarioGridModel.getSelectedCells().size() == 1) {
        selectedCell = scenarioGridModel.getSelectedCellsOrigin();
        isHeader = false;
    }
    if (selectedCell == null) {
        return false;
    }
    final int uiRowIndex = selectedCell.getRowIndex();
    final int uiColumnIndex = ColumnIndexUtilities.findUiColumnIndex(scenarioGridModel.getColumns(), selectedCell.getColumnIndex());
    ScenarioGridColumn scenarioGridColumn = (ScenarioGridColumn) scenarioGridModel.getColumns().get(uiColumnIndex);
    if (scenarioGridColumn == null) {
        return false;
    }
    return startEdit(scenarioGrid, uiColumnIndex, uiRowIndex, scenarioGridColumn, isHeader);
}
Also used : ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 14 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.

the class ScenarioContextMenuRegistry method manageHeaderRightClick.

/**
 * This method check if the click happened on an <b>header</b> cell. If it is so, manage it and returns <code>true</code>,
 * otherwise returns <code>false</code>
 * @param scenarioGrid
 * @param left
 * @param top
 * @param uiHeaderRowIndex - coordinates relative to the grid top left corner
 * @param uiColumnIndex
 * @return
 */
private boolean manageHeaderRightClick(final ScenarioGrid scenarioGrid, final int left, final int top, final Integer uiHeaderRowIndex, final Integer uiColumnIndex) {
    final ScenarioGridColumn column = (ScenarioGridColumn) scenarioGrid.getModel().getColumns().get(uiColumnIndex);
    if (column == null) {
        return false;
    }
    ScenarioHeaderMetaData columnMetadata = ScenarioSimulationGridHeaderUtilities.getColumnScenarioHeaderMetaData(column, uiHeaderRowIndex);
    if (columnMetadata == null) {
        return false;
    }
    if (uiHeaderRowIndex == null) {
        return false;
    }
    boolean showDuplicateInstance = scenarioGrid.getType().equals(ScenarioSimulationModel.Type.RULE);
    String group = ScenarioSimulationUtils.getOriginalColumnGroup(columnMetadata.getColumnGroup());
    /* The first case managed, empty string, is related to clicking on the first header row, the one containing
           GIVEN or EXPECT labels. In this case, the menu to show depends on columnMetadata.getTitle() value.
           All other cases, "GIVEN" and "EXPECT" groups names, manage the other headers rows.
         */
    switch(group) {
        case "":
            switch(columnMetadata.getTitle()) {
                case "GIVEN":
                    headerGivenContextMenu.show(scenarioGrid.getGridWidget(), left, top);
                    break;
                case "EXPECT":
                    headerExpectedContextMenu.show(scenarioGrid.getGridWidget(), left, top);
                    break;
                default:
                    otherContextMenu.show(left, top);
            }
            break;
        case "GIVEN":
            givenContextMenu.show(scenarioGrid.getGridWidget(), left, top, uiColumnIndex, group, Objects.equals(columnMetadata.getMetadataType(), ScenarioHeaderMetaData.MetadataType.PROPERTY), showDuplicateInstance);
            break;
        case "EXPECT":
            expectedContextMenu.show(scenarioGrid.getGridWidget(), left, top, uiColumnIndex, group, Objects.equals(columnMetadata.getMetadataType(), ScenarioHeaderMetaData.MetadataType.PROPERTY), showDuplicateInstance);
            break;
        default:
            otherContextMenu.show(left, top);
    }
    scenarioGrid.setSelectedColumnAndHeader(uiHeaderRowIndex, uiColumnIndex);
    return true;
}
Also used : ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 15 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.

the class ScenarioContextMenuRegistry method manageScenarioBodyRightClick.

/**
 * This method check if the click happened on an <b>body</b> cell. If it is so, manage it and returns <code>true</code>,
 * otherwise returns <code>false</code>
 * @param scenarioGrid
 * @param left
 * @param top
 * @param uiRowIndex
 * @param uiColumnIndex
 * @return
 */
private boolean manageScenarioBodyRightClick(final ScenarioGrid scenarioGrid, final int left, final int top, final int uiRowIndex, final int uiColumnIndex) {
    ScenarioGridColumn scenarioGridColumn = (ScenarioGridColumn) scenarioGrid.getModel().getColumns().get(uiColumnIndex);
    if (scenarioGridColumn == null) {
        return false;
    }
    gridContextMenu.show(scenarioGrid.getGridWidget(), left, top, uiRowIndex);
    scenarioGrid.setSelectedCell(uiRowIndex, uiColumnIndex);
    return true;
}
Also used : 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