use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.
the class EdgeParser method parseExtendedProperties.
@Override
protected void parseExtendedProperties(final ObjectParser propertiesParser) {
super.parseExtendedProperties(propertiesParser);
ViewConnector viewConnector = (ViewConnector) element.getContent();
viewConnector.getTargetConnection().ifPresent(connection -> appendConnAuto((Connection) connection, Bpmn2OryxManager.TARGET, propertiesParser));
viewConnector.getSourceConnection().ifPresent(connection -> appendConnAuto((Connection) connection, Bpmn2OryxManager.SOURCE, propertiesParser));
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method testMagnetsInLane.
private void testMagnetsInLane(Diagram<Graph, Metadata> diagram) throws Exception {
Node userTaskNode = (Node) findElementByContentType(diagram, UserTask.class);
Node scriptTaskNode = (Node) findElementByContentType(diagram, ScriptTask.class);
assertNotNull(userTaskNode);
assertNotNull(scriptTaskNode);
ViewConnector userTaskInEdgeConnector = getInEdgeViewConnector(userTaskNode);
ViewConnector scriptTaskInEdgeConnector = getInEdgeViewConnector(scriptTaskNode);
assertNotNull(userTaskInEdgeConnector);
assertNotNull(scriptTaskInEdgeConnector);
ViewConnector userTaskOutEdgeConnector = getOutEdgeViewConnector(userTaskNode);
ViewConnector scriptTaskOutEdgeConnector = getOutEdgeViewConnector(scriptTaskNode);
assertNotNull(userTaskOutEdgeConnector);
assertNotNull(scriptTaskOutEdgeConnector);
// userTaskInEdgeConnector is from magnet right-middle to middle-top
assertTrue(userTaskInEdgeConnector.getSourceConnection().isPresent());
assertTrue(userTaskInEdgeConnector.getTargetConnection().isPresent());
Connection sourceConnection = (Connection) userTaskInEdgeConnector.getSourceConnection().get();
Connection targetConnection = (Connection) userTaskInEdgeConnector.getTargetConnection().get();
assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(24d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(68d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
// scriptTaskInEdgeConnector is from magnet right-bottom to left-top
assertTrue(scriptTaskInEdgeConnector.getSourceConnection().isPresent());
assertTrue(scriptTaskInEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (Connection) scriptTaskInEdgeConnector.getSourceConnection().get();
targetConnection = (Connection) scriptTaskInEdgeConnector.getTargetConnection().get();
assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
// userTaskOutEdgeConnector is from magnet right-bottom to left-top
assertTrue(userTaskOutEdgeConnector.getSourceConnection().isPresent());
assertTrue(userTaskOutEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (Connection) userTaskOutEdgeConnector.getSourceConnection().get();
targetConnection = (Connection) userTaskOutEdgeConnector.getTargetConnection().get();
assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
// scriptTaskOutEdgeConnector is from magnet right-top to left-middle
assertTrue(scriptTaskOutEdgeConnector.getSourceConnection().isPresent());
assertTrue(scriptTaskOutEdgeConnector.getTargetConnection().isPresent());
sourceConnection = (Connection) scriptTaskOutEdgeConnector.getSourceConnection().get();
targetConnection = (Connection) scriptTaskOutEdgeConnector.getTargetConnection().get();
assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
assertEquals(0d, sourceConnection.getLocation().getY(), 0.1d);
assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
assertEquals(14d, targetConnection.getLocation().getY(), 0.1d);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.
the class ConnectorShapeTest method testApplyConnections.
@Test
@SuppressWarnings("unchecked")
public void testApplyConnections() {
final Object def = mock(Object.class);
final Edge<ViewConnector<Object>, Node> edge = new EdgeImpl<>("uuid1");
final ViewConnectorImpl<Object> content = new ViewConnectorImpl<>(def, new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(15d, 40d)));
Connection sourceConnection = mock(Connection.class);
Connection targetConnection = mock(Connection.class);
content.setSourceConnection(sourceConnection);
content.setTargetConnection(targetConnection);
edge.setContent(content);
final ShapeView<?> source = mock(ShapeView.class);
final ShapeView<?> target = mock(ShapeView.class);
tested.applyConnections(edge, source, target, MutationContext.STATIC);
verify(((IsConnector) shapeView), times(1)).connect(eq(source), eq(sourceConnection), eq(target), eq(targetConnection));
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.
the class NodeBuilderControlImpl method build.
@Override
@SuppressWarnings("unchecked")
public void build(final NodeBuildRequest request, final BuildCallback buildCallback) {
final double x = request.getX();
final double y = request.getY();
final Node<? extends View<?>, Edge> node = request.getNode();
final Edge<? extends ViewConnector<?>, Node> inEdge = request.getInEdge();
final Connection sourceConnection = request.getSourceConnection();
final Connection targetConnection = request.getTargetConnection();
if (null != node) {
final Object nodeDef = node.getContent().getDefinition();
final String nodeId = clientDefinitionManager.adapters().forDefinition().getId(nodeDef);
final ElementBuilderControlImpl ebc = getElementBuilderControl();
final Node<View<?>, Edge> parent = ebc.getParent(x, y);
final Point2D childCoordinates = ebc.getChildCoordinates(parent, x, y);
final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
ebc.getElementCommands(node, parent, childCoordinates.getX(), childCoordinates.getY(), new AbstractElementBuilderControl.CommandsCallback() {
@Override
public void onComplete(final String uuid, final List<Command<AbstractCanvasHandler, CanvasViolation>> commands) {
final CompositeCommand.Builder commandBuilder = new CompositeCommand.Builder().addCommands(commands);
if (inEdge != null) {
final Object edgeDef = inEdge.getContent().getDefinition();
final String edgeId = clientDefinitionManager.adapters().forDefinition().getId(edgeDef);
// The commands to batch for the edge that connects both nodes.
commandBuilder.addCommand(commandFactory.addConnector(inEdge.getSourceNode(), inEdge, sourceConnection, ssid));
commandBuilder.addCommand(commandFactory.setTargetNode(node, inEdge, targetConnection));
}
final CommandResult<CanvasViolation> results = elementBuilderControl.getCommandManager().execute(canvasHandler, commandBuilder.build());
if (!CommandUtils.isError(results)) {
updateConnectorShape(inEdge, node, sourceConnection, targetConnection);
}
buildCallback.onSuccess(uuid);
}
@Override
public void onError(final ClientRuntimeError error) {
buildCallback.onError(error);
}
});
}
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.
the class SetConnectionSourceNodeCommandTest method testExecuteOnlyConnectionsHasBeenChanged.
@Test
@SuppressWarnings("unchecked")
public void testExecuteOnlyConnectionsHasBeenChanged() {
when(edge.getSourceNode()).thenReturn(node);
MagnetConnection connection = MagnetConnection.Builder.at(MAGNETX, MAGNETY);
tested = new SetConnectionSourceNodeCommand(node, edge, connection);
CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
assertEquals(CommandResult.Type.INFO, result.getType());
verify(ruleManager, never()).evaluate(eq(ruleSet), any(RuleEvaluationContext.class));
verify(edgeContent, times(1)).setSourceConnection(eq(connection));
verify(edgeContent, never()).setTargetConnection(any(Connection.class));
assertEquals(sourceMagnet.get(), tested.lastConnection);
}
Aggregations