Search in sources :

Example 1 with ParentsTypeMatcher

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

Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1 ParentsTypeMatcher (org.kie.workbench.common.stunner.core.graph.util.ParentsTypeMatcher)1 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)1