Search in sources :

Example 11 with TreeWalkTraverseProcessorImpl

use of org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl 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 12 with TreeWalkTraverseProcessorImpl

use of org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl in project kie-wb-common by kiegroup.

the class CaseManagementCanvasCommandFactoryTest method setup.

@Before
public void setup() {
    when(childrenTraverseProcessorInstances.get()).thenReturn(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()));
    when(viewTraverseProcessorInstances.get()).thenReturn(new ViewTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()));
    this.factory = new CaseManagementCanvasCommandFactory(childrenTraverseProcessorInstances, null);
}
Also used : ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) ViewTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ViewTraverseProcessorImpl) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Before(org.junit.Before)

Example 13 with TreeWalkTraverseProcessorImpl

use of org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl in project kie-wb-common by kiegroup.

the class GraphValidatorImplTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    this.graphTestHandler = new TestingGraphMockHandler();
    when(graphTestHandler.definitionSetRegistry.getDefinitionSetById(eq(DEF_SET_ID))).thenReturn(defSetBean);
    when(graphTestHandler.ruleAdapter.getRuleSet(eq(defSetBean))).thenReturn(graphTestHandler.ruleSet);
    this.tested = new GraphValidatorImpl(graphTestHandler.definitionManager, graphTestHandler.ruleManager, new TreeWalkTraverseProcessorImpl());
}
Also used : TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Before(org.junit.Before)

Example 14 with TreeWalkTraverseProcessorImpl

use of org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl in project kie-wb-common by kiegroup.

the class CanvasHighlightVisitor method prepareVisit.

@SuppressWarnings("unchecked")
private void prepareVisit(final Command command) {
    final Graph graph = canvasHandler.getDiagram().getGraph();
    final TreeWalkTraverseProcessor treeWalkTraverseProcessor = new TreeWalkTraverseProcessorImpl().useStartNodePredicate(this::isStartNode);
    new ViewTraverseProcessorImpl(treeWalkTraverseProcessor).traverse(graph, new ContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() {

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

        @Override
        public void startEdgeTraversal(final Edge<View<?>, Node> edge) {
            addShape(edge.getUUID());
        }

        @Override
        public void endEdgeTraversal(final Edge<View<?>, Node> edge) {
        }

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

        @Override
        public void endNodeTraversal(final Node<View, Edge> node) {
        }

        @Override
        public void endGraphTraversal() {
            command.execute();
        }

        private void addShape(final String uuid) {
            final Shape shape = canvasHandler.getCanvas().getShape(uuid);
            if (null != shape) {
                shapes.add(shape);
            }
        }
    });
}
Also used : Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ViewTraverseProcessorImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 15 with TreeWalkTraverseProcessorImpl

use of org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl in project kie-wb-common by kiegroup.

the class GraphBoundsIndexerImplTest method setup.

@Before
public void setup() {
    this.graphTestHandlerParent = new TestingGraphMockHandler();
    graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
    ChildrenTraverseProcessor childrenTraverseProcessor = new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl());
    graphBoundsIndexerImpl = new GraphBoundsIndexerImpl(childrenTraverseProcessor);
    graphBoundsIndexerImpl.build(graphInstanceParent.graph);
}
Also used : ChildrenTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessor) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) GraphBoundsIndexerImpl(org.kie.workbench.common.stunner.core.graph.processing.index.bounds.GraphBoundsIndexerImpl) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Before(org.junit.Before)

Aggregations

TreeWalkTraverseProcessorImpl (org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl)18 ChildrenTraverseProcessorImpl (org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl)14 Node (org.kie.workbench.common.stunner.core.graph.Node)9 Before (org.junit.Before)7 Test (org.junit.Test)5 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)5 Edge (org.kie.workbench.common.stunner.core.graph.Edge)5 Graph (org.kie.workbench.common.stunner.core.graph.Graph)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Element (org.kie.workbench.common.stunner.core.graph.Element)2 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)2 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)2 ViewTraverseProcessorImpl (org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ViewTraverseProcessorImpl)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Set (java.util.Set)1