use of org.uberfire.ext.wires.core.grids.client.model.GridData.SelectedCell 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);
}
}
Aggregations