Search in sources :

Example 6 with ChildrenTraverseProcessorImpl

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

the class SafeDeleteNodeProcessorTest method testDeleteEndNode.

@Test
@SuppressWarnings("unchecked")
public void testDeleteEndNode() {
    this.tested = new SafeDeleteNodeProcessor(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()), graphHolder.graph, graphHolder.endNode);
    tested.run(callback);
    verify(callback, times(1)).deleteCandidateConnector(eq(graphHolder.edge2));
    verify(callback, times(1)).removeChild(eq(graphHolder.parentNode), eq(graphHolder.endNode));
    verify(callback, times(1)).deleteCandidateNode(eq(graphHolder.endNode));
    verify(callback, never()).removeDock(any(Node.class), any(Node.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Test(org.junit.Test)

Example 7 with ChildrenTraverseProcessorImpl

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

the class SafeDeleteNodeProcessorTest method testDeleteParentWithNonEmptyContainerInside.

@Test
@SuppressWarnings("unchecked")
public void testDeleteParentWithNonEmptyContainerInside() {
    this.tested = new SafeDeleteNodeProcessor(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()), graphHolderContainer.graph, graphHolderContainer.parentNode);
    tested.run(callback);
    InOrder inOrder = inOrder(callback);
    inOrder.verify(callback, times(1)).deleteConnector(eq(graphHolderContainer.edge2));
    inOrder.verify(callback, times(1)).removeChild(eq(graphHolderContainer.containerNode), eq(graphHolderContainer.endNode));
    inOrder.verify(callback, times(1)).deleteNode(eq(graphHolderContainer.endNode));
    inOrder.verify(callback, times(1)).deleteConnector(eq(graphHolderContainer.edge1));
    inOrder.verify(callback, times(1)).removeChild(eq(graphHolderContainer.containerNode), eq(graphHolderContainer.intermNode));
    inOrder.verify(callback, times(1)).deleteNode(eq(graphHolderContainer.intermNode));
    inOrder.verify(callback, times(1)).removeChild(eq(graphHolderContainer.containerNode), eq(graphHolderContainer.startNode));
    inOrder.verify(callback, times(1)).deleteNode(eq(graphHolderContainer.startNode));
    inOrder.verify(callback, times(1)).deleteNode(eq(graphHolderContainer.containerNode));
    inOrder.verify(callback, times(1)).deleteCandidateNode(eq(graphHolderContainer.parentNode));
}
Also used : InOrder(org.mockito.InOrder) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Test(org.junit.Test)

Example 8 with ChildrenTraverseProcessorImpl

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

the class SafeDeleteNodeProcessorTest method testDeleteStartNode.

@Test
@SuppressWarnings("unchecked")
public void testDeleteStartNode() {
    this.tested = new SafeDeleteNodeProcessor(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()), graphHolder.graph, graphHolder.startNode);
    tested.run(callback);
    verify(callback, times(1)).deleteCandidateConnector(eq(graphHolder.edge1));
    verify(callback, times(1)).removeChild(eq(graphHolder.parentNode), eq(graphHolder.startNode));
    verify(callback, times(1)).deleteCandidateNode(eq(graphHolder.startNode));
    verify(callback, never()).removeDock(any(Node.class), any(Node.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Test(org.junit.Test)

Example 9 with ChildrenTraverseProcessorImpl

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

the class TreeExplorerTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(canvasHandler.getDiagram().getGraph()).thenReturn(graph);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getShapeSetId()).thenReturn(SHAPE_SET_ID);
    when(textPropertyProviderFactory.getProvider(any(Element.class))).thenReturn(textPropertyProvider);
    when(definitionUtils.getDefinitionManager()).thenReturn(definitionManager);
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
    when(definitionAdapter.getId(anyObject())).thenReturn("defId");
    when(shapeManager.getShapeSet(eq(SHAPE_SET_ID))).thenReturn(shapeSet);
    when(shapeSet.getShapeFactory()).thenReturn(shapeFactory);
    when(shapeFactory.getGlyph(eq("defId"))).thenReturn(glyph);
    when(domGlyphRenderers.render(eq(glyph), anyDouble(), anyDouble())).thenReturn(isElement);
    this.childrenTraverseProcessor = spy(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()));
    this.testedTree = new TreeExplorer(childrenTraverseProcessor, textPropertyProviderFactory, elementSelectedEvent, definitionUtils, shapeManager, domGlyphRenderers, view) {

        @Override
        ElementWrapperWidget<?> wrapIconElement(final IsElement icon) {
            return mock(ElementWrapperWidget.class);
        }
    };
}
Also used : ElementWrapperWidget(org.jboss.errai.common.client.ui.ElementWrapperWidget) IsElement(org.jboss.errai.common.client.api.IsElement) IsElement(org.jboss.errai.common.client.api.IsElement) Element(org.kie.workbench.common.stunner.core.graph.Element) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Before(org.junit.Before)

Example 10 with ChildrenTraverseProcessorImpl

use of org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl 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)

Aggregations

ChildrenTraverseProcessorImpl (org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl)14 TreeWalkTraverseProcessorImpl (org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl)14 Node (org.kie.workbench.common.stunner.core.graph.Node)7 Before (org.junit.Before)5 Test (org.junit.Test)5 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)3 Edge (org.kie.workbench.common.stunner.core.graph.Edge)3 View (org.kie.workbench.common.stunner.core.graph.content.view.View)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Element (org.kie.workbench.common.stunner.core.graph.Element)2 Graph (org.kie.workbench.common.stunner.core.graph.Graph)2 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Stack (java.util.Stack)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1