@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); final CompositeCommand command = (CompositeCommand) commandArgumentCaptor.getValue(); UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) command.getCommands().get(0); assertEquals(element, updateElementPositionCommand.getElement()); assertEquals(location, updateElementPositionCommand.getLocation()); }
@Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> move(final Element[] elements, final Point2D[] locations) { if (elements.length != locations.length) { throw new IllegalArgumentException("The length for the elements to move " + "does not match the locations provided."); } final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .forward(); for (int i = 0; i < elements.length; i++) { final Element element = elements[i]; builder.addCommand(createMoveCommand(element, locations[i])); } final Command<AbstractCanvasHandler, CanvasViolation> command = builder.build(); CommandResult<CanvasViolation> result = getCommandManager().allow(canvasHandler, command); if (!CommandUtils.isError(result)) { result = getCommandManager().execute(canvasHandler, command); if (!CommandUtils.isError(result)) { List<String> uuids = Arrays.stream(elements).map(Element::getUUID).collect(Collectors.toList()); shapeLocationsChangedEvent.fire(new ShapeLocationsChangedEvent(uuids, canvasHandler)); } } return result; }
LocationControlImpl extends AbstractCanvasHandlerRegistrationControl<AbstractCanvasHandler> implements LocationControl<AbstractCanvasHandler, Element>,
                   CanvasControl.SessionAware<EditorSession> { @Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> move(final Element[] elements, final Point2D[] locations) { if (elements.length != locations.length) { throw new IllegalArgumentException("The length for the elements to move " + "does not match the locations provided."); } final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .forward(); for (int i = 0; i < elements.length; i++) { final Element element = elements[i]; builder.addCommand(createMoveCommand(element, locations[i])); } final Command<AbstractCanvasHandler, CanvasViolation> command = builder.build(); CommandResult<CanvasViolation> result = getCommandManager().allow(canvasHandler, command); if (!CommandUtils.isError(result)) { result = getCommandManager().execute(canvasHandler, command); if (!CommandUtils.isError(result)) { List<String> uuids = Arrays.stream(elements).map(Element::getUUID).collect(Collectors.toList()); shapeLocationsChangedEvent.fire(new ShapeLocationsChangedEvent(uuids, canvasHandler)); } } return result; } }
LocationControlImpl extends AbstractCanvasHandlerRegistrationControl<AbstractCanvasHandler> implements LocationControl<AbstractCanvasHandler, Element>,
                   CanvasControl.SessionAware<EditorSession> { @Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> move(final Element[] elements, final Point2D[] locations) { if (elements.length != locations.length) { throw new IllegalArgumentException("The length for the elements to move " + "does not match the locations provided."); } final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .forward(); for (int i = 0; i < elements.length; i++) { final Element element = elements[i]; builder.addCommand(createMoveCommand(element, locations[i])); } final Command<AbstractCanvasHandler, CanvasViolation> command = builder.build(); CommandResult<CanvasViolation> result = getCommandManager().allow(canvasHandler, command); if (!CommandUtils.isError(result)) { result = getCommandManager().execute(canvasHandler, command); if (!CommandUtils.isError(result)) { List<String> uuids = Arrays.stream(elements).map(Element::getUUID).collect(Collectors.toList()); shapeLocationsChangedEvent.fire(new ShapeLocationsChangedEvent(uuids, canvasHandler)); } } return result; } protected  LocationControlImpl(); @Inject  LocationControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory,
                               final Event<ShapeLocationsChangedEvent> shapeLocationsChangedEvent,
                               final Event<CanvasSelectionEvent> selectionEvent); }
LocationControlImpl extends AbstractCanvasHandlerRegistrationControl<AbstractCanvasHandler> implements LocationControl<AbstractCanvasHandler, Element>,
                   CanvasControl.SessionAware<EditorSession> { @Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> move(final Element[] elements, final Point2D[] locations) { if (elements.length != locations.length) { throw new IllegalArgumentException("The length for the elements to move " + "does not match the locations provided."); } final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .forward(); for (int i = 0; i < elements.length; i++) { final Element element = elements[i]; builder.addCommand(createMoveCommand(element, locations[i])); } final Command<AbstractCanvasHandler, CanvasViolation> command = builder.build(); CommandResult<CanvasViolation> result = getCommandManager().allow(canvasHandler, command); if (!CommandUtils.isError(result)) { result = getCommandManager().execute(canvasHandler, command); if (!CommandUtils.isError(result)) { List<String> uuids = Arrays.stream(elements).map(Element::getUUID).collect(Collectors.toList()); shapeLocationsChangedEvent.fire(new ShapeLocationsChangedEvent(uuids, canvasHandler)); } } return result; } protected  LocationControlImpl(); @Inject  LocationControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory,
                               final Event<ShapeLocationsChangedEvent> shapeLocationsChangedEvent,
                               final Event<CanvasSelectionEvent> selectionEvent); Collection<String> getSelectedIDs(); @Override void bind(final EditorSession session); void handleArrowKeys(final Key... keys); @Override void setCommandManagerProvider(final CommandManagerProvider<AbstractCanvasHandler> provider); @Override @SuppressWarnings("unchecked") void register(final Element element); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> move(final Element[] elements,
                                               final Point2D[] locations); }
LocationControlImpl extends AbstractCanvasHandlerRegistrationControl<AbstractCanvasHandler> implements LocationControl<AbstractCanvasHandler, Element>,
                   CanvasControl.SessionAware<EditorSession> { @Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> move(final Element[] elements, final Point2D[] locations) { if (elements.length != locations.length) { throw new IllegalArgumentException("The length for the elements to move " + "does not match the locations provided."); } final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .forward(); for (int i = 0; i < elements.length; i++) { final Element element = elements[i]; builder.addCommand(createMoveCommand(element, locations[i])); } final Command<AbstractCanvasHandler, CanvasViolation> command = builder.build(); CommandResult<CanvasViolation> result = getCommandManager().allow(canvasHandler, command); if (!CommandUtils.isError(result)) { result = getCommandManager().execute(canvasHandler, command); if (!CommandUtils.isError(result)) { List<String> uuids = Arrays.stream(elements).map(Element::getUUID).collect(Collectors.toList()); shapeLocationsChangedEvent.fire(new ShapeLocationsChangedEvent(uuids, canvasHandler)); } } return result; } protected  LocationControlImpl(); @Inject  LocationControlImpl(final CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory,
                               final Event<ShapeLocationsChangedEvent> shapeLocationsChangedEvent,
                               final Event<CanvasSelectionEvent> selectionEvent); Collection<String> getSelectedIDs(); @Override void bind(final EditorSession session); void handleArrowKeys(final Key... keys); @Override void setCommandManagerProvider(final CommandManagerProvider<AbstractCanvasHandler> provider); @Override @SuppressWarnings("unchecked") void register(final Element element); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> move(final Element[] elements,
                                               final Point2D[] locations);  }