use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand in project kie-wb-common by kiegroup.
the class AbstractEdgeBuilder method buildTargetNode.
private Node buildTargetNode(BuilderContext context, String outgoingNodeId, GraphCommandFactory commandFactory) {
GraphObjectBuilder<?, ?> outgoingNodeBuilder = getBuilder(context, outgoingNodeId);
if (outgoingNodeBuilder == null) {
throw new RuntimeException("No edge for " + outgoingNodeId);
}
Node node = (Node) outgoingNodeBuilder.build(context);
AddNodeCommand addNodeCommand = commandFactory.addNode(node);
CommandResult<RuleViolation> addEdgeResult = context.execute(addNodeCommand);
if (hasErrors(addEdgeResult)) {
throw new RuntimeException("Error building BPMN graph. Command 'addNodeCommand' execution failed.");
}
return node;
}
use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand in project kie-wb-common by kiegroup.
the class NodeProxyTest method verifyCreateTargetNode.
@SuppressWarnings("all")
private void verifyCreateTargetNode(CanvasCommand<AbstractCanvasHandler> addConnectorCommand, CanvasCommand<AbstractCanvasHandler> addNodeCommand, CanvasCommand<AbstractCanvasHandler> setTargetNodeCommand) {
tested.init();
tested.start(1d, 2d);
verify(proxy, times(1)).start(eq(1d), eq(2d));
NodeShape targetNodeShape = view.getShapeBuilder().get();
assertEquals(targetShape, targetNodeShape);
ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
verify(proxy, times(1)).execute(commandCaptor.capture());
DeferredCompositeCommand command = (DeferredCompositeCommand) commandCaptor.getValue();
List commands = command.getCommands();
assertEquals(3, command.size());
DeferredCommand c0 = (DeferredCommand) commands.get(0);
assertEquals(addNodeCommand, c0.getCommand());
DeferredCommand c1 = (DeferredCommand) commands.get(1);
assertEquals(addConnectorCommand, c1.getCommand());
DeferredCommand c2 = (DeferredCommand) commands.get(2);
assertEquals(setTargetNodeCommand, c2.getCommand());
}
use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand in project kie-wb-common by kiegroup.
the class NodeProxyTest method testCreateTargetNodeInSomeParent.
@Test
@SuppressWarnings("all")
public void testCreateTargetNodeInSomeParent() {
Node<View<?>, Edge> parentNode = new NodeImpl<>(PARENT_NODE_ID);
parentNode.setContent(new ViewImpl<>(mock(Object.class), Bounds.create()));
DirectGraphCommandExecutionContext context = new DirectGraphCommandExecutionContext(definitionManager, factoryManager, new MapIndexBuilder().build(graph));
new AddNodeCommand(parentNode).execute(context);
new SetChildrenCommand(parentNode, sourceNode).execute(context);
CanvasCommand<AbstractCanvasHandler> addConnector = mock(CanvasCommand.class);
CanvasCommand<AbstractCanvasHandler> addNode = mock(CanvasCommand.class);
CanvasCommand<AbstractCanvasHandler> setTargetNode = mock(CanvasCommand.class);
doReturn(addConnector).when(commandFactory).addConnector(eq(sourceNode), eq(edge), Mockito.<MagnetConnection>any(), eq(SHAPE_SET_ID));
doReturn(addNode).when(commandFactory).addChildNode(eq(parentNode), eq(targetNode), eq(SHAPE_SET_ID));
doReturn(setTargetNode).when(commandFactory).setTargetNode(eq(targetNode), eq(edge), any());
verifyCreateTargetNode(addConnector, addNode, setTargetNode);
}
use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand in project kie-wb-common by kiegroup.
the class AbstractNodeBuilder method doBuild.
@Override
@SuppressWarnings("unchecked")
protected T doBuild(final BuilderContext context) {
if (context.getIndex().getNode(this.nodeId) == null) {
FactoryManager factoryManager = context.getFactoryManager();
// Build the graph node for the definition.
String definitionId = getDefinitionToBuild(context);
T result = (T) factoryManager.newElement(this.nodeId, definitionId);
// Set the def properties.
setProperties(context, (BPMNDefinition) result.getContent().getDefinition());
// View Bounds.
setBounds(context, result);
AddNodeCommand addNodeCommand = context.getCommandFactory().addNode(result);
if (doExecuteCommand(context, addNodeCommand)) {
// Post processing.
afterNodeBuild(context, result);
} else {
// TODO: throw an exception and handle the error.
}
return result;
} else {
return (T) context.getIndex().getNode(this.nodeId);
}
}
use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand in project kie-wb-common by kiegroup.
the class GraphBuilder method addNode.
private void addNode(Node node) {
AddNodeCommand addNodeCommand = commandFactory.addNode(node);
execute(addNodeCommand);
}
Aggregations