DefaultGridWidgetEditCellMouseEventHandler implements NodeMouseEventHandler { @Override public boolean onNodeMouseEvent(final GridWidget gridWidget, final Point2D relativeLocation, final Optional<Integer> uiHeaderRowIndex, final Optional<Integer> uiHeaderColumnIndex, final Optional<Integer> uiRowIndex, final Optional<Integer> uiColumnIndex, final AbstractNodeMouseEvent event) { if (isDNDOperationInProgress(gridWidget)) { return false; } boolean isHandled = false; if (uiHeaderRowIndex.isPresent() && uiHeaderColumnIndex.isPresent()) { isHandled = handleHeaderCell(gridWidget, relativeLocation, uiHeaderRowIndex.get(), uiHeaderColumnIndex.get(), event); } if (!isHandled && uiRowIndex.isPresent() && uiColumnIndex.isPresent()) { isHandled = handleBodyCell(gridWidget, relativeLocation, uiRowIndex.get(), uiColumnIndex.get(), event); } return isHandled; }  @Override boolean onNodeMouseEvent(final GridWidget gridWidget,
                                    final Point2D relativeLocation,
                                    final Optional<Integer> uiHeaderRowIndex,
                                    final Optional<Integer> uiHeaderColumnIndex,
                                    final Optional<Integer> uiRowIndex,
                                    final Optional<Integer> uiColumnIndex,
                                    final AbstractNodeMouseEvent event); @Override boolean handleBodyCell(final GridWidget gridWidget,
                                  final Point2D relativeLocation,
                                  final int uiRowIndex,
                                  final int uiColumnIndex,
                                  final AbstractNodeMouseEvent event);  }
@Test public void testEditHeaderCell() { assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, Optional.of(0), Optional.of(1), Optional.empty(), Optional.empty(), event)).isFalse(); verify(uiModel, never()).selectHeaderCell(anyInt(), anyInt()); }
@Test @SuppressWarnings("unchecked") public void testEditBodyCellWithASelectedCell() { when(uiModel.getSelectedCells()).thenReturn(Collections.singletonList(new GridData.SelectedCell(0, 1))); when(uiModel.getCell(eq(0), eq(1))).thenReturn(gridCell); when(gridCell.getSupportedEditAction()).thenReturn(GridCellEditAction.DOUBLE_CLICK); assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, Optional.empty(), Optional.empty(), Optional.of(0), Optional.of(1), event)).isFalse(); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget).startEditingCell(eq(relativeLocation)); }
@Test @SuppressWarnings("unchecked") public void testEditBodyCellWithANullSelectedCell() { when(uiModel.getSelectedCells()).thenReturn(Collections.singletonList(new GridData.SelectedCell(0, 1))); when(uiModel.getCell(eq(0), eq(1))).thenReturn(null); assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, Optional.empty(), Optional.empty(), Optional.of(0), Optional.of(1), event)).isFalse(); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget).startEditingCell(eq(relativeLocation)); }
@Test public void testEditBodyCellWithMultipleSelectedCells() { when(uiModel.getSelectedCells()).thenReturn(Arrays.asList(new GridData.SelectedCell(0, 0), new GridData.SelectedCell(0, 1))); assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, Optional.empty(), Optional.empty(), Optional.of(0), Optional.of(1), event)).isFalse(); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget, never()).startEditingCell(any(Point2D.class)); }
@Test public void testEditBodyCellWithoutASelectedCell() { assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, Optional.empty(), Optional.empty(), Optional.of(0), Optional.of(1), event)).isFalse(); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget, never()).startEditingCell(any(Point2D.class)); }
@Test public void checkOnNodeMouseEventDuringDragOperation() { doReturn(true).when(handler).isDNDOperationInProgress(eq(gridWidget)); assertFalse(handler.onNodeMouseEvent(gridWidget, relativeLocation, Optional.empty(), Optional.empty(), Optional.of(0), Optional.of(1), event)); }