use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class LocationControlImplTest method testLocationAcceptor.
@Test
@SuppressWarnings("unchecked")
public void testLocationAcceptor() {
tested.enable(canvasHandler);
tested.register(element);
ArgumentCaptor<ILocationAcceptor> locationAcceptorArgumentCaptor = ArgumentCaptor.forClass(ILocationAcceptor.class);
verify(wiresManager, times(1)).setLocationAcceptor(locationAcceptorArgumentCaptor.capture());
final ILocationAcceptor locationAcceptor = locationAcceptorArgumentCaptor.getValue();
final WiresShapeView wiresContainer = mock(WiresShapeView.class);
when(wiresContainer.getUUID()).thenReturn(ELEMENT_UUID);
final com.ait.lienzo.client.core.types.Point2D point = new com.ait.lienzo.client.core.types.Point2D(40d, 50d);
locationAcceptor.accept(new WiresContainer[] { wiresContainer }, new com.ait.lienzo.client.core.types.Point2D[] { point });
ArgumentCaptor<CanvasCommand> commandArgumentCaptor = ArgumentCaptor.forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
final UpdateElementPositionCommand command = (UpdateElementPositionCommand) commandArgumentCaptor.getValue();
assertEquals(element, command.getElement());
assertEquals(new Point2D(40d, 50d), command.getLocation());
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class ResizeControlImplTest method testResize.
@Test
@SuppressWarnings("unchecked")
public void testResize() {
when(commandManager.execute(eq(canvasHandler), any(Command.class))).thenReturn(CanvasCommandResultBuilder.SUCCESS);
tested.enable(canvasHandler);
assertFalse(tested.isRegistered(element));
tested.register(element);
verify(shapeEventHandler, times(1)).supports(eq(ViewEventType.RESIZE));
final ArgumentCaptor<ResizeHandler> resizeHandlerArgumentCaptor = ArgumentCaptor.forClass(ResizeHandler.class);
verify(shapeEventHandler, times(1)).addHandler(eq(ViewEventType.RESIZE), resizeHandlerArgumentCaptor.capture());
final ResizeHandler resizeHandler = resizeHandlerArgumentCaptor.getValue();
final double x = 121.45d;
final double y = 23.456d;
final double width = 100d;
final double height = 200d;
final ResizeEvent event = new ResizeEvent(x, y, x, y, width, height);
resizeHandler.end(event);
final ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
final Command command = commandArgumentCaptor.getValue();
assertNotNull(command);
assertTrue(command instanceof AbstractCompositeCommand);
final List commands = ((AbstractCompositeCommand) command).getCommands();
assertNotNull(commands);
assertEquals(4, commands.size());
assertTrue(commands.get(0) instanceof UpdateElementPositionCommand);
final UpdateElementPositionCommand positionCommand = (UpdateElementPositionCommand) commands.get(0);
assertEquals(element, positionCommand.getElement());
assertEquals(new Point2D(x, y), positionCommand.getLocation());
assertTrue(commands.get(1) instanceof UpdateElementPropertyCommand);
final UpdateElementPropertyCommand wPropertyCommand = (UpdateElementPropertyCommand) commands.get(1);
assertEquals(element, wPropertyCommand.getElement());
assertEquals(W_PROPERTY_ID, wPropertyCommand.getPropertyId());
assertEquals(width, wPropertyCommand.getValue());
assertTrue(commands.get(2) instanceof UpdateElementPropertyCommand);
final UpdateElementPropertyCommand hPropertyCommand = (UpdateElementPropertyCommand) commands.get(2);
assertEquals(element, hPropertyCommand.getElement());
assertEquals(H_PROPERTY_ID, hPropertyCommand.getPropertyId());
assertEquals(height, hPropertyCommand.getValue());
assertTrue(commands.get(3) instanceof UpdateElementPropertyCommand);
final UpdateElementPropertyCommand rPropertyCommand = (UpdateElementPropertyCommand) commands.get(3);
assertEquals(element, rPropertyCommand.getElement());
assertEquals(R_PROPERTY_ID, rPropertyCommand.getPropertyId());
assertEquals(50d, rPropertyCommand.getValue());
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class ObserverBuilderControlTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
ServiceCallback<Node<View<Object>, Edge>> callback = (ServiceCallback<Node<View<Object>, Edge>>) (invocationOnMock.getArguments()[2]);
view = new ViewImpl<>(new Object(), new BoundsImpl(new BoundImpl(0.0, 0.0), new BoundImpl(10.0, 20.0)));
Node<View<Object>, Edge> item = new NodeImpl<>("UUID");
item.setContent(view);
callback.onSuccess(item);
return null;
}
}).when(clientFactoryServices).newElement(anyString(), anyString(), any(ServiceCallback.class));
when(graphBoundsIndexer.setRootUUID(anyString())).thenReturn(graphBoundsIndexer);
AdapterManager adapters = mock(AdapterManager.class);
DefinitionAdapter definitionAdapter = mock(DefinitionAdapter.class);
DefinitionSetRuleAdapter rulesAdapter = mock(DefinitionSetRuleAdapter.class);
when(definitionAdapter.getId(any())).thenReturn("Object");
when(rulesAdapter.getRuleSet(any())).thenReturn(mock(RuleSet.class));
when(adapters.forDefinition()).thenReturn(definitionAdapter);
when(adapters.forRules()).thenReturn(rulesAdapter);
when(clientDefinitionManager.adapters()).thenReturn(adapters);
when(clientDefinitionManager.definitionSets()).thenReturn(mock(TypeDefinitionSetRegistry.class));
when(canvasCommandFactory.addNode(any(Node.class), anyString())).thenAnswer(new Answer<Command>() {
@Override
public Command answer(InvocationOnMock invocationOnMock) {
Node node = (Node) invocationOnMock.getArguments()[0];
String uid = (String) invocationOnMock.getArguments()[1];
return new AddCanvasNodeCommand(node, uid);
}
});
when(canvasCommandFactory.updatePosition(any(Node.class), any(Point2D.class))).thenAnswer(new Answer<Command>() {
@Override
public Command answer(InvocationOnMock invocationOnMock) {
Node node = (Node) invocationOnMock.getArguments()[0];
Point2D location = (Point2D) invocationOnMock.getArguments()[1];
return new UpdateElementPositionCommand(node, location);
}
});
when(canvasCommandFactory.draw()).thenReturn(mock(CanvasCommand.class));
ShapeSet shapeSet = mock(ShapeSet.class);
ShapeFactory shapeFactory = mock(ShapeFactory.class);
when(shapeFactory.newShape(any())).thenReturn(mock(ElementShape.class));
when(shapeSet.getShapeFactory()).thenReturn(shapeFactory);
when(shapeManager.getShapeSet(anyString())).thenReturn(shapeSet);
when(shapeManager.getDefaultShapeSet(anyString())).thenReturn(shapeSet);
tested = new ObserverBuilderControl(clientDefinitionManager, clientFactoryServices, graphUtils, ruleManager, canvasCommandFactory, graphBoundsIndexer, canvasLayoutUtils, mock(Event.class));
Diagram diagram = mock(Diagram.class);
Metadata metadata = mock(Metadata.class);
when(metadata.getCanvasRootUUID()).thenReturn("ID");
when(diagram.getMetadata()).thenReturn(metadata);
MutableIndex index = mock(MutableIndex.class);
Graph graph = mock(Graph.class);
DefinitionSet graphContent = mock(DefinitionSet.class);
when(graphContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(10d, 10d), new BoundImpl(100d, 100d)));
when(graph.getContent()).thenReturn(graphContent);
when(index.getGraph()).thenReturn(graph);
when(graphIndexBuilder.build(any(Graph.class))).thenReturn(index);
canvasHandler = new CanvasHandlerImpl(clientDefinitionManager, canvasCommandFactory, clientFactoryServices, ruleManager, graphUtils, graphIndexBuilder, shapeManager, mock(TextPropertyProviderFactory.class), mock(Event.class), null, null, null);
canvasHandler.handle(mock(AbstractCanvas.class));
canvasHandler.draw(diagram, mock(ParameterizedCommand.class));
when(diagram.getGraph()).thenReturn(graph);
when(graph.nodes()).thenReturn(Collections.emptyList());
CanvasCommandManager commandManager = mock(CanvasCommandManager.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Command command = (Command) invocationOnMock.getArguments()[1];
command.execute(invocationOnMock.getArguments()[0]);
return null;
}
}).when(commandManager).execute(any(), any(Command.class));
when(commandManagerProvider.getCommandManager()).thenReturn(commandManager);
tested.enable(canvasHandler);
tested.setCommandManagerProvider(commandManagerProvider);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D 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())));
}
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.
the class AbstractElementBuilderControl method build.
@Override
@SuppressWarnings("unchecked")
public void build(final ElementBuildRequest<AbstractCanvasHandler> request, final BuildCallback buildCallback) {
if (null == canvasHandler) {
buildCallback.onSuccess(null);
return;
}
double x = request.getX();
;
double y = request.getY();
;
if (checkOutOfBoundsCanvas(x, y)) {
buildCallback.onError(new ClientRuntimeError(new ElementOutOfBoundsException("Element is placed outside canvas bounds")));
return;
}
final Object definition = request.getDefinition();
// Notify processing starts.
fireProcessingStarted();
final Node<View<?>, Edge> parent = getParent(x, y);
final Point2D childCoordinates = getChildCoordinates(parent, x, y);
getCommands(definition, parent, childCoordinates.getX(), childCoordinates.getY(), new CommandsCallback() {
@Override
public void onComplete(final String uuid, final List<Command<AbstractCanvasHandler, CanvasViolation>> commands) {
getCommandManager().execute(canvasHandler, new CompositeCommand.Builder().addCommands(commands).build());
buildCallback.onSuccess(uuid);
// Notify processing ends.
fireProcessingCompleted();
}
@Override
public void onError(final ClientRuntimeError error) {
buildCallback.onError(error);
// Notify processing ends.
fireProcessingCompleted();
}
});
}
Aggregations