Search in sources :

Example 6 with GraphCommandResultBuilder

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

the class DeregisterNodeCommand method check.

@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
    // And check it really exist on the graph storage as well.
    final org.kie.workbench.common.stunner.core.graph.Graph graph = getGraph(context);
    final Node<View<?>, Edge> candidate = (Node<View<?>, Edge>) checkCandidateNotNull(context);
    final GraphCommandResultBuilder builder = new GraphCommandResultBuilder();
    final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(graph, Optional.of(candidate), Optional.of(CardinalityContext.Operation.DELETE)));
    builder.addViolations(cardinalityRuleViolations);
    return builder.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 7 with GraphCommandResultBuilder

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

the class DockNodeCommand 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> dockingRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.docking(getGraph(context), parent, candidate));
    return new GraphCommandResultBuilder(dockingRuleViolations).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 8 with GraphCommandResultBuilder

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

the class SafeDeleteNodeCommand method doAllow.

@Override
@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> doAllow(final GraphCommandExecutionContext context, final Command<GraphCommandExecutionContext, RuleViolation> command) {
    final CommandResult<RuleViolation> result = super.doAllow(context, command);
    if (!CommandUtils.isError(result) && hasRules(context)) {
        final Graph target = getGraph(context);
        final Node<View<?>, Edge> candidate = (Node<View<?>, Edge>) getCandidate(context);
        final GraphCommandResultBuilder builder = new GraphCommandResultBuilder();
        final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(target, Optional.of(candidate), Optional.of(CardinalityContext.Operation.DELETE)));
        builder.addViolations(cardinalityRuleViolations);
        for (final RuleViolation violation : cardinalityRuleViolations) {
            if (builder.isError(violation)) {
                return builder.build();
            }
        }
        return builder.build();
    }
    return result;
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) 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 9 with GraphCommandResultBuilder

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

the class SetConnectionTargetNodeCommand method check.

@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
    final GraphCommandResultBuilder resultBuilder = new GraphCommandResultBuilder();
    final Node<? extends View<?>, Edge> targetNode = getTargetNode(context);
    final Edge<View<?>, Node> edge = (Edge<View<?>, Node>) getEdge(context);
    final Node<? extends View<?>, Edge> lastTargetNode = edge.getTargetNode();
    // Only check for rules in case the connector's target node is a different one.
    if ((null == lastTargetNode && null != targetNode) || (null != lastTargetNode && (!lastTargetNode.equals(targetNode)))) {
        final Collection<RuleViolation> connectionRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.connection(getGraph(context), edge, Optional.ofNullable(sourceNode), Optional.ofNullable(targetNode)));
        resultBuilder.addViolations(connectionRuleViolations);
        final Node<? extends View<?>, Edge> currentTarget = edge.getTargetNode();
        if (null != currentTarget) {
            final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.edgeCardinality(getGraph(context), currentTarget, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.DELETE)));
            resultBuilder.addViolations(cardinalityRuleViolations);
        }
        if (null != targetNode) {
            final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.edgeCardinality(getGraph(context), targetNode, edge, EdgeCardinalityContext.Direction.INCOMING, 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) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 10 with GraphCommandResultBuilder

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

the class SetParentNodeCommand 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)

Aggregations

GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)11 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)10 Node (org.kie.workbench.common.stunner.core.graph.Node)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)7 Element (org.kie.workbench.common.stunner.core.graph.Element)5 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 Graph (org.kie.workbench.common.stunner.core.graph.Graph)3 LinkedList (java.util.LinkedList)1 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)1 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)1 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)1 BoundsExceededViolation (org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation)1