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);
}
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);
}
}
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);
}
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());
}
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());
}
Aggregations