Search in sources :

Example 16 with DMNDiagram

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

the class DMNDiagramTextPropertyProviderImpl method setText.

@Override
public void setText(final AbstractCanvasHandler canvasHandler, final CanvasCommandManager<AbstractCanvasHandler> commandManager, final Element<? extends Definition> element, final String text) {
    final Object definition = ((DMNDiagram) DefinitionUtils.getElementDefinition(element)).getDefinitions();
    final CanvasCommand<AbstractCanvasHandler> command = canvasCommandFactory.updatePropertyValue(element, definitionUtils.getNameIdentifier(definition), new Name(NameUtils.normaliseName(text)));
    commandManager.execute(canvasHandler, command);
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 17 with DMNDiagram

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

the class AbstractDMNDiagramFactory method updateName.

private void updateName(final Node<Definition<DMNDiagram>, ?> diagramNode, final String name) {
    final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(diagramNode);
    final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
    final Name dmnName = dmnDefinitions.getName();
    if (StringUtils.isEmpty(dmnName.getValue())) {
        dmnName.setValue(name);
    }
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 18 with DMNDiagram

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

the class AbstractDMNDiagramFactory method updateDefaultNameSpaces.

private void updateDefaultNameSpaces(final Node<Definition<DMNDiagram>, ?> diagramNode) {
    final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(diagramNode);
    final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
    Stream.of(DMNModelInstrumentedBase.Namespace.values()).filter(namespace -> !dmnDefinitions.getNsContext().containsValue(namespace.getUri())).forEach(namespace -> {
        if (!namespace.getPrefix().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
            dmnDefinitions.getNsContext().put(namespace.getPrefix(), namespace.getUri());
        }
    });
    String defaultNamespace = !StringUtils.isEmpty(dmnDefinitions.getNamespace().getValue()) ? dmnDefinitions.getNamespace().getValue() : DMNModelInstrumentedBase.Namespace.DEFAULT.getUri() + UUID.uuid();
    dmnDefinitions.setNamespace(new Text(defaultNamespace));
    dmnDefinitions.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), defaultNamespace);
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) UUID(org.kie.workbench.common.stunner.core.util.UUID) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Function(java.util.function.Function) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Stream(java.util.stream.Stream) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) BindableDiagramFactory(org.kie.workbench.common.stunner.core.factory.impl.BindableDiagramFactory) StringUtils(org.kie.workbench.common.stunner.core.util.StringUtils) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Node(org.kie.workbench.common.stunner.core.graph.Node) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Text(org.kie.workbench.common.dmn.api.property.dmn.Text)

Example 19 with DMNDiagram

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

use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram 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)

Aggregations

DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)33 Node (org.kie.workbench.common.stunner.core.graph.Node)25 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)19 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)17 Test (org.junit.Test)16 View (org.kie.workbench.common.stunner.core.graph.content.view.View)16 Edge (org.kie.workbench.common.stunner.core.graph.Edge)13 Graph (org.kie.workbench.common.stunner.core.graph.Graph)12 DMNModelInstrumentedBase (org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)10 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)10 ArrayList (java.util.ArrayList)9 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)8 HashMap (java.util.HashMap)7 Optional (java.util.Optional)7 DMNDefinitionSet (org.kie.workbench.common.dmn.api.DMNDefinitionSet)7 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)7 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)7 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)7 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)7