Search in sources :

Example 36 with Edge

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

the class SetParentNodeCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
    final CommandResult<RuleViolation> results = allow(context);
    if (!results.getType().equals(CommandResult.Type.ERROR)) {
        final Node<?, Edge> parent = getParent(context);
        final Node<?, Edge> candidate = getCandidate(context);
        // TODO: Create a ParentEdgeFactory iface extending EdgeFactory using as content generics type Relationship
        final String uuid = UUID.uuid();
        final Edge<Parent, Node> edge = new EdgeImpl<>(uuid);
        edge.setContent(new Parent());
        edge.setSourceNode(parent);
        edge.setTargetNode(candidate);
        parent.getOutEdges().add(edge);
        candidate.getInEdges().add(edge);
        getMutableIndex(context).addEdge(edge);
    }
    return results;
}
Also used : Parent(org.kie.workbench.common.stunner.core.graph.content.relationship.Parent) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 37 with Edge

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

the class GraphImpl method hashCode.

@Override
public int hashCode() {
    // dirty trick to allow inner class to modify variable
    int[] hashArr = { 0 };
    final TreeWalkTraverseProcessor treeWalkTraverseProcessor = new TreeWalkTraverseProcessorImpl();
    treeWalkTraverseProcessor.traverse(this, new AbstractTreeTraverseCallback<Graph, Node, Edge>() {

        int[] myHashArr = hashArr;

        @Override
        public boolean startEdgeTraversal(final Edge edge) {
            super.startEdgeTraversal(edge);
            final Object content = edge.getContent();
            myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], content.hashCode());
            return true;
        }

        @Override
        public boolean startNodeTraversal(final Node node) {
            super.startNodeTraversal(node);
            myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], node.hashCode());
            if (!(node.getContent() instanceof DefinitionSet) && node.getContent() instanceof Definition) {
                Object def = ((Definition) (node.getContent())).getDefinition();
                myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], def.hashCode());
            }
            return true;
        }
    });
    // Get the hash from the graph traversal
    return hashArr[0];
}
Also used : TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Edge(org.kie.workbench.common.stunner.core.graph.Edge) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl)

Example 38 with Edge

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

the class GraphBoundsIndexerImpl method getAt.

@Override
public Node<View<?>, Edge> getAt(final double x, final double y, final double width, final double height, final Element parentNode) {
    Point2D parentNodePosition;
    double xToCheck = 0;
    double yToCheck = 0;
    if (parentNode != null) {
        parentNodePosition = GraphUtils.getPosition((View) parentNode.asNode().getContent());
        xToCheck = x + parentNodePosition.getX();
        yToCheck = y + parentNodePosition.getY();
    }
    Node<View<?>, Edge> element;
    Point2D[] pointsToCheck = new Point2D[5];
    pointsToCheck[0] = new Point2D(xToCheck, yToCheck);
    pointsToCheck[1] = new Point2D(xToCheck + width, yToCheck);
    pointsToCheck[2] = new Point2D(xToCheck + (width / 2), yToCheck + (height / 2));
    pointsToCheck[3] = new Point2D(xToCheck, yToCheck + height);
    pointsToCheck[4] = new Point2D(xToCheck + width, yToCheck + height);
    for (Point2D point : pointsToCheck) {
        element = findElementAt(point.getX(), point.getY());
        if (element != null) {
            if (element != parentNode) {
                return element;
            }
        }
    }
    return null;
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 39 with Edge

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

the class MapIndexBuilder method doWork.

private MapIndex doWork(final Graph<?, Node> graph, final MapIndex current) {
    final Map<String, Node> nodes = new HashMap<>();
    final Map<String, Edge> edges = new HashMap<>();
    Iterable<Node> nodesIter = graph.nodes();
    for (Node node : nodesIter) {
        processNode(nodes, edges, node);
    }
    if (null == current) {
        // Requesting a new index.
        return new MapIndex(graph, nodes, edges);
    } else {
        // Updating an existing index.
        current.nodes.clear();
        current.nodes.putAll(nodes);
        current.edges.clear();
        current.edges.putAll(edges);
        return current;
    }
}
Also used : HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 40 with Edge

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

the class MapIndexBuilder method processNode.

@SuppressWarnings("unchecked")
private void processNode(final Map<String, Node> nodes, final Map<String, Edge> edges, final Node node) {
    if (!nodes.containsKey(node.getUUID())) {
        nodes.put(node.getUUID(), node);
        final List<Edge> outEdges = node.getOutEdges();
        if (null != outEdges && !outEdges.isEmpty()) {
            for (final Edge edge : outEdges) {
                processEdge(nodes, edges, edge);
            }
        }
    }
}
Also used : Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

Edge (org.kie.workbench.common.stunner.core.graph.Edge)154 View (org.kie.workbench.common.stunner.core.graph.content.view.View)101 Node (org.kie.workbench.common.stunner.core.graph.Node)84 Test (org.junit.Test)45 Documentation (org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation)30 Name (org.kie.workbench.common.stunner.bpmn.definition.property.general.Name)30 Graph (org.kie.workbench.common.stunner.core.graph.Graph)28 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)25 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)25 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)19 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)19 List (java.util.List)17 EventPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EventPropertyReader)16 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)16 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)15 Element (org.kie.workbench.common.stunner.core.graph.Element)14 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)13 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 ArrayList (java.util.ArrayList)11