Search in sources :

Example 1 with EdgeImpl

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

the class AcyclicDirectedGraphRuleTest method checkCyclicalConnection.

@Test
@SuppressWarnings("unchecked")
public void checkCyclicalConnection() {
    final Node node1 = new NodeImpl<>("node1");
    final Node node2 = new NodeImpl<>("node2");
    final Edge c1 = new EdgeImpl<>("edge1");
    node1.getOutEdges().add(c1);
    node2.getInEdges().add(c1);
    c1.setSourceNode(node1);
    c1.setTargetNode(node2);
    graph.addNode(node1);
    graph.addNode(node2);
    when(context.getSource()).thenReturn(Optional.of(node2));
    when(context.getTarget()).thenReturn(Optional.of(node1));
    when(context.getConnector()).thenReturn(connector);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertTrue(result.violations().iterator().hasNext());
    final RuleViolation violation = result.violations().iterator().next();
    assertNotNull(violation);
    assertTrue(violation.getArguments().isPresent());
    assertEquals(1, violation.getArguments().get().length);
    assertEquals(AcyclicDirectedGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 2 with EdgeImpl

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

the class SingleConnectorPerTypeGraphRuleTest method checkHasExistingConnection.

@Test
@SuppressWarnings("unchecked")
public void checkHasExistingConnection() {
    final Node node1 = new NodeImpl<>("node1");
    final Node node2 = new NodeImpl<>("node2");
    final Edge existingConnector = new EdgeImpl<>("edge1");
    final ViewConnector existingConnectorView = mock(ViewConnector.class);
    existingConnector.setContent(existingConnectorView);
    when(existingConnectorView.getDefinition()).thenReturn(new Definition());
    node1.getOutEdges().add(existingConnector);
    node2.getInEdges().add(existingConnector);
    existingConnector.setSourceNode(node1);
    existingConnector.setTargetNode(node2);
    graph.addNode(node1);
    graph.addNode(node2);
    when(context.getSource()).thenReturn(Optional.of(node1));
    when(context.getTarget()).thenReturn(Optional.of(node2));
    when(context.getConnector()).thenReturn(connector);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertTrue(result.violations().iterator().hasNext());
    final RuleViolation violation = result.violations().iterator().next();
    assertNotNull(violation);
    assertTrue(violation.getArguments().isPresent());
    assertEquals(1, violation.getArguments().get().length);
    assertEquals(SingleConnectorPerTypeGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 3 with EdgeImpl

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

the class DMNMarshaller method connectRootWithChild.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void connectRootWithChild(final Node dmnDiagramRoot, final Node child) {
    final String uuid = org.kie.workbench.common.stunner.core.util.UUID.uuid();
    final Edge<Child, Node> edge = new EdgeImpl<>(uuid);
    edge.setContent(new Child());
    connectEdge(edge, dmnDiagramRoot, child);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child)

Example 4 with EdgeImpl

use of org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl 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 5 with EdgeImpl

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

the class SetParentNodeCommand 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);
        // TODO: Create a ParentEdgeFactory iface extending EdgeFactory using as content generics type Relationship
        final String uuid = UUID.uuid();
        final Edge<Parent, Node> edge = new EdgeImpl<>(uuid);
        edge.setContent(new Parent());
        edge.setSourceNode(parent);
        edge.setTargetNode(candidate);
        parent.getOutEdges().add(edge);
        candidate.getInEdges().add(edge);
        getMutableIndex(context).addEdge(edge);
    }
    return results;
}
Also used : Parent(org.kie.workbench.common.stunner.core.graph.content.relationship.Parent) 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)

Aggregations

EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)12 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Edge (org.kie.workbench.common.stunner.core.graph.Edge)7 Test (org.junit.Test)5 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)5 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)4 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)4 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)2 ViewConnectorImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnectorImpl)2 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)2 FlowElement (org.eclipse.bpmn2.FlowElement)1 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)1 RootElement (org.eclipse.bpmn2.RootElement)1 Before (org.junit.Before)1 ExclusiveGateway (org.kie.workbench.common.stunner.bpmn.definition.ExclusiveGateway)1 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)1 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)1 Element (org.kie.workbench.common.stunner.core.graph.Element)1 Graph (org.kie.workbench.common.stunner.core.graph.Graph)1 Dock (org.kie.workbench.common.stunner.core.graph.content.relationship.Dock)1