/** * The constructor should first call super() to initialize the component and * then handle any initialization relevant to Vaadin. */ public VOpenLayersMap() { setWidth("500px"); setHeight("500px"); add(map); add(fakePaintables); fakePaintables.setVisible(false); // This method call of the Paintable interface sets the component // style name in DOM tree setStyleName(CLASSNAME); sinkEvents(Event.ONCONTEXTMENU); addDomHandler(new ContextMenuHandler() { public void onContextMenu(ContextMenuEvent event) { handleBodyContextMenu(event); } }, ContextMenuEvent.getType()); }
@Override public void setPlatypusPopupMenu(PlatypusPopupMenu aMenu) { if (menu != aMenu) { if (menuTriggerReg != null) menuTriggerReg.removeHandler(); menu = aMenu; if (menu != null) { menuTriggerReg = super.addDomHandler(new ContextMenuHandler() { @Override public void onContextMenu(ContextMenuEvent event) { event.preventDefault(); event.stopPropagation(); menu.setPopupPosition(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY()); menu.show(); } }, ContextMenuEvent.getType()); } } }
@Override public void setPlatypusPopupMenu(PlatypusPopupMenu aMenu) { if (contextMenu != aMenu) { if (menuTriggerReg != null) menuTriggerReg.removeHandler(); contextMenu = aMenu; if (contextMenu != null) { menuTriggerReg = super.addDomHandler(new ContextMenuHandler() { @Override public void onContextMenu(ContextMenuEvent event) { event.preventDefault(); event.stopPropagation(); contextMenu.setPopupPosition(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY()); contextMenu.show(); } }, ContextMenuEvent.getType()); } } }
@Test @SuppressWarnings("unchecked") public void onContextMenu_RowContextMenu() { final GuidedDecisionTableView.Presenter dtPresenter = makeDecisionTable(); final GridData uiModel = dtPresenter.getView().getModel(); final GridColumn uiColumn = new RowNumberColumn(); uiModel.appendColumn(uiColumn); when(columnInformation.getColumn()).thenReturn(uiColumn); when(modellerPresenter.getAvailableDecisionTables()).thenReturn(new HashSet<GuidedDecisionTableView.Presenter>() {{ add(dtPresenter); }}); final ContextMenuHandler handler = contextMenuSupport.getContextMenuHandler(modellerPresenter); handler.onContextMenu(event); verify(rowContextMenu, times(1)).show(any(Integer.class), any(Integer.class)); verify(cellContextMenu, never()).show(any(Integer.class), any(Integer.class)); }
@Test @SuppressWarnings("unchecked") public void onContextMenuWithoutCellSelectionManager() { final GuidedDecisionTableView.Presenter dtPresenter = makeDecisionTable(); final GridData uiModel = dtPresenter.getView().getModel(); final GridColumn uiColumn = new RowNumberColumn(); uiModel.appendColumn(uiColumn); when(columnInformation.getColumn()).thenReturn(uiColumn); when(modellerPresenter.getAvailableDecisionTables()).thenReturn(new HashSet<GuidedDecisionTableView.Presenter>() {{ add(dtPresenter); }}); final GridCell uiCell = mock(GridCell.class); when(uiModel.getCell(any(Integer.class), any(Integer.class))).thenReturn(uiCell); when(uiCell.getSelectionManager()).thenReturn(null); final ContextMenuHandler handler = contextMenuSupport.getContextMenuHandler(modellerPresenter); handler.onContextMenu(event); verify(layer, never()).batch(); }
@Before public void setup() { when(gridLayer.addNodeMouseMoveHandler(any(NodeMouseMoveHandler.class))).thenReturn(mock(HandlerRegistration.class)); when(gridLayer.addNodeMouseOutHandler(any(NodeMouseOutHandler.class))).thenReturn(mock(HandlerRegistration.class)); when(view.addKeyDownHandler(any(KeyDownHandler.class))).thenReturn(mock(HandlerRegistration.class)); when(view.addContextMenuHandler(any(ContextMenuHandler.class))).thenReturn(mock(HandlerRegistration.class)); when(view.addMouseDownHandler(any(MouseDownHandler.class))).thenReturn(mock(HandlerRegistration.class)); when(view.getGridLayerView()).thenReturn(gridLayer); when(view.getBounds()).thenReturn(bounds); final GuidedDecisionTableModellerPresenter wrapped = new GuidedDecisionTableModellerPresenter(view, dtablePresenterProvider, contextMenuSupport, updateRadarEvent, pinnedEvent, columnHeaderPopOver, wizardManagedInstance); presenter = spy(wrapped); when(dtablePresenterProvider.get()).thenReturn(dtablePresenter); when(dtablePresenter.getView()).thenReturn(dtableView); when(dtableView.getModel()).thenReturn(new BaseGridData()); }
@Override public void onModuleLoad() { // Rest client configuration RestClient.setJacksonMarshallingActive(true); RestClient.setApplicationRoot("rs"); // Disable right click RootLayoutPanel.get().addDomHandler(new ContextMenuHandler() { @Override public void onContextMenu(ContextMenuEvent event) { event.preventDefault(); event.stopPropagation(); } }, ContextMenuEvent.getType()); // Create main content mainLayout = new MainLayout(); RootLayoutPanel.get().add(mainLayout); // init mainLayout.init(); }
@Test @SuppressWarnings("unchecked") public void onContextMenu_CellContextMenu() { final GuidedDecisionTableView.Presenter dtPresenter = makeDecisionTable(); final GridData uiModel = dtPresenter.getView().getModel(); final GridColumn uiColumn = new BaseGridColumn(mock(GridColumn.HeaderMetaData.class), mock(GridColumnRenderer.class), 100.0); uiModel.appendColumn(uiColumn); when(columnInformation.getColumn()).thenReturn(uiColumn); when(modellerPresenter.getAvailableDecisionTables()).thenReturn(new HashSet<GuidedDecisionTableView.Presenter>() {{ add(dtPresenter); }}); final ContextMenuHandler handler = contextMenuSupport.getContextMenuHandler(modellerPresenter); handler.onContextMenu(event); verify(rowContextMenu, never()).show(any(Integer.class), any(Integer.class)); verify(cellContextMenu, times(1)).show(any(Integer.class), any(Integer.class)); }
@Test @SuppressWarnings("unchecked") public void testContextMenuCellIsSelectedCell() { final GuidedDecisionTableView.Presenter dtPresenter = makeDecisionTable(); final GridData uiModel = dtPresenter.getView().getModel(); final GridColumn uiColumn = new RowNumberColumn(); uiModel.appendColumn(uiColumn); //Cell associated with Mock onContextMenu Event has indices (0,0) uiModel.selectCells(0, 0, 1, 1); when(columnInformation.getColumn()).thenReturn(uiColumn); when(modellerPresenter.getAvailableDecisionTables()).thenReturn(new HashSet<GuidedDecisionTableView.Presenter>() { { add(dtPresenter); } }); final ContextMenuHandler handler = contextMenuSupport.getContextMenuHandler(modellerPresenter); handler.onContextMenu(event); // this method is called if the handler does a selectCell, which should not occur for this test case verify(cellSelectionStrategy, never()).handleSelection(any(GridData.class), any(Integer.class), any(Integer.class), any(Boolean.class), any(Boolean.class)); verify(rowContextMenu, times(1)).show(any(Integer.class), any(Integer.class)); verify(cellContextMenu, never()).show(any(Integer.class), any(Integer.class)); }
@Test @SuppressWarnings("unchecked") public void onContextMenuWithCellSelectionManagerWithChangeInSelection() { final GuidedDecisionTableView.Presenter dtPresenter = makeDecisionTable(); final GridData uiModel = dtPresenter.getView().getModel(); final GridColumn uiColumn = new RowNumberColumn(); uiModel.appendColumn(uiColumn); when(columnInformation.getColumn()).thenReturn(uiColumn); when(modellerPresenter.getAvailableDecisionTables()).thenReturn(new HashSet<GuidedDecisionTableView.Presenter>() {{ add(dtPresenter); }}); when(uiModel.getCell(any(Integer.class), any(Integer.class))).thenReturn(uiCell); when(cellSelectionStrategy.handleSelection(any(GridData.class), any(Integer.class), any(Integer.class), any(Boolean.class), any(Boolean.class))).thenReturn(true); final ContextMenuHandler handler = contextMenuSupport.getContextMenuHandler(modellerPresenter); handler.onContextMenu(event); verify(cellSelectionStrategy, times(1)).handleSelection(eq(uiModel), eq(0), eq(0), eq(false), eq(false)); verify(layer, times(1)).batch(); }
@Test @SuppressWarnings("unchecked") public void onContextMenuWithCellSelectionManagerWithoutChangeInSelection() { final GuidedDecisionTableView.Presenter dtPresenter = makeDecisionTable(); final GridData uiModel = dtPresenter.getView().getModel(); final GridColumn uiColumn = new RowNumberColumn(); uiModel.appendColumn(uiColumn); when(columnInformation.getColumn()).thenReturn(uiColumn); when(modellerPresenter.getAvailableDecisionTables()).thenReturn(new HashSet<GuidedDecisionTableView.Presenter>() {{ add(dtPresenter); }}); when(uiModel.getCell(any(Integer.class), any(Integer.class))).thenReturn(uiCell); final ContextMenuHandler handler = contextMenuSupport.getContextMenuHandler(modellerPresenter); handler.onContextMenu(event); verify(cellSelectionStrategy, times(1)).handleSelection(eq(uiModel), eq(0), eq(0), eq(false), eq(false)); verify(layer, never()).batch(); }
public HandlerRegistration addContextMenuHandler(ContextMenuHandler handler) { return addDomHandler(handler, ContextMenuEvent.getType()); }
public ContextMenuHandler getContextMenuHandler(final GuidedDecisionTableModellerView.Presenter modellerPresenter) { return new GuidedDecisionTableModellerContextMenuHandler(modellerPresenter, cellContextMenu, rowContextMenu); }