use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.
the class ConnectorShape method applyConnections.
@Override
public void applyConnections(final Edge<ViewConnector<W>, Node> element, final ShapeView<?> source, final ShapeView<?> target, final MutationContext mutationContext) {
final ViewConnector connectionContent = element.getContent();
final Connection sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null);
final Connection targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null);
if (null != source && null != target) {
IsConnector shapeView = (IsConnector) getShapeView();
shapeView.connect(source, sourceConnection, target, targetConnection);
}
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.
the class SetConnectionTargetNodeCommandTest method testExecuteOnlyConnectionsHasBeenChanged.
@Test
@SuppressWarnings("unchecked")
public void testExecuteOnlyConnectionsHasBeenChanged() {
when(edge.getTargetNode()).thenReturn(node);
MagnetConnection connection = MagnetConnection.Builder.at(MAGNETX, MAGNETY);
tested = new SetConnectionTargetNodeCommand(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)).setTargetConnection(eq(connection));
verify(edgeContent, never()).setSourceConnection(any(Connection.class));
assertEquals(targetMagnet.get(), tested.lastConnection);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest 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 AbstractEdgeBuilder method buildTargetConnection.
private void buildTargetConnection(BuilderContext context, T edge, Node node, GraphCommandFactory commandFactory) {
Double[] targetDocker = null;
if (dockers != null && dockers.size() > 1) {
targetDocker = dockers.get(dockers.size() - 1);
}
Connection targetConnection = null;
if (null != targetDocker) {
targetConnection = MagnetConnection.Builder.at(targetDocker[0], targetDocker[1]).setAuto(isTargetAutoConnection());
}
SetConnectionTargetNodeCommand setTargetNodeCommand = commandFactory.setTargetNode(node, edge, targetConnection);
CommandResult<RuleViolation> setTargetResult = context.execute(setTargetNodeCommand);
if (hasErrors(setTargetResult)) {
throw new RuntimeException("Error building BPMN graph. Command 'SetConnectionTargetNodeCommand' execution failed.");
}
}
use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.
the class AbstractNodeBuilder method afterNodeBuild.
@SuppressWarnings("unchecked")
protected void afterNodeBuild(final BuilderContext context, final T node) {
// Outgoing connections.
if (outgoingResourceIds != null && !outgoingResourceIds.isEmpty()) {
for (String outgoingNodeId : outgoingResourceIds) {
GraphObjectBuilder<?, ?> outgoingBuilder = getBuilder(context, outgoingNodeId);
if (outgoingBuilder == null) {
throw new RuntimeException("No outgoing edge builder for " + outgoingNodeId);
}
final List<Command<GraphCommandExecutionContext, RuleViolation>> commands = new LinkedList<>();
// If outgoing element it's a node means that it's docked.
if (outgoingBuilder instanceof AbstractNodeBuilder) {
// Command - Create the docked node.
Node docked = (Node) outgoingBuilder.build(context);
commands.add(context.getCommandFactory().addDockedNode(node, docked));
// Obtain docked position and use those for the docked node.
final List<Double[]> dockers = ((AbstractNodeBuilder) outgoingBuilder).dockers;
if (!dockers.isEmpty()) {
// TODO: Use not only first docker coordinates?
Double[] dCoords = dockers.get(0);
double x = dCoords[0];
double y = dCoords[1];
commands.add(context.getCommandFactory().updatePosition(docked, new Point2D(x, y)));
}
} else {
// Create the outgoing edge.
AbstractEdgeBuilder edgeBuilder = (AbstractEdgeBuilder) outgoingBuilder;
Edge edge = (Edge) edgeBuilder.build(context);
if (edge != null) {
// Command - Execute the graph command to set the node as the edge connection's source..
Double[] sourceDocker = null;
final List<Double[]> dockers = ((AbstractEdgeBuilder) outgoingBuilder).dockers;
if (dockers != null && dockers.size() > 1) {
sourceDocker = dockers.get(0);
}
Connection sourceConnection = null;
if (null != sourceDocker) {
sourceConnection = MagnetConnection.Builder.at(sourceDocker[0], sourceDocker[1]).setAuto(edgeBuilder.isSourceAutoConnection());
}
commands.add(context.getCommandFactory().setSourceNode(node, edge, sourceConnection));
}
}
if (!commands.isEmpty()) {
for (Command<GraphCommandExecutionContext, RuleViolation> command : commands) {
doExecuteCommand(context, command);
}
}
}
}
// Children connections.
if (childNodeIds != null && !childNodeIds.isEmpty()) {
for (String childNodeId : childNodeIds) {
GraphObjectBuilder<?, ?> childNodeBuilder = getBuilder(context, childNodeId);
if (childNodeBuilder == null) {
throw new RuntimeException("No child node builder for " + childNodeId);
}
Command<GraphCommandExecutionContext, RuleViolation> command = null;
if (childNodeBuilder instanceof NodeObjectBuilder) {
// Command - Create the child node and the parent-child relationship.
Node childNode = (Node) childNodeBuilder.build(context);
command = context.getCommandFactory().addChildNode(node, childNode);
}
if (null != command) {
doExecuteCommand(context, command);
}
}
}
}
Aggregations