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