Search in sources :

Example 1 with HasCellEditorControls

use of org.kie.workbench.common.dmn.client.widgets.grid.controls.HasCellEditorControls in project kie-wb-common by kiegroup.

the class UndefinedExpressionColumn method edit.

@Override
@SuppressWarnings("unchecked")
public void edit(final GridCell<String> cell, final GridBodyCellEditContext context, final Callback<GridCellValue<String>> callback) {
    final int uiRowIndex = context.getRowIndex();
    final int uiColumnIndex = context.getColumnIndex();
    final double absoluteCellX = context.getAbsoluteCellX();
    final double absoluteCellY = context.getAbsoluteCellY();
    if (cell == null) {
        return;
    }
    if (cell instanceof HasCellEditorControls) {
        final HasCellEditorControls hasControls = (HasCellEditorControls) cell;
        final Optional<HasCellEditorControls.Editor> editor = hasControls.getEditor();
        editor.ifPresent(e -> {
            e.bind(this, uiRowIndex, uiColumnIndex);
            final double[] dxy = { 0.0, 0.0 };
            final Optional<com.ait.lienzo.client.core.types.Point2D> rx = context.getRelativeLocation();
            rx.ifPresent(r -> {
                dxy[0] = r.getX();
                dxy[1] = r.getY();
            });
            cellEditorControls.show(e, (int) (absoluteCellX + dxy[0]), (int) (absoluteCellY + dxy[1]));
        });
    }
}
Also used : HasCellEditorControls(org.kie.workbench.common.dmn.client.widgets.grid.controls.HasCellEditorControls)

Example 2 with HasCellEditorControls

use of org.kie.workbench.common.dmn.client.widgets.grid.controls.HasCellEditorControls in project kie-wb-common by kiegroup.

the class DMNGridPanelContextMenuHandler method onContextMenu.

@Override
@SuppressWarnings("unchecked")
public void onContextMenu(final ContextMenuEvent event) {
    event.preventDefault();
    event.stopPropagation();
    final boolean isShiftKeyDown = event.getNativeEvent().getShiftKey();
    final boolean isControlKeyDown = event.getNativeEvent().getCtrlKey();
    final int canvasX = getRelativeX(event);
    final int canvasY = getRelativeY(event);
    final List<CandidateGridWidget> candidateGridWidgets = new ArrayList<>();
    for (GridWidget gridWidget : gridLayer.getGridWidgets()) {
        final GridData gridModel = gridWidget.getModel();
        final Point2D ap = CoordinateUtilities.convertDOMToGridCoordinate(gridWidget, new Point2D(canvasX, canvasY));
        final Integer uiRowIndex = CoordinateUtilities.getUiRowIndex(gridWidget, ap.getY());
        final Integer uiColumnIndex = CoordinateUtilities.getUiColumnIndex(gridWidget, ap.getX());
        if (uiRowIndex == null || uiColumnIndex == null) {
            continue;
        }
        final GridCell<?> cell = gridModel.getCell(uiRowIndex, uiColumnIndex);
        if (cell == null) {
            continue;
        }
        if (cell instanceof HasCellEditorControls) {
            final HasCellEditorControls hasControls = (HasCellEditorControls) cell;
            candidateGridWidgets.add(new CandidateGridWidget(ap, uiRowIndex, uiColumnIndex, gridWidget, hasControls));
        }
    }
    if (candidateGridWidgets.isEmpty()) {
        return;
    }
    // Candidate Grids are ordered bottom (least nested) to top (most nested). Therefore the last element is the more specific match.
    final CandidateGridWidget candidateGridWidget = candidateGridWidgets.get(candidateGridWidgets.size() - 1);
    final Point2D ap = candidateGridWidget.ap;
    final int uiRowIndex = candidateGridWidget.uiRowIndex;
    final int uiColumnIndex = candidateGridWidget.uiColumnIndex;
    final GridWidget gridWidget = candidateGridWidget.gridWidget;
    final HasCellEditorControls hasCellEditorControls = candidateGridWidget.hasCellEditorControls;
    final Optional<HasCellEditorControls.Editor> editor = hasCellEditorControls.getEditor();
    editor.ifPresent(e -> {
        e.bind(gridWidget, uiRowIndex, uiColumnIndex);
        cellEditorControls.show(e, (int) (ap.getX() + gridWidget.getAbsoluteX()), (int) (ap.getY() + gridWidget.getAbsoluteY()));
    });
    // If the right-click did not occur in an already selected cell, ensure the cell is selected
    final GridData gridData = gridWidget.getModel();
    final GridColumn<?> column = gridData.getColumns().get(uiColumnIndex);
    final int modelColumnIndex = column.getIndex();
    final Stream<SelectedCell> modelColumnSelectedCells = gridData.getSelectedCells().stream().filter(sc -> sc.getColumnIndex() == modelColumnIndex);
    final boolean isContextMenuCellSelectedCell = modelColumnSelectedCells.map(SelectedCell::getRowIndex).anyMatch(ri -> ri == uiRowIndex);
    if (!isContextMenuCellSelectedCell) {
        selectCell(uiRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown);
    }
}
Also used : GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) ArrayList(java.util.ArrayList) SelectedCell(org.uberfire.ext.wires.core.grids.client.model.GridData.SelectedCell) Point2D(com.ait.lienzo.client.core.types.Point2D) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) HasCellEditorControls(org.kie.workbench.common.dmn.client.widgets.grid.controls.HasCellEditorControls) DMNEditor(org.kie.workbench.common.dmn.api.qualifiers.DMNEditor)

Aggregations

HasCellEditorControls (org.kie.workbench.common.dmn.client.widgets.grid.controls.HasCellEditorControls)2 Point2D (com.ait.lienzo.client.core.types.Point2D)1 ArrayList (java.util.ArrayList)1 DMNEditor (org.kie.workbench.common.dmn.api.qualifiers.DMNEditor)1 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)1 SelectedCell (org.uberfire.ext.wires.core.grids.client.model.GridData.SelectedCell)1 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)1