Search in sources :

Example 66 with Definition

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

the class TestingGraphMockHandler method newViewNode.

public Node newViewNode(String uuid, Optional<Object> def, final double x, final double y, final double w, final double h) {
    final Object definition = def.isPresent() ? def.get() : newDef("def-" + uuid, Optional.empty());
    when(definitionUtils.buildBounds(eq(definition), anyDouble(), anyDouble())).thenReturn(new BoundsImpl(new BoundImpl(x, y), new BoundImpl(x + w, y + h)));
    final Node<Definition<Object>, Edge> result = nodeFactory.build(uuid, definition);
    execute(commandFactory.addNode(result));
    when(graphIndex.getNode(eq(uuid))).thenReturn(result);
    when(graphIndex.get(eq(uuid))).thenReturn(result);
    return result;
}
Also used : BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 67 with Definition

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

the class LiteralExpressionGridTest method setup.

@Before
public void setup() {
    tupleWithoutValue = new GridCellTuple(0, 0, gridWidget);
    tupleWithValue = new GridCellValueTuple<>(0, 0, gridWidget, new BaseGridCellValue<>("value"));
    definition = new LiteralExpressionEditorDefinition(gridPanel, gridLayer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, cellEditorControls, listSelector, translationService);
    final Decision decision = new Decision();
    decision.setName(new Name("name"));
    hasName = Optional.of(decision);
    expression = definition.getModelClass();
    expression.ifPresent(e -> e.setText(EXPRESSION_TEXT));
    doReturn(session).when(sessionManager).getCurrentSession();
    doReturn(canvasHandler).when(session).getCanvasHandler();
    doReturn(mock(Bounds.class)).when(gridLayer).getVisibleBounds();
    when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
    when(canvasHandler.getGraphIndex()).thenReturn(index);
    when(index.get(anyString())).thenReturn(element);
    when(element.getContent()).thenReturn(mock(Definition.class));
    when(definitionUtils.getNameIdentifier(any())).thenReturn("name");
    when(canvasCommandFactory.updatePropertyValue(any(Element.class), anyString(), any())).thenReturn(mock(UpdateElementPropertyCommand.class));
    when(parentGridWidget.getModel()).thenReturn(parentGridUiModel);
    when(parent.getGridWidget()).thenReturn(parentGridWidget);
    when(parent.getRowIndex()).thenReturn(0);
    when(parent.getColumnIndex()).thenReturn(1);
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Bounds(org.uberfire.ext.wires.core.grids.client.model.Bounds) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) HasName(org.kie.workbench.common.dmn.api.definition.HasName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 68 with Definition

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

the class BaseExpressionGrid method getUpdateStunnerTitleCommand.

protected Optional<AbstractCanvasGraphCommand> getUpdateStunnerTitleCommand(final String value) {
    AbstractCanvasGraphCommand command = null;
    if (nodeUUID.isPresent()) {
        final String uuid = nodeUUID.get();
        final AbstractCanvasHandler canvasHandler = (AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler();
        final Element<?> element = canvasHandler.getGraphIndex().get(uuid);
        if (element.getContent() instanceof Definition) {
            final Definition definition = (Definition) element.getContent();
            final String nameId = definitionUtils.getNameIdentifier(definition.getDefinition());
            if (nameId != null) {
                command = (AbstractCanvasGraphCommand) canvasCommandFactory.updatePropertyValue(element, nameId, value);
            }
        }
    }
    return Optional.ofNullable(command);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AbstractCanvasGraphCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasGraphCommand) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition)

Example 69 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition 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 70 with Definition

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

the class DMNDiagramsSessionTest method createNodeWithContentDefinitionId.

private Node createNodeWithContentDefinitionId(final String contentDefinitionId) {
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    when(drgElement.getContentDefinitionId()).thenReturn(contentDefinitionId);
    when(definition.getDefinition()).thenReturn(drgElement);
    when(node.getContent()).thenReturn(definition);
    return node;
}
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)

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