Search in sources :

Example 31 with View

use of org.kie.workbench.common.stunner.core.graph.content.view.View 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 32 with View

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

the class SetConnectionSourceNodeCommand method check.

@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
    final GraphCommandResultBuilder resultBuilder = new GraphCommandResultBuilder();
    final Node<View<?>, Edge> sourceNode = (Node<View<?>, Edge>) getSourceNode(context);
    final Edge<View<?>, Node> edge = (Edge<View<?>, Node>) getEdge(context);
    final Node<? extends View<?>, Edge> lastSourceNode = edge.getSourceNode();
    // Only check for rules in case the connector's source node is a different one.
    if ((null == lastSourceNode && null != sourceNode) || (null != lastSourceNode && (!lastSourceNode.equals(sourceNode)))) {
        // New connection being made
        final Collection<RuleViolation> connectionRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.connection(getGraph(context), edge, Optional.ofNullable(sourceNode), Optional.ofNullable(targetNode)));
        resultBuilder.addViolations(connectionRuleViolations);
        final Node<View<?>, Edge> currentSource = edge.getSourceNode();
        // If the edge has an outoutgoing source node, check cardinality for removing it.
        if (null != currentSource) {
            final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.edgeCardinality(getGraph(context), currentSource, edge, EdgeCardinalityContext.Direction.OUTGOING, Optional.of(CardinalityContext.Operation.DELETE)));
            resultBuilder.addViolations(cardinalityRuleViolations);
        }
        // If the new source node exist, evaluate cardinality rules for this edge.
        if (null != sourceNode) {
            final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.edgeCardinality(getGraph(context), sourceNode, edge, EdgeCardinalityContext.Direction.OUTGOING, Optional.of(CardinalityContext.Operation.ADD)));
            resultBuilder.addViolations(cardinalityRuleViolations);
        }
    }
    return resultBuilder.build();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 33 with View

use of org.kie.workbench.common.stunner.core.graph.content.view.View 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 34 with View

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

the class GraphBoundsIndexerImpl method getNodeAbsoluteCoordinates.

private double[] getNodeAbsoluteCoordinates(final Node node, final double parentX, final double parentY) {
    final View content = (View) node.getContent();
    final Bounds bounds = content.getBounds();
    final Bounds.Bound ulBound = bounds.getUpperLeft();
    final Bounds.Bound lrBound = bounds.getLowerRight();
    final double ulX = ulBound.getX() + parentX;
    final double ulY = ulBound.getY() + parentY;
    final double lrX = lrBound.getX() + parentX;
    final double lrY = lrBound.getY() + parentY;
    return new double[] { ulX, ulY, lrX, lrY };
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 35 with View

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

the class ConnectorParentsMatchConnectionHandler method evaluateConnection.

private RuleViolations evaluateConnection(final RuleExtension rule, final GraphConnectionContext context) {
    LOGGER.log(Level.INFO, "Evaluating rule handler [" + getClass().getName() + "]...");
    final Optional<Node<? extends View<?>, ? extends Edge>> sourceNode = context.getSource();
    final Optional<Node<? extends View<?>, ? extends Edge>> targetNode = context.getTarget();
    final Class<?>[] typeArguments = rule.getTypeArguments();
    final Class<?> parentType = null != typeArguments ? typeArguments[0] : null;
    final DefaultRuleViolations result = new DefaultRuleViolations();
    boolean isValid = true;
    if (sourceNode.isPresent() && targetNode.isPresent()) {
        isValid = new ParentsTypeMatcher(definitionManager).forParentType(parentType).test(sourceNode.get(), targetNode.get());
    }
    if (!isValid) {
        addViolation(context.getConnector().getUUID(), rule, result);
    }
    return result;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ParentsTypeMatcher(org.kie.workbench.common.stunner.core.graph.util.ParentsTypeMatcher)

Aggregations

View (org.kie.workbench.common.stunner.core.graph.content.view.View)144 Edge (org.kie.workbench.common.stunner.core.graph.Edge)100 Node (org.kie.workbench.common.stunner.core.graph.Node)57 Test (org.junit.Test)49 Graph (org.kie.workbench.common.stunner.core.graph.Graph)45 Element (org.kie.workbench.common.stunner.core.graph.Element)36 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)32 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)31 Documentation (org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation)31 Name (org.kie.workbench.common.stunner.bpmn.definition.property.general.Name)31 FlowElement (org.eclipse.bpmn2.FlowElement)26 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)26 RootElement (org.eclipse.bpmn2.RootElement)26 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)21 EventPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EventPropertyReader)16 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)16 DataIOSet (org.kie.workbench.common.stunner.bpmn.definition.property.dataio.DataIOSet)14 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 ProcessVariables (org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessVariables)10