Search in sources :

Example 91 with Node

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

the class BPMNDiagramMarshallerBase method asNodeMap.

@SuppressWarnings("unchecked")
private Map<String, Node<View, ?>> asNodeMap(Iterable nodes) {
    Map<String, Node<View, ?>> oldNodes = new HashMap<>();
    nodes.forEach(n -> {
        Node n1 = (Node) n;
        oldNodes.put(n1.getUUID(), n1);
    });
    return oldNodes;
}
Also used : HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) Matchers.anyString(org.mockito.Matchers.anyString)

Example 92 with Node

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

the class CaseManagementUtilsTest method checkGetFirstDiagramNodeWithNonEmptyGraph.

@Test
@SuppressWarnings("unchecked")
public void checkGetFirstDiagramNodeWithNonEmptyGraph() {
    final Graph graph = new GraphImpl<>("uuid", new GraphNodeStoreImpl());
    final Node node = new NodeImpl<Definition>("node-uuid");
    final CaseManagementDiagram content = new CaseManagementDiagram.CaseManagementDiagramBuilder().build();
    node.setContent(new DefinitionImpl<>(content));
    graph.addNode(node);
    final Node<Definition<CaseManagementDiagram>, ?> fNode = CaseManagementUtils.getFirstDiagramNode(graph);
    assertNotNull(fNode);
    assertEquals("node-uuid", fNode.getUUID());
    assertEquals(content, fNode.getContent().getDefinition());
}
Also used : GraphNodeStoreImpl(org.kie.workbench.common.stunner.core.graph.store.GraphNodeStoreImpl) Graph(org.kie.workbench.common.stunner.core.graph.Graph) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) CaseManagementDiagram(org.kie.workbench.common.stunner.cm.definition.CaseManagementDiagram) GraphImpl(org.kie.workbench.common.stunner.core.graph.impl.GraphImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Test(org.junit.Test)

Example 93 with Node

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

the class CaseManagementContainmentAcceptorControlImpl method evaluate.

private boolean evaluate(final Element parent, final Node[] children, final Function<Command<AbstractCanvasHandler, CanvasViolation>, CommandResult<CanvasViolation>> executor) {
    if (parent == null && (children == null || children.length == 0)) {
        return false;
    }
    final Node child = children[0];
    final Optional<Edge<?, Node>> edge = getFirstIncomingEdge(child, e -> e.getContent() instanceof Child);
    if (edge.isPresent()) {
        final Command<AbstractCanvasHandler, CanvasViolation> command = buildCommands(parent, child, edge.get());
        final CommandResult<CanvasViolation> result = executor.apply(command);
        return isCommandSuccess(result);
    }
    return true;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) 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)

Example 94 with Node

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

the class CaseManagementDrawCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) {
    final Diagram diagram = context.getDiagram();
    final String shapeSetId = context.getDiagram().getMetadata().getShapeSetId();
    childrenTraverseProcessor.traverse(diagram.getGraph(), new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {

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

        @Override
        public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) {
            super.startNodeTraversal(parents, node);
            addNode(node);
            context.addChild(parents.get(parents.size() - 1), node);
            return true;
        }

        private void addNode(final Node<View, Edge> node) {
            context.register(shapeSetId, node);
            context.applyElementMutation(node, MutationContext.STATIC);
        }

        @Override
        public void endGraphTraversal() {
            super.endGraphTraversal();
            context.getCanvas().draw();
        }
    });
    return buildResult();
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 95 with Node

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

the class CaseManagementSetChildNodeGraphCommand method addRelationship.

@SuppressWarnings("unchecked")
private void addRelationship(final Node parent, final Node child, final Optional<Integer> index, final GraphCommandExecutionContext context) {
    final String uuid = UUID.uuid();
    final Edge<Child, Node> edge = new EdgeImpl<>(uuid);
    edge.setContent(new Child());
    edge.setSourceNode(parent);
    edge.setTargetNode(child);
    if (index.isPresent()) {
        parent.getOutEdges().add(index.get(), edge);
    } else {
        parent.getOutEdges().add(edge);
    }
    child.getInEdges().add(edge);
    getMutableIndex(context).addEdge(edge);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) 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