Search in sources :

Example 16 with DMNDiagramElement

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement in project kie-wb-common by kiegroup.

the class DMNDiagramsSessionTest method testClear.

@Test
public void testClear() {
    final DMNDiagramElement dmnDiagram = mock(DMNDiagramElement.class);
    final Diagram stunnerDiagram = mock(Diagram.class);
    final String diagramId = "0000";
    when(dmnDiagram.getId()).thenReturn(new Id(diagramId));
    dmnDiagramsSession.add(dmnDiagram, stunnerDiagram);
    assertEquals(dmnDiagram, dmnDiagramsSession.getDMNDiagramElement(diagramId));
    assertEquals(stunnerDiagram, dmnDiagramsSession.getDiagram(diagramId));
    assertEquals(dmnDiagram, dmnDiagramsSession.getDiagramTuple(diagramId).getDMNDiagram());
    assertEquals(stunnerDiagram, dmnDiagramsSession.getDiagramTuple(diagramId).getStunnerDiagram());
    dmnDiagramsSession.clear();
    assertNull(dmnDiagramsSession.getDMNDiagramElement(diagramId));
    assertNull(dmnDiagramsSession.getDiagram(diagramId));
    assertNull(dmnDiagramsSession.getDiagramTuple(diagramId).getDMNDiagram());
    assertNull(dmnDiagramsSession.getDiagramTuple(diagramId).getStunnerDiagram());
}
Also used : Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 17 with DMNDiagramElement

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement in project kie-wb-common by kiegroup.

the class ObserverBuilderControl method updateElementFromDefinition.

@Override
@SuppressWarnings("unchecked")
protected void updateElementFromDefinition(final Element element, final Object definition) {
    final Object content = element.getContent();
    if (!(content instanceof View)) {
        return;
    }
    final Object newDefinition = ((View) content).getDefinition();
    if (newDefinition instanceof HasName && definition instanceof HasName) {
        ((HasName) newDefinition).getName().setValue(((HasName) definition).getName().getValue());
    }
    if (newDefinition instanceof DynamicReadOnly && definition instanceof DynamicReadOnly) {
        ((DynamicReadOnly) newDefinition).setAllowOnlyVisualChange(((DynamicReadOnly) definition).isAllowOnlyVisualChange());
    }
    if (newDefinition instanceof HasVariable && definition instanceof HasVariable) {
        ((HasVariable) newDefinition).setVariable(((HasVariable) definition).getVariable());
    }
    if (newDefinition instanceof BusinessKnowledgeModel && definition instanceof BusinessKnowledgeModel) {
        ((BusinessKnowledgeModel) newDefinition).setEncapsulatedLogic(((BusinessKnowledgeModel) definition).getEncapsulatedLogic());
    }
    if (newDefinition instanceof HasExpression && definition instanceof HasExpression) {
        ((HasExpression) newDefinition).setExpression(((HasExpression) definition).getExpression());
    }
    if (newDefinition instanceof DMNElement && definition instanceof DMNElement) {
        final DMNElement dmnElement = (DMNElement) definition;
        if (!StringUtils.isEmpty(dmnElement.getId().getValue())) {
            ((DMNElement) newDefinition).getId().setValue(dmnElement.getId().getValue());
        }
    }
    final Optional<DMNDiagramElement> currentDMNDiagramElement = getDMNDiagramsSession().getCurrentDMNDiagramElement();
    if (currentDMNDiagramElement.isPresent() && newDefinition instanceof HasContentDefinitionId) {
        ((HasContentDefinitionId) newDefinition).setDiagramId(currentDMNDiagramElement.get().getId().getValue());
    }
}
Also used : DynamicReadOnly(org.kie.workbench.common.forms.adf.definitions.DynamicReadOnly) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasContentDefinitionId(org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId) HasName(org.kie.workbench.common.dmn.api.definition.HasName) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 18 with DMNDiagramElement

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement in project kie-wb-common by kiegroup.

the class DMNMarshallerService method onDiagramSelected.

public void onDiagramSelected(@Observes final DMNDiagramSelected selected) {
    final DMNDiagramElement dmnDiagramElement = selected.getDiagramElement();
    if (isActiveService()) {
        final String diagramId = dmnDiagramElement.getId().getValue();
        final Diagram stunnerDiagram = dmnDiagramsSession.getDiagram(diagramId);
        final Metadata metadata = dmnDiagramsSession.getDRGDiagram().getMetadata();
        final String fileName = metadata.getPath().getFileName();
        final Diagram diagram = dmnDiagramFactory.build(fileName, metadata, stunnerDiagram.getGraph());
        onDiagramLoad(diagram);
    }
}
Also used : Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) JSONString(com.google.gwt.json.client.JSONString) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)

Example 19 with DMNDiagramElement

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement 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 20 with DMNDiagramElement

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement in project kie-wb-common by kiegroup.

the class DecisionNavigatorItemFactory method makeRoot.

public DecisionNavigatorItem makeRoot(final DMNDiagramTuple diagramTuple) {
    final DMNDiagramElement dmnDiagramElement = diagramTuple.getDMNDiagram();
    final String uuid = dmnDiagramElement.getId().getValue();
    final String diagramName = dmnDiagramElement.getName().getValue();
    final String label;
    final boolean isDRG = isDRG(dmnDiagramElement);
    if (isDRG) {
        final Graph graph = diagramTuple.getStunnerDiagram().getGraph();
        final Node<?, ?> rootNode = getRootNode(graph);
        label = getNodeName(rootNode);
    } else {
        label = diagramName;
    }
    return navigatorItemBuilder().withUUID(uuid).withLabel(label).withType(ROOT).withIsDRG(isDRG).withOnClick(getOnClickAction(dmnDiagramElement)).withOnUpdate(getOnUpdate(dmnDiagramElement)).withOnRemove(getOnRemove(dmnDiagramElement)).build();
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)

Aggregations

DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)35 Test (org.junit.Test)23 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)21 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)13 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)10 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)8 Node (org.kie.workbench.common.stunner.core.graph.Node)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 DMNDiagramTuple (org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramTuple)5 Graph (org.kie.workbench.common.stunner.core.graph.Graph)5 DecisionNavigatorItem (org.kie.workbench.common.dmn.client.docks.navigator.DecisionNavigatorItem)4 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)3 HasContentDefinitionId (org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId)3 JSONString (com.google.gwt.json.client.JSONString)2 QName (javax.xml.namespace.QName)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)2 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)2