Search in sources :

Example 26 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class CaseGraphFactoryImpl method buildInitialisationCommands.

// Add a Case diagram and a start event nodes by default.
@Override
protected List<Command> buildInitialisationCommands() {
    final List<Command> commands = new ArrayList<>();
    final Node<Definition<BPMNDiagram>, Edge> diagramNode = (Node<Definition<BPMNDiagram>, Edge>) factoryManager.newElement(UUID.uuid(), getDefinitionId(getDiagramType()));
    commands.add(graphCommandFactory.addNode(diagramNode));
    final AdHoc adHoc = diagramNode.getContent().getDefinition().getDiagramSet().getAdHoc();
    adHoc.setValue(true);
    return commands;
}
Also used : BPMNDiagram(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram) Command(org.kie.workbench.common.stunner.core.command.Command) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) AdHoc(org.kie.workbench.common.stunner.bpmn.definition.property.diagram.AdHoc) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 27 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class ObserverBuilderControlTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) {
            ServiceCallback<Node<View<Object>, Edge>> callback = (ServiceCallback<Node<View<Object>, Edge>>) (invocationOnMock.getArguments()[2]);
            view = new ViewImpl<>(new Object(), Bounds.create(0.0, 0.0, 10.0, 20.0));
            Node<View<Object>, Edge> item = new NodeImpl<>("UUID");
            item.setContent(view);
            callback.onSuccess(item);
            return null;
        }
    }).when(clientFactoryServices).newElement(anyString(), anyString(), any(ServiceCallback.class));
    when(graphBoundsIndexer.setRootUUID(anyString())).thenReturn(graphBoundsIndexer);
    AdapterManager adapters = mock(AdapterManager.class);
    DefinitionAdapter definitionAdapter = mock(DefinitionAdapter.class);
    DefinitionSetRuleAdapter rulesAdapter = mock(DefinitionSetRuleAdapter.class);
    when(definitionAdapter.getId(any())).thenReturn(DefinitionId.build("Object"));
    when(rulesAdapter.getRuleSet(any())).thenReturn(mock(RuleSet.class));
    when(adapters.forDefinition()).thenReturn(definitionAdapter);
    when(adapters.forRules()).thenReturn(rulesAdapter);
    when(definitionAdapter.getId(DEF)).thenReturn(DefinitionId.build(DEF_ID));
    when(definitionAdapter.getLabels(DEF)).thenReturn(new String[0]);
    when(clientDefinitionManager.adapters()).thenReturn(adapters);
    when(clientDefinitionManager.definitionSets()).thenReturn(mock(TypeDefinitionSetRegistry.class));
    when(canvasCommandFactory.addNode(any(Node.class), any())).thenAnswer(new Answer<Command>() {

        @Override
        public Command answer(InvocationOnMock invocationOnMock) {
            Node node = (Node) invocationOnMock.getArguments()[0];
            String uid = (String) invocationOnMock.getArguments()[1];
            return new AddCanvasNodeCommand(node, uid);
        }
    });
    when(canvasCommandFactory.updatePosition(any(Node.class), any(Point2D.class))).thenAnswer(new Answer<Command>() {

        @Override
        public Command answer(InvocationOnMock invocationOnMock) {
            Node node = (Node) invocationOnMock.getArguments()[0];
            Point2D location = (Point2D) invocationOnMock.getArguments()[1];
            return new UpdateElementPositionCommand(node, location);
        }
    });
    when(canvasCommandFactory.draw()).thenReturn(mock(CanvasCommand.class));
    ShapeSet shapeSet = mock(ShapeSet.class);
    ShapeFactory shapeFactory = mock(ShapeFactory.class);
    when(shapeFactory.newShape(any())).thenReturn(mock(ElementShape.class));
    when(shapeSet.getShapeFactory()).thenReturn(shapeFactory);
    when(shapeManager.getShapeSet(any())).thenReturn(shapeSet);
    when(shapeManager.getDefaultShapeSet(any())).thenReturn(shapeSet);
    tested = new ObserverBuilderControl(clientDefinitionManager, clientFactoryServices, ruleManager, canvasCommandFactory, mock(ClientTranslationMessages.class), graphBoundsIndexer, mock(EventSourceMock.class));
    Diagram diagram = mock(Diagram.class);
    Metadata metadata = mock(Metadata.class);
    when(metadata.getCanvasRootUUID()).thenReturn("ID");
    when(diagram.getMetadata()).thenReturn(metadata);
    MutableIndex index = mock(MutableIndex.class);
    Graph graph = mock(Graph.class);
    DefinitionSet graphContent = mock(DefinitionSet.class);
    when(graph.getContent()).thenReturn(graphContent);
    when(index.getGraph()).thenReturn(graph);
    when(graphIndexBuilder.build(any(Graph.class))).thenReturn(index);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.emptyList());
    CanvasCommandManager commandManager = mock(CanvasCommandManager.class);
    doAnswer(invocationOnMock -> {
        Command command = (Command) invocationOnMock.getArguments()[1];
        command.execute(invocationOnMock.getArguments()[0]);
        return null;
    }).when(commandManager).execute(any(), any(Command.class));
    when(commandManagerProvider.getCommandManager()).thenReturn(commandManager);
    canvas = mock(AbstractCanvas.class);
    canvasTransform = spy(new TransformImpl(new Point2D(0, 0), new Point2D(1, 1)));
    canvasView = mock(AbstractCanvas.CanvasView.class);
    canvasWidget = mock(Widget.class);
    canvasElement = mock(com.google.gwt.user.client.Element.class);
    document = mock(Document.class);
    when(canvas.getView()).thenReturn(canvasView);
    when(canvas.getTransform()).thenReturn(canvasTransform);
    when(canvasView.asWidget()).thenReturn(canvasWidget);
    when(canvasWidget.getElement()).thenReturn(canvasElement);
    when(canvasElement.getOwnerDocument()).thenReturn(document);
    canvasPanel = mock(CanvasPanel.class);
    when(canvasView.getPanel()).thenReturn(canvasPanel);
    canvasHandler = new CanvasHandlerImpl(clientDefinitionManager, canvasCommandFactory, ruleManager, graphUtils, graphIndexBuilder, shapeManager, mock(TextPropertyProviderFactory.class), mock(EventSourceMock.class), null, null, null);
    GraphCommandExecutionContext graphCommandExecutionContext = mock(GraphCommandExecutionContext.class);
    when(graphCommandExecutionContext.getGraphIndex()).thenReturn(index);
    canvasHandler.setGraphExecutionContext(() -> graphCommandExecutionContext);
    canvasHandler.handle(canvas);
    canvasHandler.draw(diagram, mock(ParameterizedCommand.class));
    tested.init(canvasHandler);
    tested.setCommandManagerProvider(commandManagerProvider);
}
Also used : TypeDefinitionSetRegistry(org.kie.workbench.common.stunner.core.registry.definition.TypeDefinitionSetRegistry) CanvasPanel(org.kie.workbench.common.stunner.core.client.canvas.CanvasPanel) Node(org.kie.workbench.common.stunner.core.graph.Node) ShapeSet(org.kie.workbench.common.stunner.core.client.ShapeSet) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) TransformImpl(org.kie.workbench.common.stunner.core.client.canvas.TransformImpl) Widget(com.google.gwt.user.client.ui.Widget) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory) ObserverBuilderControl(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.ObserverBuilderControl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Document(com.google.gwt.dom.client.Document) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) MutableIndex(org.kie.workbench.common.stunner.core.graph.processing.index.MutableIndex) CanvasHandlerImpl(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandlerImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Graph(org.kie.workbench.common.stunner.core.graph.Graph) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) AddCanvasNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddCanvasNodeCommand) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CanvasCommandManager(org.kie.workbench.common.stunner.core.client.command.CanvasCommandManager) AddCanvasNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddCanvasNodeCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) DefinitionSetRuleAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionSetRuleAdapter) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Before(org.junit.Before)

Example 28 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class DeleteNodeCommandTest method exclusionsTestCanvasCommands.

@Test
public void exclusionsTestCanvasCommands() {
    final SafeDeleteNodeCommand.Options options = SafeDeleteNodeCommand.Options.exclude(new HashSet<String>() {

        {
            add(graphHolder.edge2.getUUID());
        }
    });
    this.tested = new DeleteNodeCommand(graphHolder.intermNode, options);
    final CommandResult<CanvasViolation> result = tested.allow(canvasHandler);
    assertEquals(CommandResult.Type.INFO, result.getType());
    final AbstractCompositeCommand<AbstractCanvasHandler, CanvasViolation> compositeCommand = tested.getCommand();
    assertNotNull(compositeCommand);
    assertEquals(6, compositeCommand.size());
    final List<Command<AbstractCanvasHandler, CanvasViolation>> commands = compositeCommand.getCommands();
    assertNotNull(commands);
    final CanvasUndockNodeCommand c1 = (CanvasUndockNodeCommand) commands.get(0);
    final RemoveCanvasChildrenCommand c2 = (RemoveCanvasChildrenCommand) commands.get(1);
    final DeleteCanvasNodeCommand c3 = (DeleteCanvasNodeCommand) commands.get(2);
    final DeleteCanvasConnectorCommand c5 = (DeleteCanvasConnectorCommand) commands.get(3);
    final RemoveCanvasChildrenCommand c4 = (RemoveCanvasChildrenCommand) commands.get(4);
    final DeleteCanvasNodeCommand c6 = (DeleteCanvasNodeCommand) commands.get(5);
    assertEquals(graphHolder.intermNode, c1.getParent());
    assertEquals(graphHolder.dockedNode, c1.getChild());
    assertEquals(graphHolder.dockedNode, c2.getChildren().iterator().next());
    assertEquals(graphHolder.parentNode, c2.getParent());
    assertEquals(graphHolder.dockedNode, c3.getCandidate());
    assertEquals(graphHolder.parentNode, c4.getParent());
    assertEquals(graphHolder.intermNode, c4.getChildren().iterator().next());
    assertEquals(graphHolder.edge1, c5.getCandidate());
    assertEquals(graphHolder.intermNode, c6.getCandidate());
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) SafeDeleteNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SafeDeleteNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand) SafeDeleteNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SafeDeleteNodeCommand) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) SafeDeleteNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SafeDeleteNodeCommand) Test(org.junit.Test)

Example 29 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class ElementBuilderControlImplTest method getElementCommandsNoParent.

@Test
public void getElementCommandsNoParent() {
    ParentAssignment parentAssignment = ParentAssignment.NONE;
    elementBuilderControl.getElementCommands(node, parent, parentAssignment, X, Y, callback);
    verify(callback).onComplete(any(), commandsCapture.capture());
    List<Command<AbstractCanvasHandler, CanvasViolation>> commands = commandsCapture.getValue();
    assertTrue(commands.get(0) instanceof AddNodeCommand);
    assertTrue(commands.get(1) instanceof UpdateElementPositionCommand);
    verify(canvasCommandFactory).addNode(node, SHAPE_SET_ID);
    ArgumentCaptor<Point2D> positionCaptor = ArgumentCaptor.forClass(Point2D.class);
    verify(canvasCommandFactory).updatePosition(eq(node), positionCaptor.capture());
    assertEquals(positionCaptor.getValue(), new Point2D(X, Y));
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) UpdateDockNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateDockNodeCommand) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ParentAssignment(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Test(org.junit.Test)

Example 30 with Command

use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.

the class ElementBuilderControlImplTest method getElementCommandsContainment.

@Test
public void getElementCommandsContainment() {
    ParentAssignment parentAssignment = ParentAssignment.CONTAINMENT;
    elementBuilderControl.getElementCommands(node, parent, parentAssignment, X, Y, callback);
    verify(callback).onComplete(any(), commandsCapture.capture());
    List<Command<AbstractCanvasHandler, CanvasViolation>> commands = commandsCapture.getValue();
    assertTrue(commands.get(0) instanceof AddChildNodeCommand);
    assertTrue(commands.get(1) instanceof UpdateElementPositionCommand);
    verify(canvasCommandFactory).addChildNode(parent, node, SHAPE_SET_ID);
    ArgumentCaptor<Point2D> positionCaptor = ArgumentCaptor.forClass(Point2D.class);
    verify(canvasCommandFactory).updatePosition(eq(node), positionCaptor.capture());
    assertEquals(positionCaptor.getValue(), new Point2D(X, Y));
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) UpdateDockNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateDockNodeCommand) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ParentAssignment(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Test(org.junit.Test)

Aggregations

Command (org.kie.workbench.common.stunner.core.command.Command)74 Test (org.junit.Test)53 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)23 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)22 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)19 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)16 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Node (org.kie.workbench.common.stunner.core.graph.Node)12 List (java.util.List)10 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)10 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)10 View (org.kie.workbench.common.stunner.core.graph.content.view.View)9 SetCellValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand)7 Consumer (java.util.function.Consumer)6 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)6 ArrayList (java.util.ArrayList)5 AddNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand)5 Element (org.kie.workbench.common.stunner.core.graph.Element)5 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)5