Search in sources :

Example 1 with DragHandler

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));
}
Also used : Optional(java.util.Optional) DragHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler) AdapterRegistry(org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) DragEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) DecisionServiceSVGShapeView(org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView) Test(org.junit.Test)

Example 2 with DragHandler

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);
    }
}
Also used : DragEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DragHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler) DecisionServiceSVGShapeView(org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView)

Example 3 with 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));
}
Also used : CanvasPanel(org.kie.workbench.common.stunner.core.client.canvas.CanvasPanel) CanvasSettings(org.kie.workbench.common.stunner.core.client.canvas.CanvasSettings) DragHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler) ViewEventHandlerManager(org.kie.workbench.common.stunner.client.lienzo.shape.view.ViewEventHandlerManager) Test(org.junit.Test)

Example 4 with 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;
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) DragEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent) AbstractWiresDragEvent(com.ait.lienzo.client.core.shape.wires.event.AbstractWiresDragEvent) DragHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler)

Example 5 with DragHandler

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);
            }
        }
    }
}
Also used : DragEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) MouseExitHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitHandler) MouseEnterEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent) DragHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler) MouseExitEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) MouseEnterHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterHandler)

Aggregations

DragHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler)5 DragEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent)4 Test (org.junit.Test)2 DecisionServiceSVGShapeView (org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView)2 AbstractWiresDragEvent (com.ait.lienzo.client.core.shape.wires.event.AbstractWiresDragEvent)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 Optional (java.util.Optional)1 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)1 DecisionServiceDividerLineY (org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY)1 ViewEventHandlerManager (org.kie.workbench.common.stunner.client.lienzo.shape.view.ViewEventHandlerManager)1 DefinitionManager (org.kie.workbench.common.stunner.core.api.DefinitionManager)1 CanvasPanel (org.kie.workbench.common.stunner.core.client.canvas.CanvasPanel)1 CanvasSettings (org.kie.workbench.common.stunner.core.client.canvas.CanvasSettings)1 UpdateElementPropertyCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand)1 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)1 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)1 MouseEnterEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent)1 MouseEnterHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterHandler)1