Search in sources :

Example 1 with ShapeView

use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.

the class ShapeUtils method updateEdgeConnection.

@SuppressWarnings("unchecked")
public static void updateEdgeConnection(final AbstractCanvasHandler context, final Connection connection, final Node<? extends View<?>, Edge> node) {
    if (null != node && null == connection.getLocation() && connection instanceof MagnetConnection) {
        final MagnetConnection magnetConnection = (MagnetConnection) connection;
        final OptionalInt magnetIndex = magnetConnection.getMagnetIndex();
        if (magnetIndex.orElse(-1) == MagnetConnection.MAGNET_CENTER) {
            final Shape<ShapeView<?>> nodeShape = context.getCanvas().getShape(node.getUUID());
            final BoundingBox boundingBox = nodeShape.getShapeView().getBoundingBox();
            magnetConnection.setLocation(new Point2D(boundingBox.getWidth() / 2, boundingBox.getHeight() / 2));
        }
    }
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) OptionalInt(java.util.OptionalInt) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)

Example 2 with ShapeView

use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.

the class MapSelectionControlTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    ShapeViewExtStub shapeView = new ShapeViewExtStub(shapeEventHandler, hasControlPoints);
    when(element.getUUID()).thenReturn(ELEMENT_UUID);
    when(element.getContent()).thenReturn(new ViewImpl<>(definition, BoundsImpl.build(0, 0, 10, 10)));
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getCanvasRootUUID()).thenReturn(ROOT_UUID);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvas.getLayer()).thenReturn(layer);
    when(canvas.getShape(eq(ELEMENT_UUID))).thenReturn(shape);
    when(canvas.getShapes()).thenReturn(Collections.singletonList(shape));
    when(shape.getUUID()).thenReturn(ELEMENT_UUID);
    when(shape.getShapeView()).thenReturn(shapeView);
    when(shapeEventHandler.supports(eq(ViewEventType.MOUSE_CLICK))).thenReturn(true);
    this.tested = new MapSelectionControl(e -> elementSelectedEvent.fire((CanvasSelectionEvent) e), e -> clearSelectionEvent.fire((CanvasClearSelectionEvent) e));
    this.tested.setReadonly(false);
}
Also used : CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ViewHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewHandler) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HasControlPoints(org.kie.workbench.common.stunner.core.client.shape.view.HasControlPoints) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Layer(org.kie.workbench.common.stunner.core.client.canvas.Layer) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) ArgumentCaptor(org.mockito.ArgumentCaptor) Matchers.eq(org.mockito.Matchers.eq) CanvasShapeRemovedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasShapeRemovedEvent) ShapeState(org.kie.workbench.common.stunner.core.client.shape.ShapeState) Element(org.kie.workbench.common.stunner.core.graph.Element) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Before(org.junit.Before) ViewEventType(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEventType) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Assert.assertFalse(org.junit.Assert.assertFalse) ShapeViewExtStub(org.kie.workbench.common.stunner.core.client.shape.ShapeViewExtStub) EventSourceMock(org.uberfire.mocks.EventSourceMock) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ShapeViewExtStub(org.kie.workbench.common.stunner.core.client.shape.ShapeViewExtStub) Before(org.junit.Before)

Example 3 with ShapeView

use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.

the class ShapeUtilsTest method testApplyConnections.

@Test
@SuppressWarnings("unchecked")
public void testApplyConnections() {
    final Shape startNodeShape = mock(Shape.class);
    final ShapeView startNodeShapeView = mock(ShapeView.class);
    final Shape intermNodeShape = mock(Shape.class);
    final ShapeView intermNodeShapeView = mock(ShapeView.class);
    final EdgeShape edge1EdgeShape = mock(EdgeShape.class);
    when(canvas.getShape(eq(instance2.startNode.getUUID()))).thenReturn(startNodeShape);
    when(canvas.getShape(eq(instance2.intermNode.getUUID()))).thenReturn(intermNodeShape);
    when(canvas.getShape(eq(instance2.edge1.getUUID()))).thenReturn(edge1EdgeShape);
    when(startNodeShape.getShapeView()).thenReturn(startNodeShapeView);
    when(intermNodeShape.getShapeView()).thenReturn(intermNodeShapeView);
    when(edge1EdgeShape.getShapeView()).thenReturn(edge1ShapeView);
    ShapeUtils.applyConnections(instance2.edge1, canvasHandler, MutationContext.STATIC);
    verify(edge1EdgeShape, times(1)).applyConnections(eq(instance2.edge1), eq(startNodeShapeView), eq(intermNodeShapeView), eq(MutationContext.STATIC));
}
Also used : EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) ConnectorShape(org.kie.workbench.common.stunner.core.client.shape.impl.ConnectorShape) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) Test(org.junit.Test)

Example 4 with ShapeView

use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView 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);
            }
        }
    }
}
Also used : MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Example 5 with ShapeView

use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.

the class AbstractRegistrationCanvasNodeCommand method register.

@SuppressWarnings("unchecked")
protected void register(final AbstractCanvasHandler context) {
    context.register(shapeSetId, candidate);
    // Update view bounds for the element, if not set, by using the values from the shape view.
    final double[] size = GraphUtils.getNodeSize(candidate.getContent());
    if (size[0] <= 0 || size[1] <= 0) {
        final Shape shape = context.getCanvas().getShape(candidate.getUUID());
        final ShapeView shapeView = shape.getShapeView();
        final Point2D location = GraphUtils.getPosition(candidate.getContent());
        final BoundingBox boundingBox = shapeView.getBoundingBox();
        candidate.getContent().setBounds(new BoundsImpl(new BoundImpl(location.getX(), location.getY()), new BoundImpl(location.getX() + boundingBox.getWidth(), location.getY() + boundingBox.getHeight())));
    }
}
Also used : Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)

Aggregations

ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)8 Test (org.junit.Test)4 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)3 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)3 BPMNViewDefinition (org.kie.workbench.common.stunner.bpmn.definition.BPMNViewDefinition)2 StartNoneEvent (org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent)2 BoundingBox (org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox)2 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)2 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)2 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)2 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)2 Collections (java.util.Collections)1 OptionalInt (java.util.OptionalInt)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1