use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent in project kie-wb-common by kiegroup.
the class ViewEventHandlerManagerTest method testClickHandler.
@Test
@SuppressWarnings("unchecked")
public void testClickHandler() {
final ViewHandler<ViewEvent> clickHandler = mock(ViewHandler.class);
final HandlerRegistration handlerRegistration = mock(HandlerRegistration.class);
when(node.addNodeMouseClickHandler(any(NodeMouseClickHandler.class))).thenReturn(handlerRegistration);
tested.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
final ArgumentCaptor<NodeMouseClickHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseClickHandler.class);
verify(node, times(1)).addNodeMouseClickHandler(clickHandlerArgumentCaptor.capture());
final NodeMouseClickHandler nodeCLickHandler = clickHandlerArgumentCaptor.getValue();
final NodeMouseClickEvent clickEvent = mock(NodeMouseClickEvent.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.isButtonLeft()).thenReturn(true);
when(clickEvent.isButtonRight()).thenReturn(true);
when(clickEvent.isButtonMiddle()).thenReturn(true);
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.onNodeMouseClick(clickEvent);
final ArgumentCaptor<ViewEvent> eventArgumentCaptor = ArgumentCaptor.forClass(ViewEvent.class);
verify(clickHandler, times(1)).handle(eventArgumentCaptor.capture());
final MouseClickEvent viewEvent = (MouseClickEvent) eventArgumentCaptor.getValue();
assertEquals(x, viewEvent.getX(), 0d);
assertEquals(y, viewEvent.getY(), 0d);
assertEquals(x, viewEvent.getClientX(), 0d);
assertEquals(y, viewEvent.getClientY(), 0d);
assertTrue(viewEvent.isButtonLeft());
assertTrue(viewEvent.isButtonRight());
assertTrue(viewEvent.isButtonMiddle());
assertTrue(viewEvent.isAltKeyDown());
assertTrue(viewEvent.isMetaKeyDown());
assertTrue(viewEvent.isShiftKeyDown());
assertNotNull(tested.getRegistrationMap().get(ViewEventType.MOUSE_CLICK));
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent in project kie-wb-common by kiegroup.
the class LienzoSelectionControlTest method testRegisterAndClick.
@Test
public void testRegisterAndClick() {
tested.init(canvasHandler);
tested.register(element);
verify(selectionControl, times(1)).register(eq(element));
ArgumentCaptor<MouseClickHandler> clickHandlerCaptor = ArgumentCaptor.forClass(MouseClickHandler.class);
verify(shapeViewHandlers, times(1)).supports(eq(ViewEventType.MOUSE_CLICK));
verify(shapeViewHandlers, times(1)).addHandler(eq(ViewEventType.MOUSE_CLICK), clickHandlerCaptor.capture());
final MouseClickHandler clickHandler = clickHandlerCaptor.getValue();
assertEquals(clickHandler, tested.getHandlers().get(ELEMENT_UUID));
MouseClickEvent event = mock(MouseClickEvent.class);
when(event.isButtonLeft()).thenReturn(true);
clickHandler.handle(event);
verify(selectionControl, times(1)).select(eq(element.getUUID()));
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent in project kie-wb-common by kiegroup.
the class FormGenerationToolboxActionTest method testOnClick.
@Test
@SuppressWarnings("unchecked")
public void testOnClick() {
final MouseClickEvent event = mock(MouseClickEvent.class);
tested.onMouseClick(canvasHandler, "uuid", event);
verify(formGenerationManager, times(1)).call(any(Consumer.class));
verify(formGenerationService, times(1)).generateSelectedForms(eq(diagram), eq(new String[] { "uuid" }));
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent in project kie-wb-common by kiegroup.
the class LienzoSelectionControl method onRegister.
@Override
protected void onRegister(final Element element) {
super.onRegister(element);
final Shape<?> shape = getSelectionControl().getCanvas().getShape(element.getUUID());
if (null != shape) {
final ShapeView shapeView = shape.getShapeView();
if (shapeView instanceof HasEventHandlers) {
final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView;
if (hasEventHandlers.supports(ViewEventType.MOUSE_CLICK)) {
final MouseClickHandler clickHandler = new MouseClickHandler() {
@Override
public void handle(final MouseClickEvent event) {
if (event.isButtonLeft() || event.isButtonRight()) {
singleSelect(element);
}
}
};
hasEventHandlers.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
registerHandler(shape.getUUID(), clickHandler);
}
}
}
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent in project kie-wb-common by kiegroup.
the class ViewEventHandlerManager method onMouseClick.
private void onMouseClick(final ViewHandler<ViewEvent> eventHandler, final int x, final int y, final int clientX, final int clientY, final boolean isShiftKeyDown, final boolean isAltKeyDown, final boolean isMetaKeyDown, final boolean isButtonLeft, final boolean isButtonMiddle, final boolean isButtonRight) {
final MouseClickEvent event = new MouseClickEvent(x, y, clientX, clientY);
event.setShiftKeyDown(isShiftKeyDown);
event.setAltKeyDown(isAltKeyDown);
event.setMetaKeyDown(isMetaKeyDown);
event.setButtonLeft(isButtonLeft);
event.setButtonMiddle(isButtonMiddle);
event.setButtonRight(isButtonRight);
eventHandler.handle(event);
}
Aggregations