Search in sources :

Example 41 with Diagram

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

the class ActivityDataIOEditorWidget method isMultipleInstanceVariable.

public boolean isMultipleInstanceVariable(final String name) {
    ClientSession session = sessionManager.getCurrentSession();
    Diagram diagram = session.getCanvasHandler().getDiagram();
    Node selectedNode = getSelectedNode(diagram, sessionManager.getCurrentSession());
    Collection<VariableUsage> variableUsages = VariableUtils.findVariableUsages(selectedNode, name);
    return variableUsages.stream().anyMatch(variableUsage -> variableUsage.getUsageType() == VariableUsage.USAGE_TYPE.MULTIPLE_INSTANCE_DATA_INPUT || variableUsage.getUsageType() == VariableUsage.USAGE_TYPE.MULTIPLE_INSTANCE_DATA_OUTPUT);
}
Also used : ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) ClientUtils.getSelectedNode(org.kie.workbench.common.stunner.core.client.util.ClientUtils.getSelectedNode) Node(org.kie.workbench.common.stunner.core.graph.Node) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) VariableUsage(org.kie.workbench.common.stunner.bpmn.client.util.VariableUsage)

Example 42 with Diagram

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

the class AssignmentsEditorWidget method getProcessVariables.

protected String getProcessVariables() {
    Diagram diagram = canvasSessionManager.getCurrentSession().getCanvasHandler().getDiagram();
    Node selectedElement = getSelectedElement();
    String variables = VariableUtils.encodeProcessVariables(diagram, selectedElement);
    StringBuilder sb = new StringBuilder();
    if (!variables.isEmpty()) {
        sb.append(variables);
    }
    String dataObjects = DataObjectUtils.findDataObjects(canvasSessionManager.getCurrentSession(), graphUtils, getSelectedElement(), getParentIds()).stream().map(AssignmentsEditorWidget::dataObjectToProcessVariableFormat).collect(Collectors.joining(","));
    if (!dataObjects.isEmpty()) {
        sb.append(dataObjects);
    }
    return sb.toString();
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 43 with Diagram

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

the class ManagedToolbar method load.

@Override
public void load(final S session) {
    final Diagram diagram = session.getCanvasHandler().getDiagram();
    final Annotation qualifier = definitionUtils.getQualifier(diagram.getMetadata().getDefinitionSetId());
    // Initialize the command and view instances.
    commandTypes.stream().map(type -> loadCommand(type, qualifier)).forEach(this::registerCommand);
    // Show the toolbar.
    show(session);
}
Also used : InstanceUtils(org.kie.workbench.common.stunner.core.client.session.impl.InstanceUtils) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) ToolbarView(org.kie.workbench.common.stunner.client.widgets.toolbar.ToolbarView) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) AbstractToolbarItem(org.kie.workbench.common.stunner.client.widgets.toolbar.item.AbstractToolbarItem) Inject(javax.inject.Inject) AbstractToolbarCommand(org.kie.workbench.common.stunner.client.widgets.toolbar.command.AbstractToolbarCommand) List(java.util.List) Dependent(javax.enterprise.context.Dependent) Annotation(java.lang.annotation.Annotation) PostConstruct(javax.annotation.PostConstruct) Any(javax.enterprise.inject.Any) LinkedList(java.util.LinkedList) Toolbar(org.kie.workbench.common.stunner.client.widgets.toolbar.Toolbar) ToolbarCommand(org.kie.workbench.common.stunner.client.widgets.toolbar.ToolbarCommand) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Annotation(java.lang.annotation.Annotation) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 44 with Diagram

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

the class GeneralCreateNodeActionTest method testExecuteAction.

@Test
public void testExecuteAction() {
    final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class);
    final String sourceNodeId = "src-id";
    final String targetNodeId = "dest-id";
    final String connectorId = "edge-id";
    final AbstractCanvas canvas = mock(AbstractCanvas.class);
    doReturn(canvas).when(canvasHandler).getCanvas();
    doReturn(canvas).when(canvasHandler).getAbstractCanvas();
    final Diagram diagram = mock(Diagram.class);
    doReturn(diagram).when(canvasHandler).getDiagram();
    final Metadata metadata = mock(Metadata.class);
    doReturn(metadata).when(diagram).getMetadata();
    final String shapeSetId = "shape-set-id";
    doReturn(shapeSetId).when(metadata).getShapeSetId();
    final Index graphIndex = mock(Index.class);
    doReturn(graphIndex).when(canvasHandler).getGraphIndex();
    final Element sourceElement = mock(Element.class);
    doReturn(sourceElement).when(graphIndex).get(sourceNodeId);
    final Node sourceNode = mock(Node.class);
    final View sourceElementContent = mock(View.class);
    doReturn(sourceElementContent).when(sourceNode).getContent();
    doReturn(Bounds.create(10d, 0d, 200d, 100d)).when(sourceElementContent).getBounds();
    doReturn(sourceNode).when(sourceElement).asNode();
    doReturn(Collections.emptyList()).when(sourceNode).getInEdges();
    final Element targetNodeElement = mock(Element.class);
    doReturn(targetNodeElement).when(clientFactoryManager).newElement(anyString(), eq(targetNodeId));
    final Node targetNode = mock(Node.class);
    final View targetElementContent = mock(View.class);
    doReturn(targetElementContent).when(targetNode).getContent();
    doReturn(Bounds.create(-100d, 0d, 0d, 100d)).when(targetElementContent).getBounds();
    doReturn(targetNode).when(targetNodeElement).asNode();
    final String targetNodeUuid = "target-uuid";
    doReturn(targetNodeUuid).when(targetNode).getUUID();
    final Element connectorElement = mock(Element.class);
    doReturn(connectorElement).when(clientFactoryManager).newElement(anyString(), eq(connectorId));
    final Edge connectorEdge = mock(Edge.class);
    doReturn(connectorEdge).when(connectorElement).asEdge();
    when(canvasLayoutUtils.getNext(eq(canvasHandler), eq(sourceNode), eq(targetNode))).thenReturn(new Point2D(100d, 500d));
    createNodeAction.executeAction(canvasHandler, sourceNodeId, targetNodeId, connectorId);
    final ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
    verify(sessionCommandManager).execute(eq(canvasHandler), commandArgumentCaptor.capture());
    final DeferredCompositeCommand command = (DeferredCompositeCommand) commandArgumentCaptor.getValue();
    final DeferredCommand c0 = (DeferredCommand) command.getCommands().get(0);
    final DeferredCommand c1 = (DeferredCommand) command.getCommands().get(1);
    final DeferredCommand c2 = (DeferredCommand) command.getCommands().get(2);
    final DeferredCommand c3 = (DeferredCommand) command.getCommands().get(3);
    final AddNodeCommand addNodeCommand = (AddNodeCommand) c0.getCommand();
    final UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) c1.getCommand();
    final AddConnectorCommand addConnectorCommand = (AddConnectorCommand) c2.getCommand();
    final SetConnectionTargetNodeCommand setTargetNodeCommand = (SetConnectionTargetNodeCommand) c3.getCommand();
    Assertions.assertThat(targetNode).isEqualTo(addNodeCommand.getCandidate());
    Assertions.assertThat(shapeSetId).isEqualTo(addNodeCommand.getShapeSetId());
    Assertions.assertThat(connectorEdge).isEqualTo(addConnectorCommand.getCandidate());
    Assertions.assertThat(sourceNode).isEqualTo(addConnectorCommand.getSource());
    Assertions.assertThat(shapeSetId).isEqualTo(addConnectorCommand.getShapeSetId());
    Assertions.assertThat(connectorEdge).isEqualTo(setTargetNodeCommand.getEdge());
    Assertions.assertThat(targetNode).isEqualTo(setTargetNodeCommand.getNode());
    Assertions.assertThat(targetNode).isEqualTo(updateElementPositionCommand.getElement());
    Assertions.assertThat(new Point2D(100d, 500d)).isEqualTo(updateElementPositionCommand.getLocation());
    final ArgumentCaptor<CanvasSelectionEvent> eventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
    verify(selectionEvent).fire(eventArgumentCaptor.capture());
    final CanvasSelectionEvent eCaptured = eventArgumentCaptor.getValue();
    Assertions.assertThat(targetNodeUuid).isEqualTo(eCaptured.getIdentifiers().iterator().next());
    Assertions.assertThat(addConnectorCommand.getConnection()).isInstanceOf(MagnetConnection.class);
    Assertions.assertThat(((MagnetConnection) addConnectorCommand.getConnection()).getMagnetIndex().getAsInt()).isEqualTo(MagnetConnection.MAGNET_LEFT);
    Assertions.assertThat(setTargetNodeCommand.getConnection()).isInstanceOf(MagnetConnection.class);
    Assertions.assertThat(((MagnetConnection) setTargetNodeCommand.getConnection()).getMagnetIndex().getAsInt()).isEqualTo(MagnetConnection.MAGNET_RIGHT);
}
Also used : DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) AddConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) DeferredCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge) AddConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand) DeferredCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCommand) Test(org.junit.Test)

Example 45 with Diagram

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

the class ClientFactoryServicesTest method testNewDiagramLocal.

@Test
@SuppressWarnings("unchecked")
public void testNewDiagramLocal() {
    String id = "id1";
    String name = "name1";
    ServiceCallback<Diagram> callback = mock(ServiceCallback.class);
    Diagram def = mock(Diagram.class);
    when(clientFactoryManager.newDiagram(eq(name), eq(id), any(Metadata.class))).thenReturn(def);
    tested.newDiagram(name, id, metadata, callback);
    verify(callback, times(1)).onSuccess(eq(def));
    verify(clientFactoryManager, times(1)).newDiagram(eq(name), eq(id), eq(metadata));
    verify(factoryService, times(0)).newDiagram(anyString(), anyString(), any(Metadata.class));
}
Also used : Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

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