Search in sources :

Example 16 with Group

use of com.ait.lienzo.client.core.shape.Group in project kie-wb-common by kiegroup.

the class LocationControlImplTest method testMove.

@Test
@SuppressWarnings("unchecked")
public void testMove() throws Exception {
    final WiresShapeView wiresShape = mock(WiresShapeView.class);
    final WiresShapeView childWiresShape = mock(WiresShapeView.class);
    final MagnetManager.Magnets magnets = mock(MagnetManager.Magnets.class);
    final WiresMagnet magnet = mock(WiresMagnet.class);
    final WiresConnection connection = mock(WiresConnection.class);
    final NFastArrayList<WiresConnection> connections = new NFastArrayList<>(connection);
    final WiresConnector connector = mock(WiresConnector.class);
    final String connectorUUID = UUID.uuid();
    final NFastArrayList<WiresShape> children = new NFastArrayList<>(childWiresShape);
    final Group connectorGroup = mock(Group.class);
    final Edge connectorEdge = mock(Edge.class);
    final com.ait.lienzo.client.core.types.Point2D controlPointLienzo = new com.ait.lienzo.client.core.types.Point2D(100, 100);
    final Point2DArray controlPointsLienzo = new Point2DArray(controlPointLienzo);
    final ViewConnector viewConnector = mock(ViewConnector.class);
    Group parentGroup = mock(Group.class);
    BoundingBox parentBB = new BoundingBox(0, 0, 200, 200);
    MultiPath head = mock(MultiPath.class);
    MultiPath tail = mock(MultiPath.class);
    when(childWiresShape.getMagnets()).thenReturn(magnets);
    when(childWiresShape.getParent()).thenReturn(wiresShape);
    when(wiresShape.getGroup()).thenReturn(parentGroup);
    when(parentGroup.getBoundingBox()).thenReturn(parentBB);
    when(wiresShape.getX()).thenReturn(0d);
    when(wiresShape.getY()).thenReturn(0d);
    when(magnets.size()).thenReturn(1);
    when(magnets.getMagnet(0)).thenReturn(magnet);
    when(magnet.getConnectionsSize()).thenReturn(connections.size());
    when(magnet.getConnections()).thenReturn(connections);
    when(connection.getConnector()).thenReturn(connector);
    when(connector.getGroup()).thenReturn(connectorGroup);
    when(connectorGroup.uuid()).thenReturn(connectorUUID);
    when(connector.getControlPoints()).thenReturn(controlPointsLienzo);
    when(connector.getHead()).thenReturn(head);
    when(connector.getTail()).thenReturn(tail);
    when(head.getLocation()).thenReturn(new com.ait.lienzo.client.core.types.Point2D(1, 1));
    when(tail.getLocation()).thenReturn(new com.ait.lienzo.client.core.types.Point2D(2, 2));
    when(wiresShape.getChildShapes()).thenReturn(children);
    when(shape.getShapeView()).thenReturn(wiresShape);
    when(graphIndex.getEdge(connectorUUID)).thenReturn(connectorEdge);
    when(connectorEdge.getContent()).thenReturn(viewConnector);
    when(connectorGroup.getUserData()).thenReturn(new WiresUtils.UserData(connectorUUID, ""));
    tested.init(canvasHandler);
    tested.register(element);
    Point2D location = new Point2D(45d, 65.5d);
    tested.move(new Element[] { element }, new Point2D[] { location });
    ArgumentCaptor<CanvasCommand> commandArgumentCaptor = forClass(CanvasCommand.class);
    verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
    ArgumentCaptor<ShapeLocationsChangedEvent> shapeLocationsChangedEventCaptor = forClass(ShapeLocationsChangedEvent.class);
    verify(shapeLocationsChangedEvent, times(1)).fire(shapeLocationsChangedEventCaptor.capture());
    assertTrue(shapeLocationsChangedEventCaptor.getValue() instanceof ShapeLocationsChangedEvent);
    // assert parent node move
    final CompositeCommand command = (CompositeCommand) commandArgumentCaptor.getValue();
    UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) command.getCommands().get(0);
    assertEquals(element, updateElementPositionCommand.getElement());
    assertEquals(location, updateElementPositionCommand.getLocation());
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) MagnetManager(com.ait.lienzo.client.core.shape.wires.MagnetManager) NFastArrayList(com.ait.tooling.nativetools.client.collection.NFastArrayList) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) WiresUtils(org.kie.workbench.common.stunner.client.lienzo.canvas.wires.WiresUtils) MultiPath(com.ait.lienzo.client.core.shape.MultiPath) WiresConnector(com.ait.lienzo.client.core.shape.wires.WiresConnector) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) WiresConnection(com.ait.lienzo.client.core.shape.wires.WiresConnection) Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) WiresShape(com.ait.lienzo.client.core.shape.wires.WiresShape) ShapeLocationsChangedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.ShapeLocationsChangedEvent) WiresShapeView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView) WiresMagnet(com.ait.lienzo.client.core.shape.wires.WiresMagnet) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 17 with Group

use of com.ait.lienzo.client.core.shape.Group in project kie-wb-common by kiegroup.

the class ShapeGlyphDragHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    proxyPanel = spy(new LienzoPanelImpl(DRAG_PROXY_WIDTH, DRAG_PROXY_HEIGHT));
    when(proxyPanel.getElement()).thenReturn(proxyElement);
    when(proxyElement.getStyle()).thenReturn(proxyStyle);
    handlerRegistrations = new ArrayList<>();
    glyphGroup = new Group();
    when(glyphLienzoGlyphRenderer.render(eq(glyph), anyDouble(), anyDouble())).thenReturn(glyphGroup);
    when(glyphDragItem.getHeight()).thenReturn(DRAG_PROXY_WIDTH);
    when(glyphDragItem.getWidth()).thenReturn(DRAG_PROXY_HEIGHT);
    when(glyphDragItem.getShape()).thenReturn(glyph);
    when(rootPanel.addDomHandler(any(MouseMoveHandler.class), eq(MouseMoveEvent.getType()))).thenReturn(moveHandlerReg);
    when(rootPanel.addDomHandler(any(MouseUpHandler.class), eq(MouseUpEvent.getType()))).thenReturn(upHandlerReg);
    when(rootPanel.addDomHandler(any(KeyDownHandler.class), eq(KeyDownEvent.getType()))).thenReturn(keyHandlerReg);
    tested = new ShapeGlyphDragHandler(glyphLienzoGlyphRenderer, handlerRegistrations, () -> rootPanel, item -> proxyPanel, (task, timeout) -> task.execute());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MouseMoveEvent(com.google.gwt.event.dom.client.MouseMoveEvent) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) MouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler) RunWith(org.junit.runner.RunWith) Group(com.ait.lienzo.client.core.shape.Group) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) AbsolutePanel(com.google.gwt.user.client.ui.AbsolutePanel) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) LienzoMockitoTestRunner(com.ait.lienzo.test.LienzoMockitoTestRunner) Layer(com.ait.lienzo.client.core.shape.Layer) Style(com.google.gwt.dom.client.Style) ArgumentCaptor(org.mockito.ArgumentCaptor) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) MouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler) LienzoPanelImpl(com.ait.lienzo.client.widget.panel.impl.LienzoPanelImpl) Callback(org.kie.workbench.common.stunner.client.lienzo.components.glyph.ShapeGlyphDragHandler.Callback) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ArgumentMatchers.anyDouble(org.mockito.ArgumentMatchers.anyDouble) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) MouseUpEvent(com.google.gwt.event.dom.client.MouseUpEvent) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Group(com.ait.lienzo.client.core.shape.Group) MouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) MouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler) LienzoPanelImpl(com.ait.lienzo.client.widget.panel.impl.LienzoPanelImpl) Before(org.junit.Before)

Example 18 with Group

use of com.ait.lienzo.client.core.shape.Group in project kie-wb-common by kiegroup.

the class WiresUtilsTest method isWiresShapeWhenWiresContainer.

@Test
public void isWiresShapeWhenWiresContainer() {
    final WiresContainer wc = new WiresContainer(new Group());
    assertFalse(WiresUtils.isWiresShape(wc));
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) WiresContainer(com.ait.lienzo.client.core.shape.wires.WiresContainer) Test(org.junit.Test)

Example 19 with Group

use of com.ait.lienzo.client.core.shape.Group in project kie-wb-common by kiegroup.

the class WiresLayerTest method setUp.

@Before
public void setUp() throws Exception {
    Group shapeGroup = new Group();
    when(shape.uuid()).thenReturn(SHAPE_UUID);
    when(shape.getGroup()).thenReturn(shapeGroup);
    Group connectorGroup = new Group();
    when(connector.getGroup()).thenReturn(connectorGroup);
    when(wiresManager.getMagnetManager()).thenReturn(magnetManager);
    tested = new WiresLayer();
    tested.use(wiresManager);
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) Before(org.junit.Before)

Example 20 with Group

use of com.ait.lienzo.client.core.shape.Group in project kie-wb-common by kiegroup.

the class LienzoPictureGlyphRendererTest method testRender.

@Test
@SuppressWarnings("unchecked")
public void testRender() {
    final Group glyphView = tested.render(glyph, 100, 100);
    assertNotNull(glyphView);
    verify(pictureBuilder, times(1)).accept(eq("http://url"), any(Consumer.class));
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) Consumer(java.util.function.Consumer) BiConsumer(java.util.function.BiConsumer) Test(org.junit.Test)

Aggregations

Group (com.ait.lienzo.client.core.shape.Group)66 Test (org.junit.Test)17 Rectangle (com.ait.lienzo.client.core.shape.Rectangle)10 Before (org.junit.Before)10 Text (com.ait.lienzo.client.core.shape.Text)9 GridRenderer (org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.GridRenderer)8 Layer (com.ait.lienzo.client.core.shape.Layer)7 Point2D (com.ait.lienzo.client.core.types.Point2D)7 Command (org.uberfire.mvp.Command)6 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)4 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)4 Line (com.ait.lienzo.client.core.shape.Line)3 ArrayList (java.util.ArrayList)3 SVGContainer (org.kie.workbench.common.stunner.svg.client.shape.view.SVGContainer)3 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)3 GridRendererTheme (org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.themes.GridRendererTheme)3 IPathClipper (com.ait.lienzo.client.core.shape.IPathClipper)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)2 WiresShape (com.ait.lienzo.client.core.shape.wires.WiresShape)2 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)2