Search in sources :

Example 6 with ViewConnector

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

the class SafeDeleteNodeCommand method initialize.

@Override
@SuppressWarnings("unchecked")
protected SafeDeleteNodeCommand initialize(final GraphCommandExecutionContext context) {
    super.initialize(context);
    final Graph<?, Node> graph = getGraph(context);
    final Node<Definition<?>, Edge> candidate = (Node<Definition<?>, Edge>) getCandidate(context);
    new SafeDeleteNodeProcessor(new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()), graph, candidate).run(new SafeDeleteNodeProcessor.Callback() {

        private final Set<String> processedConnectors = new HashSet<String>();

        @Override
        public void deleteCandidateConnector(final Edge<? extends View<?>, Node> edge) {
        // This command will delete candidate's connectors once deleting the candidate node later on,
        // as it potentially performs the connectors shortcut operation.
        }

        @Override
        public void deleteConnector(final Edge<? extends View<?>, Node> edge) {
            doDeleteConnector(edge);
        }

        @Override
        public void removeChild(final Element<?> parent, final Node<?, Edge> candidate) {
            log("RemoveChildCommand [parent=" + parent.getUUID() + ", candidate=" + candidate.getUUID() + "]");
            addCommand(new RemoveChildCommand((Node<?, Edge>) parent, candidate));
            safeDeleteCallback.ifPresent(c -> c.removeChild(parent, candidate));
        }

        @Override
        public void removeDock(final Node<?, Edge> parent, final Node<?, Edge> candidate) {
            log("UnDockNodeCommand [parent=" + parent.getUUID() + ", candidate=" + candidate.getUUID() + "]");
            addCommand(new UnDockNodeCommand(parent, candidate));
            safeDeleteCallback.ifPresent(c -> c.removeDock(parent, candidate));
        }

        @Override
        public void deleteCandidateNode(final Node<?, Edge> node) {
            processCandidateConnectors();
            deleteNode(node);
        }

        @Override
        public void deleteNode(final Node<?, Edge> node) {
            log("DeregisterNodeCommand [node=" + node.getUUID() + "]");
            addCommand(new DeregisterNodeCommand(node));
            safeDeleteCallback.ifPresent(c -> c.deleteNode(node));
        }

        private void processCandidateConnectors() {
            if (options.isDeleteCandidateConnectors()) {
                if (options.isShortcutCandidateConnectors() && hasSingleIncomingEdge().and(hasSingleOutgoingEdge()).test(candidate)) {
                    final Edge<? extends ViewConnector<?>, Node> in = getViewConnector().apply(candidate.getInEdges());
                    final Edge<? extends ViewConnector<?>, Node> out = getViewConnector().apply(candidate.getOutEdges());
                    shortcut(in, out);
                } else {
                    Stream.concat(candidate.getInEdges().stream(), candidate.getOutEdges().stream()).filter(e -> e.getContent() instanceof ViewConnector).forEach(this::deleteConnector);
                }
            }
        }

        private void shortcut(final Edge<? extends ViewConnector<?>, Node> in, final Edge<? extends ViewConnector<?>, Node> out) {
            final ViewConnector<?> outContent = out.getContent();
            final Node targetNode = out.getTargetNode();
            addCommand(new DeleteConnectorCommand(out));
            safeDeleteCallback.ifPresent(c -> c.deleteCandidateConnector(out));
            addCommand(new SetConnectionTargetNodeCommand(targetNode, in, outContent.getTargetConnection().orElse(null)));
            safeDeleteCallback.ifPresent(c -> c.setEdgeTargetNode(targetNode, in));
        }

        private void doDeleteConnector(final Edge<? extends View<?>, Node> edge) {
            if (!processedConnectors.contains(edge.getUUID())) {
                log("IN DoDeleteConnector [edge=" + edge.getUUID() + "]");
                addCommand(new DeleteConnectorCommand(edge));
                safeDeleteCallback.ifPresent(c -> c.deleteConnector(edge));
                processedConnectors.add(edge.getUUID());
            }
        }
    });
    return this;
}
Also used : Edge(org.kie.workbench.common.stunner.core.graph.Edge) Portable(org.jboss.errai.common.client.api.annotations.Portable) Function(java.util.function.Function) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Level(java.util.logging.Level) HashSet(java.util.HashSet) SafeDeleteNodeProcessor(org.kie.workbench.common.stunner.core.graph.util.SafeDeleteNodeProcessor) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) NonPortable(org.jboss.errai.common.client.api.annotations.NonPortable) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) Element(org.kie.workbench.common.stunner.core.graph.Element) PortablePreconditions(org.kie.soup.commons.validation.PortablePreconditions) Command(org.kie.workbench.common.stunner.core.command.Command) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) CardinalityContext(org.kie.workbench.common.stunner.core.rule.context.CardinalityContext) Predicate(java.util.function.Predicate) Collection(java.util.Collection) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) Set(java.util.Set) Logger(java.util.logging.Logger) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Stream(java.util.stream.Stream) CommandUtils(org.kie.workbench.common.stunner.core.command.util.CommandUtils) Optional(java.util.Optional) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) MapsTo(org.jboss.errai.common.client.api.annotations.MapsTo) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) SafeDeleteNodeProcessor(org.kie.workbench.common.stunner.core.graph.util.SafeDeleteNodeProcessor) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) Edge(org.kie.workbench.common.stunner.core.graph.Edge) HashSet(java.util.HashSet)

Example 7 with ViewConnector

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

the class SetConnectionSourceNodeCommand 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 Edge<? extends View, Node> edge = getEdge(context);
        final Node<?, Edge> sourceNode = getSourceNode(context);
        final Node<? extends View<?>, Edge> lastSourceNode = edge.getSourceNode();
        // New connection being made
        if (null != lastSourceNode) {
            this.lastSourceNodeUUID = lastSourceNode.getUUID();
            lastSourceNode.getOutEdges().remove(edge);
        }
        if (null != sourceNode) {
            sourceNode.getOutEdges().add(edge);
        }
        edge.setSourceNode(sourceNode);
        // Magnet being moved on node
        ViewConnector connectionContent = (ViewConnector) edge.getContent();
        lastConnection = (Connection) connectionContent.getSourceConnection().orElse(null);
        connectionContent.setSourceConnection(connection);
    }
    return results;
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 8 with ViewConnector

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

the class StunnerLogger method log.

public static void log(final Edge<?, Node> edge) {
    log("Edge UUID: " + edge.getUUID());
    final Object content = edge.getContent();
    log("  Edge Content: " + content.getClass().getName());
    final Node inNode = edge.getSourceNode();
    final Node outNode = edge.getTargetNode();
    log("  Edge In Node: " + (null != inNode ? inNode.getUUID() : "null"));
    log("  Edge Out Node: " + (null != outNode ? outNode.getUUID() : "null"));
    if (edge.getContent() instanceof ViewConnector) {
        log((ViewConnector) edge.getContent());
    }
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node)

Example 9 with ViewConnector

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

the class AddCanvasConnectorCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) {
    context.register(shapeSetId, candidate);
    context.applyElementMutation(candidate, MutationContext.STATIC);
    if (candidate.getContent() instanceof ViewConnector) {
        ControlPoint[] controlPoints = ((ViewConnector) candidate.getContent()).getControlPoints().stream().toArray(ControlPoint[]::new);
        CommandResult<CanvasViolation> addControlPointsResult = new AddCanvasControlPointCommand(candidate, controlPoints).execute(context);
        ShapeUtils.hideControlPoints(candidate, context);
        if (CommandUtils.isError(addControlPointsResult)) {
            return addControlPointsResult;
        }
    }
    ShapeUtils.updateEdgeConnections(candidate, context);
    ShapeUtils.applyConnections(candidate, context, MutationContext.STATIC);
    final Node source = candidate.getSourceNode();
    if (null != source) {
        context.notifyCanvasElementUpdated(source);
    }
    return buildResult();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)

Example 10 with ViewConnector

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

the class CanvasLayoutUtils method getNext.

@SuppressWarnings("unchecked")
public Point2D getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final Node<View<?>, Edge> newNode) {
    final double[] rootBounds = getBoundCoordinates(root.getContent());
    final double[] rootSize = GraphUtils.getNodeSize(root.getContent());
    final double[] newNodeSize = GraphUtils.getNodeSize(newNode.getContent());
    Point2D[] offset = { new Point2D(PADDING_X, 0) };
    Point2D[] parentOffset = { new Point2D(0, 0) };
    double[] maxNodeY = { 0 };
    if (root.getOutEdges().size() > 0) {
        root.getOutEdges().stream().filter(e -> e.getContent() instanceof ViewConnector).filter(e -> null != e.getTargetNode() && !e.getTargetNode().equals(newNode)).forEach(n -> {
            final Node<View<?>, Edge> node = n.getTargetNode();
            final Point2D nodePos = GraphUtils.getPosition(node.getContent());
            final Point2D rootPos = GraphUtils.getPosition(root.getContent());
            if (nodePos.getY() > maxNodeY[0]) {
                maxNodeY[0] = nodePos.getY();
                final double[] nodeSize = GraphUtils.getNodeSize(node.getContent());
                offset[0].setY(maxNodeY[0] + nodeSize[1] - rootPos.getY());
            }
        });
        offset[0].setY(offset[0].getY() + parentOffset[0].getY() + PADDING_Y);
    } else {
        offset[0].setY(parentOffset[0].getY() - (newNodeSize[1] - rootSize[1]) / 2);
    }
    offset[0].setX(offset[0].getX() + PADDING_X);
    final Point2D offsetCoordinates = new Point2D(offset[0].getX(), offset[0].getY());
    final Point2D rootNodeCoordinates = new Point2D(rootBounds[0], rootBounds[1]);
    return getNext(canvasHandler, root, rootSize[0], rootSize[1], newNodeSize[0], newNodeSize[1], offsetCoordinates, rootNodeCoordinates);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Violation(org.kie.workbench.common.stunner.core.validation.Violation) GraphBoundsIndexer(org.kie.workbench.common.stunner.core.graph.processing.index.bounds.GraphBoundsIndexer) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) RuleContextBuilder(org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Inject(javax.inject.Inject) NodeContainmentContext(org.kie.workbench.common.stunner.core.rule.context.NodeContainmentContext) Graph(org.kie.workbench.common.stunner.core.graph.Graph) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Dependent(javax.enterprise.context.Dependent) Element(org.kie.workbench.common.stunner.core.graph.Element) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) 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)

Aggregations

ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)30 Node (org.kie.workbench.common.stunner.core.graph.Node)20 Edge (org.kie.workbench.common.stunner.core.graph.Edge)17 Graph (org.kie.workbench.common.stunner.core.graph.Graph)10 Test (org.junit.Test)8 View (org.kie.workbench.common.stunner.core.graph.content.view.View)8 List (java.util.List)7 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)6 ArrayList (java.util.ArrayList)5 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)5 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)5 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)5 ScriptTask (org.kie.workbench.common.stunner.bpmn.definition.ScriptTask)4 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)4 Element (org.kie.workbench.common.stunner.core.graph.Element)3 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)3 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)3 LinkedList (java.util.LinkedList)2 InclusiveGateway (org.kie.workbench.common.stunner.bpmn.definition.InclusiveGateway)2 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)2