Search in sources :

Example 81 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DMNDiagramFactoryImplTest method testModelName.

@Test
@SuppressWarnings("unchecked")
public void testModelName() {
    final Diagram diagram = factory.build(NAME, metadata, graph);
    // We can safely get the first object on the iterator as we know the graph only contains one node
    final Node<View, Edge> root = (Node<View, Edge>) diagram.getGraph().nodes().iterator().next();
    final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(root);
    final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
    assertEquals(NAME, dmnDefinitions.getName().getValue());
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 82 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DMNDiagramFactoryImplTest method testModelNameWithNonEmptyExistingName.

@Test
@SuppressWarnings("unchecked")
public void testModelNameWithNonEmptyExistingName() {
    final Node<View, Edge> existingRoot = (Node<View, Edge>) graph.nodes().iterator().next();
    final DMNDiagram existingDMNDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(existingRoot);
    final Definitions existingDMNDefinitions = existingDMNDiagram.getDefinitions();
    existingDMNDefinitions.getName().setValue(EXISTING_NAME);
    final Diagram newDiagram = factory.build(NAME, metadata, graph);
    final Node<View, Edge> newRoot = (Node<View, Edge>) newDiagram.getGraph().nodes().iterator().next();
    final DMNDiagram newDMNDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(newRoot);
    final Definitions newDMNDefinitions = newDMNDiagram.getDefinitions();
    assertEquals(EXISTING_NAME, newDMNDefinitions.getName().getValue());
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 83 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DMNDiagramsSessionState method getDiagramTuple.

DMNDiagramTuple getDiagramTuple(final String dmnDiagramElementId) {
    final Diagram diagram = getDiagram(dmnDiagramElementId);
    final DMNDiagramElement dmnDiagramElement = getDMNDiagramElement(dmnDiagramElementId);
    return new DMNDiagramTuple(diagram, dmnDiagramElement);
}
Also used : DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 84 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DecisionNavigatorItemsProvider method getItems.

public List<DecisionNavigatorItem> getItems() {
    final List<DecisionNavigatorItem> items = new ArrayList<>();
    dmnDiagramsSession.getDMNDiagrams().stream().sorted((e1, e2) -> {
        final String dmnElementName1 = e1.getDMNDiagram().getName().getValue();
        final String dmnElementName2 = e2.getDMNDiagram().getName().getValue();
        return DRG.equals(dmnElementName1) ? -1 : DRG.equals(dmnElementName2) ? 1 : 0;
    }).forEach(diagramTuple -> {
        final Diagram stunner = diagramTuple.getStunnerDiagram();
        final DecisionNavigatorItem root = makeRoot(diagramTuple);
        items.add(root);
        getNodes(stunner).forEach(node -> makeItem(root, node));
    });
    if (items.size() > 1) {
        items.add(0, itemFactory.makeSeparator(DRG));
        items.add(2, itemFactory.makeSeparator(DRDs));
    }
    return items;
}
Also used : TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) DMNDiagramTuple(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramTuple) DecisionNavigatorItemFactory(org.kie.workbench.common.dmn.client.docks.navigator.factories.DecisionNavigatorItemFactory) Collectors(java.util.stream.Collectors) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) List(java.util.List) DMNDiagramsSession(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DMNDiagramUtils(org.kie.workbench.common.dmn.api.graph.DMNDiagramUtils) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 85 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class PreviewDiagramScreen method isSameDiagramSession.

private boolean isSameDiagramSession(final ClientSession session) {
    final CanvasHandler canvasHandler = session.getCanvasHandler();
    final Diagram diagram = canvasHandler.getDiagram();
    return Optional.ofNullable(diagram).map((Function<Diagram, Metadata>) Diagram::getMetadata).map(this::isSameDiagramSession).orElse(false);
}
Also used : CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Aggregations

Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)128 Test (org.junit.Test)64 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)48 Node (org.kie.workbench.common.stunner.core.graph.Node)38 Graph (org.kie.workbench.common.stunner.core.graph.Graph)31 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)24 View (org.kie.workbench.common.stunner.core.graph.content.view.View)23 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)22 ArrayList (java.util.ArrayList)20 List (java.util.List)20 Edge (org.kie.workbench.common.stunner.core.graph.Edge)20 Inject (javax.inject.Inject)15 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)15 Before (org.junit.Before)14 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 Map (java.util.Map)13 Optional (java.util.Optional)13 Collectors (java.util.stream.Collectors)13 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)13 Collection (java.util.Collection)12