use of org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler in project kie-wb-common by kiegroup.
the class DecisionServiceMoveDividerControlTest method testRegisterDecisionServiceElementDragEnd.
@Test
@SuppressWarnings("unchecked")
public void testRegisterDecisionServiceElementDragEnd() {
final DefinitionManager definitionManager = mock(DefinitionManager.class);
final AdapterManager adapterManager = mock(AdapterManager.class);
final AdapterRegistry adapterRegistry = mock(AdapterRegistry.class);
final PropertyAdapter<Object, Object> propertyAdapter = mock(PropertyAdapter.class);
final DefinitionAdapter<Object> definitionAdapter = mock(DefinitionAdapter.class);
final DecisionServiceDividerLineY dividerLineY = new DecisionServiceDividerLineY();
final Optional dividerYProperty = Optional.of(dividerLineY);
final UpdateElementPropertyCommand updateElementPropertyCommand = mock(UpdateElementPropertyCommand.class);
final DecisionService decisionService = mock(DecisionService.class);
final DecisionServiceSVGShapeView decisionServiceShapeView = mock(DecisionServiceSVGShapeView.class);
final DragEvent dragEvent = mock(DragEvent.class);
when(canvasHandler.getDefinitionManager()).thenReturn(definitionManager);
when(definitionManager.adapters()).thenReturn(adapterManager);
when(adapterManager.registry()).thenReturn(adapterRegistry);
when(adapterManager.forProperty()).thenReturn(propertyAdapter);
when(adapterRegistry.getDefinitionAdapter(Mockito.<Class>any())).thenReturn(definitionAdapter);
when(definitionAdapter.getProperty(decisionService, DIVIDER_Y_PROPERTY_ID)).thenReturn(dividerYProperty);
when(propertyAdapter.getId(dividerLineY)).thenReturn(DIVIDER_Y_PROPERTY_ID);
when(canvasCommandFactory.updatePropertyValue(eq(element), eq(DIVIDER_Y_PROPERTY_ID), Mockito.<Object>any())).thenReturn(updateElementPropertyCommand);
when(definition.getDefinition()).thenReturn(decisionService);
when(shape.getShapeView()).thenReturn(decisionServiceShapeView);
control.register(element);
verify(decisionServiceShapeView).addDividerDragHandler(dragHandlerCaptor.capture());
when(decisionServiceShapeView.getDividerLineY()).thenReturn(DIVIDER_Y);
final DragHandler dragHandler = dragHandlerCaptor.getValue();
dragHandler.end(dragEvent);
verify(canvasCommandFactory).updatePropertyValue(eq(element), eq(DIVIDER_Y_PROPERTY_ID), eq(DIVIDER_Y));
verify(commandManager).execute(eq(canvasHandler), eq(updateElementPropertyCommand));
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler in project kie-wb-common by kiegroup.
the class DecisionServiceMoveDividerControl method register.
@Override
@SuppressWarnings("unchecked")
public void register(final Element element) {
if (checkNotRegistered(element)) {
final Object definition = ((Definition) element.getContent()).getDefinition();
if (!isDecisionServiceDefinition(definition)) {
return;
}
final Canvas<?> canvas = canvasHandler.getCanvas();
final Shape<?> shape = canvas.getShape(element.getUUID());
final ShapeView<?> shapeView = shape.getShapeView();
if (!isDecisionServiceShapeView(shapeView)) {
return;
}
final DecisionServiceSVGShapeView decisionServiceShapeView = (DecisionServiceSVGShapeView) shapeView;
final DragHandler dragHandler = new DragHandler() {
@Override
public void end(final DragEvent event) {
final CommandResult<CanvasViolation> result = doMoveDivider(element, decisionServiceShapeView.getDividerLineY());
if (CommandUtils.isError(result)) {
LOGGER.log(Level.WARNING, "Command failed at resize end [result=" + result + "]");
}
}
};
decisionServiceShapeView.addDividerDragHandler(dragHandler);
registerHandler(element.getUUID(), dragHandler);
}
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler in project kie-wb-common by kiegroup.
the class LienzoCanvasTest method testEventHandling.
@Test
public void testEventHandling() {
CanvasPanel panel = mock(CanvasPanel.class);
CanvasSettings settings = mock(CanvasSettings.class);
ViewEventHandlerManager eventHandler = mock(ViewEventHandlerManager.class);
tested.initialize(panel, settings, eventHandler);
tested.supports(ViewEventType.DRAG);
verify(eventHandler, times(1)).supports(eq(ViewEventType.DRAG));
tested.enableHandlers();
verify(eventHandler, times(1)).enable();
tested.disableHandlers();
verify(eventHandler, times(1)).disable();
DragHandler dragHandler = mock(DragHandler.class);
tested.addHandler(ViewEventType.DRAG, dragHandler);
verify(eventHandler, times(1)).addHandler(eq(ViewEventType.DRAG), eq(dragHandler));
tested.removeHandler(dragHandler);
verify(eventHandler, times(1)).removeHandler(eq(dragHandler));
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler in project kie-wb-common by kiegroup.
the class WiresShapeViewExt method registerDragHandler.
private HandlerRegistration[] registerDragHandler(final ViewHandler<DragEvent> eventHandler) {
if (!getAttachableShape().isDraggable()) {
final DragHandler dragHandler = (DragHandler) eventHandler;
setDragEnabled(true);
HandlerRegistration dragStartReg = addWiresDragStartHandler(wiresDragStartEvent -> {
final DragEvent e = buildDragEvent(wiresDragStartEvent);
dragHandler.start(e);
});
HandlerRegistration dragMoveReg = addWiresDragMoveHandler(wiresDragMoveEvent -> {
final DragEvent e = buildDragEvent(wiresDragMoveEvent);
dragHandler.handle(e);
});
HandlerRegistration dragEndReg = addWiresDragEndHandler(wiresDragEndEvent -> {
final DragEvent e = buildDragEvent(wiresDragEndEvent);
dragHandler.end(e);
});
return new HandlerRegistration[] { dragStartReg, dragMoveReg, dragEndReg };
}
return null;
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler in project kie-wb-common by kiegroup.
the class LocationControlImpl method register.
@Override
@SuppressWarnings("unchecked")
public void register(final Element element) {
if (null != element.asNode() && checkNotRegistered(element)) {
final AbstractCanvas<?> canvas = canvasHandler.getAbstractCanvas();
final Shape<?> shape = canvas.getShape(element.getUUID());
final ShapeView shapeView = shape.getShapeView();
// Enable drag & ensure location constraints are set, if any.
shapeView.setDragEnabled(true);
ensureDragConstraints(canvas, shapeView);
// Register handlers.
if (shape.getShapeView() instanceof HasEventHandlers) {
final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView;
// Change mouse cursor, if shape supports it.
if (supportsMouseEnter(hasEventHandlers) && supportsMouseExit(hasEventHandlers)) {
final MouseEnterHandler overHandler = new MouseEnterHandler() {
@Override
public void handle(MouseEnterEvent event) {
canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.MOVE);
}
};
hasEventHandlers.addHandler(ViewEventType.MOUSE_ENTER, overHandler);
registerHandler(shape.getUUID(), overHandler);
final MouseExitHandler outHandler = new MouseExitHandler() {
@Override
public void handle(MouseExitEvent event) {
canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.DEFAULT);
}
};
hasEventHandlers.addHandler(ViewEventType.MOUSE_EXIT, outHandler);
registerHandler(shape.getUUID(), outHandler);
// Adding DragHandler on the shape to check whether the moving shape is not selected, th
final DragHandler dragHandler = new DragHandler() {
@Override
public void start(DragEvent event) {
// Instead of firing the event on Drag start, now will be fired at the end, hence improving performance
}
@Override
public void end(DragEvent event) {
selectionEvent.fire(new CanvasSelectionEvent(canvasHandler, shape.getUUID()));
}
@Override
public void handle(DragEvent event) {
}
};
hasEventHandlers.addHandler(ViewEventType.DRAG, dragHandler);
registerHandler(shape.getUUID(), dragHandler);
}
}
}
}
Aggregations