use of com.google.gwt.event.shared.HandlerRegistration in project kie-wb-common by kiegroup.
the class ViewEventHandlerManagerTest method testMouseEnterHandler.
@Test
@SuppressWarnings("unchecked")
public void testMouseEnterHandler() {
final ViewHandler<ViewEvent> clickHandler = mock(ViewHandler.class);
final HandlerRegistration handlerRegistration = mock(HandlerRegistration.class);
when(shape.addNodeMouseEnterHandler(any(NodeMouseEnterHandler.class))).thenReturn(handlerRegistration);
tested.addHandler(ViewEventType.MOUSE_ENTER, clickHandler);
final ArgumentCaptor<NodeMouseEnterHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseEnterHandler.class);
verify(shape, times(1)).addNodeMouseEnterHandler(clickHandlerArgumentCaptor.capture());
final NodeMouseEnterHandler nodeCLickHandler = clickHandlerArgumentCaptor.getValue();
final NodeMouseEnterEvent clickEvent = mock(NodeMouseEnterEvent.class);
final MouseEvent mouseEvent = mock(MouseEvent.class);
final int x = 102;
final int y = 410;
when(clickEvent.getX()).thenReturn(x);
when(clickEvent.getY()).thenReturn(y);
when(clickEvent.isShiftKeyDown()).thenReturn(true);
when(clickEvent.isAltKeyDown()).thenReturn(true);
when(clickEvent.isMetaKeyDown()).thenReturn(true);
when(clickEvent.getMouseEvent()).thenReturn(mouseEvent);
when(mouseEvent.getClientX()).thenReturn(x);
when(mouseEvent.getClientY()).thenReturn(y);
nodeCLickHandler.onNodeMouseEnter(clickEvent);
final ArgumentCaptor<ViewEvent> eventArgumentCaptor = ArgumentCaptor.forClass(ViewEvent.class);
verify(clickHandler, times(1)).handle(eventArgumentCaptor.capture());
final MouseEnterEvent viewEvent = (MouseEnterEvent) eventArgumentCaptor.getValue();
assertEquals(x, viewEvent.getX(), 0d);
assertEquals(y, viewEvent.getY(), 0d);
assertEquals(x, viewEvent.getClientX(), 0d);
assertEquals(y, viewEvent.getClientY(), 0d);
assertTrue(viewEvent.isAltKeyDown());
assertTrue(viewEvent.isMetaKeyDown());
assertTrue(viewEvent.isShiftKeyDown());
assertNotNull(tested.getRegistrationMap().get(ViewEventType.MOUSE_ENTER));
}
use of com.google.gwt.event.shared.HandlerRegistration in project drools-wb by kiegroup.
the class AnalyzerControllerImplTest method areHandlersTornDownOnTerminate.
@Test
public void areHandlersTornDownOnTerminate() throws Exception {
final HandlerRegistration validateEvent = mock(HandlerRegistration.class);
when(eventBus.addHandler(ValidateEvent.TYPE, controller)).thenReturn(validateEvent);
final HandlerRegistration deleteRowEvent = mock(HandlerRegistration.class);
when(eventBus.addHandler(DeleteRowEvent.TYPE, controller)).thenReturn(deleteRowEvent);
final HandlerRegistration afterColumnDeleted = mock(HandlerRegistration.class);
when(eventBus.addHandler(AfterColumnDeleted.TYPE, controller)).thenReturn(afterColumnDeleted);
final HandlerRegistration updateColumnDataEvent = mock(HandlerRegistration.class);
when(eventBus.addHandler(UpdateColumnDataEvent.TYPE, controller)).thenReturn(updateColumnDataEvent);
final HandlerRegistration appendRowEvent = mock(HandlerRegistration.class);
when(eventBus.addHandler(AppendRowEvent.TYPE, controller)).thenReturn(appendRowEvent);
final HandlerRegistration insertRowEvent = mock(HandlerRegistration.class);
when(eventBus.addHandler(InsertRowEvent.TYPE, controller)).thenReturn(insertRowEvent);
final HandlerRegistration afterColumnInserted = mock(HandlerRegistration.class);
when(eventBus.addHandler(AfterColumnInserted.TYPE, controller)).thenReturn(afterColumnInserted);
controller.initialiseAnalysis();
controller.terminateAnalysis();
verify(validateEvent).removeHandler();
verify(deleteRowEvent).removeHandler();
verify(afterColumnDeleted).removeHandler();
verify(updateColumnDataEvent).removeHandler();
verify(appendRowEvent).removeHandler();
verify(insertRowEvent).removeHandler();
verify(afterColumnDeleted).removeHandler();
}
use of com.google.gwt.event.shared.HandlerRegistration in project drools-wb by kiegroup.
the class EventsTest method tearDownRemovesHandlers.
@Test
public void tearDownRemovesHandlers() throws Exception {
final HandlerRegistration registration = mock(HandlerRegistration.class);
when(eventBus.addHandler(ValidateEvent.TYPE, analyzerController)).thenReturn(registration);
mockOtherEventHandlerRegistrations();
events.setup();
events.teardown();
verify(registration).removeHandler();
}
use of com.google.gwt.event.shared.HandlerRegistration in project drools-wb by kiegroup.
the class FieldDatePicker method addValueChangeHandler.
public HandlerRegistration addValueChangeHandler(final ValueChangeHandler<String> handler) {
HandlerRegistration registration = new HandlerRegistration() {
@Override
public void removeHandler() {
handlerManager.removeHandler(ValueChangeEvent.getType(), handler);
}
};
handlerManager.addHandler(ValueChangeEvent.getType(), handler);
return registration;
}
use of com.google.gwt.event.shared.HandlerRegistration in project gwt-ol3 by TDesjardins.
the class Map method addMapMoveListener.
/**
* Adds a map move listener for the given map.
*/
@JsOverlay
public final HandlerRegistration addMapMoveListener(final EventListener<MapEvent> listener) {
final HandlerRegistration handlerMap = OLUtil.observe(this, "moveend", listener);
View view = getView();
if (view == null)
return handlerMap;
// if we have a view, fire events while the map is moving
// try to set up an event handler for the change of the view center
// as "moveend" will be only fired when the map stops moving
final HandlerRegistration handlerView = OLUtil.observe(view, "change:center", event -> {
// create an artificial move event
ol.events.Event e2 = OLUtil.createLinkedEvent(event, "move", Map.this);
MapEvent mapEvent = OLUtil.initMapEvent(e2, Map.this);
listener.onEvent(mapEvent);
});
// return a handler registration, which detaches both event handlers
return () -> {
handlerMap.removeHandler();
handlerView.removeHandler();
};
}
Aggregations