Search in sources :

Example 91 with Definition

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

the class DMNElementsSynchronizerTest method testDefinitionContainsDRGElement.

@Test
public void testDefinitionContainsDRGElement() {
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    when(definition.getDefinition()).thenReturn(drgElement);
    when(node.getContent()).thenReturn(definition);
    final boolean containsDRGElement = synchronizer.definitionContainsDRGElement(node);
    assertTrue(containsDRGElement);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 92 with Definition

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

the class ElementFactoryTest method testBuild.

@Test
public void testBuild() {
    final String UUID = "UUID";
    final String DEFINITION = "Definition String";
    Element element = mock(Element.class);
    ElementFactory<String, Definition<String>, Element<Definition<String>>> factory = new ElementFactory() {

        @Override
        public Class<? extends ElementFactory> getFactoryType() {
            return null;
        }

        @Override
        public Element build(String uuid, Object definition) {
            return element;
        }

        @Override
        public boolean accepts(Object source) {
            return false;
        }
    };
    assertEquals(element, factory.build(UUID, DEFINITION, null));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Test(org.junit.Test)

Example 93 with Definition

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

the class NodeConnector method connectEdgeToNodes.

void connectEdgeToNodes(final String connectorTypeId, final JSITDMNElement jsiDMNElement, final JSITDMNElementReference jsiDMNElementReference, final Map<String, List<NodeEntry>> entriesById, final String diagramId, final List<JSIDMNEdge> edges, final boolean isDMNDIPresent, final Node currentNode) {
    final String reqInputID = getId(jsiDMNElementReference);
    final List<NodeEntry> nodeEntries = entriesById.get(reqInputID);
    if (nodeEntries == null || nodeEntries.isEmpty()) {
        return;
    }
    final Optional<JSIDMNEdge> existingEdge = findExistingEdge(jsiDMNElement, edges);
    if (!isDMNDIPresent) {
        // Generate new a edge and connect it
        final NodeEntry nodeEntry = nodeEntries.get(0);
        final Node requiredNode = nodeEntry.getNode();
        final View<?> view = (View<?>) requiredNode.getContent();
        final double viewWidth = view.getBounds().getWidth();
        final double viewHeight = view.getBounds().getHeight();
        connectWbEdge(connectorTypeId, diagramId, currentNode, requiredNode, newEdge(viewWidth / 2, viewHeight / 2), uuid());
    } else if (existingEdge.isPresent()) {
        // Connect existing edge
        final JSIDMNEdge edge = Js.uncheckedCast(existingEdge.get());
        final Optional<Node> requiredNode = getSourceNode(edge, nodeEntries);
        final String id = edge.getDmnElementRef().getLocalPart();
        final String currentNodeId = ((DRGElement) ((Definition) currentNode.getContent()).getDefinition()).getContentDefinitionId();
        // The edge can be connected with another instance of the same Node and not the currentNode
        if (isEdgeConnectedWithNode(edge, currentNode, entriesById.get(currentNodeId))) {
            connectWbEdge(connectorTypeId, diagramId, currentNode, requiredNode.get(), edge, id);
        }
    }
}
Also used : Optional(java.util.Optional) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 94 with Definition

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

the class DMNCommonActionsToolboxFactoryTest method testAddEditWhenIsNotDecisionOrBusinessKnowledgeModelAction.

@Test
public void testAddEditWhenIsNotDecisionOrBusinessKnowledgeModelAction() {
    final List<ToolboxAction<AbstractCanvasHandler>> actions = new ArrayList<>();
    final Element element = mock(Element.class);
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final Object someObject = mock(Object.class);
    when(element.asNode()).thenReturn(node);
    when(element.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(someObject);
    tested.addEditAction(element, actions);
    assertEquals(0, actions.size());
}
Also used : ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) DeleteNodeToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.DeleteNodeToolboxAction) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Test(org.junit.Test)

Example 95 with Definition

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

the class DMNDiagramTextPropertyProviderImplTest method checkSupportsDMNDiagram.

@Test
@SuppressWarnings("unchecked")
public void checkSupportsDMNDiagram() {
    assertTrue(provider.supports(element));
    final Element other = mock(Element.class);
    final Definition otherContent = mock(Definition.class);
    final TextAnnotation otherDefinition = mock(TextAnnotation.class);
    when(other.getContent()).thenReturn(otherContent);
    when(otherContent.getDefinition()).thenReturn(otherDefinition);
    assertFalse(provider.supports(other));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Test(org.junit.Test)

Aggregations

Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)111 Node (org.kie.workbench.common.stunner.core.graph.Node)61 Test (org.junit.Test)46 Element (org.kie.workbench.common.stunner.core.graph.Element)31 Edge (org.kie.workbench.common.stunner.core.graph.Edge)25 Graph (org.kie.workbench.common.stunner.core.graph.Graph)20 ArrayList (java.util.ArrayList)16 Optional (java.util.Optional)14 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)14 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)11 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)10 List (java.util.List)9 Before (org.junit.Before)9 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)9 HasContentDefinitionId (org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId)9 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)9 Stream (java.util.stream.Stream)8