Search in sources :

Example 21 with Node

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

the class ShapeUtils method moveViewConnectorsToTop.

@SuppressWarnings("unchecked")
public static void moveViewConnectorsToTop(final AbstractCanvasHandler canvasHandler, final Node<?, Edge> node) {
    final Set<String> connectorIds = new HashSet<>();
    // Obtain all view connectors for the node and its children.
    appendViewConnectorIds(connectorIds, node);
    new ChildrenTraverseProcessorImpl(new TreeWalkTraverseProcessorImpl()).setRootUUID(node.getUUID()).traverse(canvasHandler.getGraphIndex().getGraph(), new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {

        @Override
        public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> childNode) {
            appendViewConnectorIds(connectorIds, childNode);
            return true;
        }
    });
    // Update connector's view.
    connectorIds.forEach(id -> moveShapeToTop(canvasHandler, id));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) ChildrenTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessorImpl) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) HashSet(java.util.HashSet)

Example 22 with Node

use of org.kie.workbench.common.stunner.core.graph.Node 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 23 with Node

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

the class SetChildNodeCommand 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);
        final String uuid = UUID.uuid();
        final Edge<Child, Node> edge = new EdgeImpl<>(uuid);
        edge.setContent(new Child());
        edge.setSourceNode(parent);
        edge.setTargetNode(candidate);
        parent.getOutEdges().add(edge);
        candidate.getInEdges().add(edge);
        getMutableIndex(context).addEdge(edge);
    }
    return results;
}
Also used : 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) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child)

Example 24 with Node

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

the class SetChildNodeCommand method check.

@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
    final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
    final Node<Definition<?>, Edge> candidate = (Node<Definition<?>, Edge>) getCandidate(context);
    final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), parent, candidate));
    return new GraphCommandResultBuilder(containmentRuleViolations).build();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 25 with Node

use of org.kie.workbench.common.stunner.core.graph.Node 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)

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