Search in sources :

Example 61 with Node

use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.

the class AbstractEdgeBuilder method afterEdgeBuild.

@SuppressWarnings("unchecked")
protected void afterEdgeBuild(final BuilderContext context, final T edge) {
    // Outgoing connections.
    if (outgoingResourceIds != null && !outgoingResourceIds.isEmpty()) {
        for (String outgoingNodeId : outgoingResourceIds) {
            GraphCommandFactory commandFactory = context.getCommandFactory();
            // Command - Add the node into the graph store.
            Node node = buildTargetNode(context, outgoingNodeId, commandFactory);
            // Command - Set the edge connection's target node.
            buildTargetConnection(context, edge, node, commandFactory);
            // Command - ControlPoints
            buildControlPoints(context, edge, commandFactory);
        }
    }
}
Also used : GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) Node(org.kie.workbench.common.stunner.core.graph.Node)

Example 62 with Node

use of org.kie.workbench.common.stunner.core.graph.Node 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;
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 63 with Node

use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.

the class BPMN2JsonParser method initialize.

/*
        ****************************************************************
        *               Custom Stunner logic
        ****************************************************************
     */
@SuppressWarnings("unchecked")
private void initialize(final ContextualParser.Context parsingContext) {
    Graph graph = diagram.getGraph();
    final Map<String, EdgeParser> edgeParsers = new HashMap<>();
    new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()).traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {

        final Stack<NodeParser> parsers = new Stack<NodeParser>();

        NodeParser currentParser = null;

        @Override
        public void startGraphTraversal(Graph<DefinitionSet, Node<View, Edge>> graph) {
            super.startGraphTraversal(graph);
        }

        @Override
        public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) {
            super.startNodeTraversal(parents, node);
            onNodeTraversal(node);
            return true;
        }

        @Override
        public void startNodeTraversal(final Node<View, Edge> node) {
            super.startNodeTraversal(node);
            onNodeTraversal(node);
        }

        private void onNodeTraversal(final Node node) {
            NodeParser p = new NodeParser("", node);
            if (null != currentParser) {
                parsers.peek().addChild(p);
            } else {
                BPMN2JsonParser.this.rootParser = p;
            }
            currentParser = p;
            List<Edge> outEdges = node.getOutEdges();
            if (null != outEdges && !outEdges.isEmpty()) {
                for (Edge edge : outEdges) {
                    // Only add the edges with view connector types into the resulting structure to generate the bpmn definition.
                    if (edge.getContent() instanceof ViewConnector && !edgeParsers.containsKey(edge.getUUID())) {
                        edgeParsers.put(edge.getUUID(), new EdgeParser("", (Edge) edge));
                    }
                }
            }
        }

        @Override
        public void startEdgeTraversal(Edge<Child, Node> edge) {
            super.startEdgeTraversal(edge);
            parsers.push(currentParser);
        }

        @Override
        public void endEdgeTraversal(Edge<Child, Node> edge) {
            super.endEdgeTraversal(edge);
            currentParser = parsers.pop();
        }

        @Override
        public void endGraphTraversal() {
            super.endGraphTraversal();
        }
    });
    // In oryx format, all edges are added into the main BPMNDiagram node.
    if (null != rootParser && !edgeParsers.isEmpty()) {
        for (EdgeParser edgeParser : edgeParsers.values()) {
            rootParser.addChild(edgeParser);
        }
    }
    // Initialize all the element parsers added in the tree.
    BPMN2JsonParser.this.rootParser.initialize(parsingContext);
    System.out.println("End of children and view traverse");
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Stack(java.util.Stack) Graph(org.kie.workbench.common.stunner.core.graph.Graph) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) List(java.util.List) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child)

Example 64 with Node

use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.

the class CaseManagementAddChildNodeGraphCommand method initialize.

@Override
protected CaseManagementAddChildNodeGraphCommand initialize(final GraphCommandExecutionContext context) {
    final Node parent = getParent(context);
    final Node child = getCandidate();
    this.addCommand(new RegisterNodeCommand(child));
    this.addCommand(new CaseManagementSetChildNodeGraphCommand(parent, child, Optional.of(0), Optional.empty(), Optional.empty()));
    return this;
}
Also used : RegisterNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.RegisterNodeCommand) Node(org.kie.workbench.common.stunner.core.graph.Node)

Example 65 with Node

use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.

the class CaseManagementSetChildNodeGraphCommand method getEdgeForTarget.

@SuppressWarnings("unchecked")
private Optional<Edge> getEdgeForTarget(final Optional<Node> parent, final Node child) {
    return parent.flatMap((p) -> {
        Edge edge = null;
        final List<Edge> outEdges = parent.get().getOutEdges();
        if (!(outEdges == null || outEdges.isEmpty())) {
            for (Edge outEdge : outEdges) {
                if (outEdge.getContent() instanceof Child) {
                    final Node targetNode = outEdge.getTargetNode();
                    if (child.equals(targetNode)) {
                        edge = outEdge;
                        break;
                    }
                }
            }
        }
        return Optional.ofNullable(edge);
    });
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child)

Aggregations

Node (org.kie.workbench.common.stunner.core.graph.Node)153 Edge (org.kie.workbench.common.stunner.core.graph.Edge)85 View (org.kie.workbench.common.stunner.core.graph.content.view.View)59 Test (org.junit.Test)38 Graph (org.kie.workbench.common.stunner.core.graph.Graph)32 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)24 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)21 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)17 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)15 Element (org.kie.workbench.common.stunner.core.graph.Element)14 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)13 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)13 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)13 Matchers.anyString (org.mockito.Matchers.anyString)13 List (java.util.List)12 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 Before (org.junit.Before)11 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)11 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)11