@Test public void onContextMenu_WithGridWidget_WithCellValueOfWrongType() { when(nativeEvent.getClientX()).thenReturn((int) (COLUMN0_WIDTH / 2)); when(nativeEvent.getClientY()).thenReturn((int) (ROW_HEIGHT + ROW_HEIGHT / 2)); final BaseGrid gridWidget = mockGridWidget(); when(gridLayer.getGridWidgets()).thenReturn(Collections.singleton(gridWidget)); gridWidget.getModel().setCellValue(1, 0, new ExpressionCellValue(Optional.empty())); handler.onContextMenu(event); verify(cellEditorControls, never()).show(any(HasCellEditorControls.Editor.class), anyInt(), anyInt()); }
@Override @SuppressWarnings("unchecked") public void onContextMenu(final ContextMenuEvent event) { event.preventDefault(); event.stopPropagation(); final int canvasX = getRelativeXOfEvent(event); final int canvasY = getRelativeYOfEvent(event); final boolean isShiftKeyDown = event.getNativeEvent().getShiftKey(); final boolean isControlKeyDown = event.getNativeEvent().getCtrlKey(); final List<CandidateGridWidget> candidateGridWidgets = new ArrayList<>(); for (GridWidget gridWidget : gridLayer.getGridWidgets()) { if (DynamicReadOnlyUtils.isOnlyVisualChangeAllowed(gridWidget)) { continue; } final GridData gridModel = gridWidget.getModel(); final Point2D ap = convertDOMToGridCoordinate(gridWidget, new Point2D(canvasX, canvasY)); final Integer uiHeaderRowIndex = getUiHeaderRowIndex(gridWidget, ap); final Integer uiColumnIndex = getUiColumnIndex(gridWidget, ap.getX()); if (Objects.nonNull(uiHeaderRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridColumn.HeaderMetaData hasCellEditorControls = gridModel.getColumns().get(uiColumnIndex).getHeaderMetaData().get(uiHeaderRowIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiHeaderRowIndex, uiColumnIndex, hasCellEditorControls, candidateGridWidgets, () -> cellSelectionHandler.selectHeaderCellIfRequired(uiHeaderRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } final Integer uiRowIndex = getUiRowIndex(gridWidget, ap.getY()); if (Objects.nonNull(uiRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridCell<?> hasCellEditorControls = gridModel.getCell(uiRowIndex, uiColumnIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiRowIndex, uiColumnIndex, gridWidget, candidateGridWidgets, () -> cellSelectionHandler.selectCellIfRequired(uiRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } } if (candidateGridWidgets.isEmpty()) { return; } final CandidateGridWidget candidateGridWidget = candidateGridWidgets.get(candidateGridWidgets.size() - 1); final Point2D ap = candidateGridWidget.ap; final int uiRowIndex = candidateGridWidget.uiRowIndex; final int uiColumnIndex = candidateGridWidget.uiColumnIndex; final Object binding = candidateGridWidget.binding; final HasCellEditorControls hasCellEditorControls = candidateGridWidget.hasCellEditorControls; final Optional<HasCellEditorControls.Editor> editor = hasCellEditorControls.getEditor(); editor.ifPresent(e -> { candidateGridWidget.ensureCellSelectedCommand.execute(); e.bind(binding, uiRowIndex, uiColumnIndex); cellEditorControls.show(e, (int) (ap.getX()), (int) (ap.getY())); }); }
DMNGridPanelContextMenuHandler implements ContextMenuHandler { @Override @SuppressWarnings("unchecked") public void onContextMenu(final ContextMenuEvent event) { event.preventDefault(); event.stopPropagation(); final int canvasX = getRelativeXOfEvent(event); final int canvasY = getRelativeYOfEvent(event); final boolean isShiftKeyDown = event.getNativeEvent().getShiftKey(); final boolean isControlKeyDown = event.getNativeEvent().getCtrlKey(); final List<CandidateGridWidget> candidateGridWidgets = new ArrayList<>(); for (GridWidget gridWidget : gridLayer.getGridWidgets()) { if (DynamicReadOnlyUtils.isOnlyVisualChangeAllowed(gridWidget)) { continue; } final GridData gridModel = gridWidget.getModel(); final Point2D ap = convertDOMToGridCoordinate(gridWidget, new Point2D(canvasX, canvasY)); final Integer uiHeaderRowIndex = getUiHeaderRowIndex(gridWidget, ap); final Integer uiColumnIndex = getUiColumnIndex(gridWidget, ap.getX()); if (Objects.nonNull(uiHeaderRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridColumn.HeaderMetaData hasCellEditorControls = gridModel.getColumns().get(uiColumnIndex).getHeaderMetaData().get(uiHeaderRowIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiHeaderRowIndex, uiColumnIndex, hasCellEditorControls, candidateGridWidgets, () -> cellSelectionHandler.selectHeaderCellIfRequired(uiHeaderRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } final Integer uiRowIndex = getUiRowIndex(gridWidget, ap.getY()); if (Objects.nonNull(uiRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridCell<?> hasCellEditorControls = gridModel.getCell(uiRowIndex, uiColumnIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiRowIndex, uiColumnIndex, gridWidget, candidateGridWidgets, () -> cellSelectionHandler.selectCellIfRequired(uiRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } } if (candidateGridWidgets.isEmpty()) { return; } final CandidateGridWidget candidateGridWidget = candidateGridWidgets.get(candidateGridWidgets.size() - 1); final Point2D ap = candidateGridWidget.ap; final int uiRowIndex = candidateGridWidget.uiRowIndex; final int uiColumnIndex = candidateGridWidget.uiColumnIndex; final Object binding = candidateGridWidget.binding; final HasCellEditorControls hasCellEditorControls = candidateGridWidget.hasCellEditorControls; final Optional<HasCellEditorControls.Editor> editor = hasCellEditorControls.getEditor(); editor.ifPresent(e -> { candidateGridWidget.ensureCellSelectedCommand.execute(); e.bind(binding, uiRowIndex, uiColumnIndex); cellEditorControls.show(e, (int) (ap.getX()), (int) (ap.getY())); }); } }
DMNGridPanelContextMenuHandler implements ContextMenuHandler { @Override @SuppressWarnings("unchecked") public void onContextMenu(final ContextMenuEvent event) { event.preventDefault(); event.stopPropagation(); final int canvasX = getRelativeXOfEvent(event); final int canvasY = getRelativeYOfEvent(event); final boolean isShiftKeyDown = event.getNativeEvent().getShiftKey(); final boolean isControlKeyDown = event.getNativeEvent().getCtrlKey(); final List<CandidateGridWidget> candidateGridWidgets = new ArrayList<>(); for (GridWidget gridWidget : gridLayer.getGridWidgets()) { if (DynamicReadOnlyUtils.isOnlyVisualChangeAllowed(gridWidget)) { continue; } final GridData gridModel = gridWidget.getModel(); final Point2D ap = convertDOMToGridCoordinate(gridWidget, new Point2D(canvasX, canvasY)); final Integer uiHeaderRowIndex = getUiHeaderRowIndex(gridWidget, ap); final Integer uiColumnIndex = getUiColumnIndex(gridWidget, ap.getX()); if (Objects.nonNull(uiHeaderRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridColumn.HeaderMetaData hasCellEditorControls = gridModel.getColumns().get(uiColumnIndex).getHeaderMetaData().get(uiHeaderRowIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiHeaderRowIndex, uiColumnIndex, hasCellEditorControls, candidateGridWidgets, () -> cellSelectionHandler.selectHeaderCellIfRequired(uiHeaderRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } final Integer uiRowIndex = getUiRowIndex(gridWidget, ap.getY()); if (Objects.nonNull(uiRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridCell<?> hasCellEditorControls = gridModel.getCell(uiRowIndex, uiColumnIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiRowIndex, uiColumnIndex, gridWidget, candidateGridWidgets, () -> cellSelectionHandler.selectCellIfRequired(uiRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } } if (candidateGridWidgets.isEmpty()) { return; } final CandidateGridWidget candidateGridWidget = candidateGridWidgets.get(candidateGridWidgets.size() - 1); final Point2D ap = candidateGridWidget.ap; final int uiRowIndex = candidateGridWidget.uiRowIndex; final int uiColumnIndex = candidateGridWidget.uiColumnIndex; final Object binding = candidateGridWidget.binding; final HasCellEditorControls hasCellEditorControls = candidateGridWidget.hasCellEditorControls; final Optional<HasCellEditorControls.Editor> editor = hasCellEditorControls.getEditor(); editor.ifPresent(e -> { candidateGridWidget.ensureCellSelectedCommand.execute(); e.bind(binding, uiRowIndex, uiColumnIndex); cellEditorControls.show(e, (int) (ap.getX()), (int) (ap.getY())); }); } DMNGridPanelContextMenuHandler(final DMNGridLayer gridLayer,
                                   final CellEditorControlsView.Presenter cellEditorControls,
                                   final DMNGridPanelCellSelectionHandler cellSelectionHandler); }
DMNGridPanelContextMenuHandler implements ContextMenuHandler { @Override @SuppressWarnings("unchecked") public void onContextMenu(final ContextMenuEvent event) { event.preventDefault(); event.stopPropagation(); final int canvasX = getRelativeXOfEvent(event); final int canvasY = getRelativeYOfEvent(event); final boolean isShiftKeyDown = event.getNativeEvent().getShiftKey(); final boolean isControlKeyDown = event.getNativeEvent().getCtrlKey(); final List<CandidateGridWidget> candidateGridWidgets = new ArrayList<>(); for (GridWidget gridWidget : gridLayer.getGridWidgets()) { if (DynamicReadOnlyUtils.isOnlyVisualChangeAllowed(gridWidget)) { continue; } final GridData gridModel = gridWidget.getModel(); final Point2D ap = convertDOMToGridCoordinate(gridWidget, new Point2D(canvasX, canvasY)); final Integer uiHeaderRowIndex = getUiHeaderRowIndex(gridWidget, ap); final Integer uiColumnIndex = getUiColumnIndex(gridWidget, ap.getX()); if (Objects.nonNull(uiHeaderRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridColumn.HeaderMetaData hasCellEditorControls = gridModel.getColumns().get(uiColumnIndex).getHeaderMetaData().get(uiHeaderRowIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiHeaderRowIndex, uiColumnIndex, hasCellEditorControls, candidateGridWidgets, () -> cellSelectionHandler.selectHeaderCellIfRequired(uiHeaderRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } final Integer uiRowIndex = getUiRowIndex(gridWidget, ap.getY()); if (Objects.nonNull(uiRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridCell<?> hasCellEditorControls = gridModel.getCell(uiRowIndex, uiColumnIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiRowIndex, uiColumnIndex, gridWidget, candidateGridWidgets, () -> cellSelectionHandler.selectCellIfRequired(uiRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } } if (candidateGridWidgets.isEmpty()) { return; } final CandidateGridWidget candidateGridWidget = candidateGridWidgets.get(candidateGridWidgets.size() - 1); final Point2D ap = candidateGridWidget.ap; final int uiRowIndex = candidateGridWidget.uiRowIndex; final int uiColumnIndex = candidateGridWidget.uiColumnIndex; final Object binding = candidateGridWidget.binding; final HasCellEditorControls hasCellEditorControls = candidateGridWidget.hasCellEditorControls; final Optional<HasCellEditorControls.Editor> editor = hasCellEditorControls.getEditor(); editor.ifPresent(e -> { candidateGridWidget.ensureCellSelectedCommand.execute(); e.bind(binding, uiRowIndex, uiColumnIndex); cellEditorControls.show(e, (int) (ap.getX()), (int) (ap.getY())); }); } DMNGridPanelContextMenuHandler(final DMNGridLayer gridLayer,
                                   final CellEditorControlsView.Presenter cellEditorControls,
                                   final DMNGridPanelCellSelectionHandler cellSelectionHandler); @Override @SuppressWarnings("unchecked") void onContextMenu(final ContextMenuEvent event); }
DMNGridPanelContextMenuHandler implements ContextMenuHandler { @Override @SuppressWarnings("unchecked") public void onContextMenu(final ContextMenuEvent event) { event.preventDefault(); event.stopPropagation(); final int canvasX = getRelativeXOfEvent(event); final int canvasY = getRelativeYOfEvent(event); final boolean isShiftKeyDown = event.getNativeEvent().getShiftKey(); final boolean isControlKeyDown = event.getNativeEvent().getCtrlKey(); final List<CandidateGridWidget> candidateGridWidgets = new ArrayList<>(); for (GridWidget gridWidget : gridLayer.getGridWidgets()) { if (DynamicReadOnlyUtils.isOnlyVisualChangeAllowed(gridWidget)) { continue; } final GridData gridModel = gridWidget.getModel(); final Point2D ap = convertDOMToGridCoordinate(gridWidget, new Point2D(canvasX, canvasY)); final Integer uiHeaderRowIndex = getUiHeaderRowIndex(gridWidget, ap); final Integer uiColumnIndex = getUiColumnIndex(gridWidget, ap.getX()); if (Objects.nonNull(uiHeaderRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridColumn.HeaderMetaData hasCellEditorControls = gridModel.getColumns().get(uiColumnIndex).getHeaderMetaData().get(uiHeaderRowIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiHeaderRowIndex, uiColumnIndex, hasCellEditorControls, candidateGridWidgets, () -> cellSelectionHandler.selectHeaderCellIfRequired(uiHeaderRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } final Integer uiRowIndex = getUiRowIndex(gridWidget, ap.getY()); if (Objects.nonNull(uiRowIndex) && Objects.nonNull(uiColumnIndex)) { final GridCell<?> hasCellEditorControls = gridModel.getCell(uiRowIndex, uiColumnIndex); registerCandidateGridWidget(hasCellEditorControls, gridWidget.getComputedLocation().add(ap), uiRowIndex, uiColumnIndex, gridWidget, candidateGridWidgets, () -> cellSelectionHandler.selectCellIfRequired(uiRowIndex, uiColumnIndex, gridWidget, isShiftKeyDown, isControlKeyDown)); } } if (candidateGridWidgets.isEmpty()) { return; } final CandidateGridWidget candidateGridWidget = candidateGridWidgets.get(candidateGridWidgets.size() - 1); final Point2D ap = candidateGridWidget.ap; final int uiRowIndex = candidateGridWidget.uiRowIndex; final int uiColumnIndex = candidateGridWidget.uiColumnIndex; final Object binding = candidateGridWidget.binding; final HasCellEditorControls hasCellEditorControls = candidateGridWidget.hasCellEditorControls; final Optional<HasCellEditorControls.Editor> editor = hasCellEditorControls.getEditor(); editor.ifPresent(e -> { candidateGridWidget.ensureCellSelectedCommand.execute(); e.bind(binding, uiRowIndex, uiColumnIndex); cellEditorControls.show(e, (int) (ap.getX()), (int) (ap.getY())); }); } DMNGridPanelContextMenuHandler(final DMNGridLayer gridLayer,
                                   final CellEditorControlsView.Presenter cellEditorControls,
                                   final DMNGridPanelCellSelectionHandler cellSelectionHandler); @Override @SuppressWarnings("unchecked") void onContextMenu(final ContextMenuEvent event);  }