Search in sources :

Example 56 with Command

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

the class UndoSessionCommandTest method testOnCommandExecuted.

@Test
@SuppressWarnings("unchecked")
public void testOnCommandExecuted() {
    command.bind(session);
    command.listen(statusCallback);
    ((UndoSessionCommand) command).onCommandAdded(new RegisterChangedEvent(canvasHandler));
    assertFalse(command.isEnabled());
    commandHistory.add(mock(Command.class));
    ((UndoSessionCommand) command).onCommandAdded(new RegisterChangedEvent(canvasHandler));
    assertTrue(command.isEnabled());
    verify(statusCallback, atLeastOnce()).execute();
    verify(commandRegistry, never()).clear();
}
Also used : AbstractClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.AbstractClientSessionCommand) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) Command(org.kie.workbench.common.stunner.core.command.Command) RegisterChangedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.registration.RegisterChangedEvent) Test(org.junit.Test)

Example 57 with Command

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

the class NodeBuilderControlImpl method build.

@Override
@SuppressWarnings("unchecked")
public void build(final NodeBuildRequest request, final BuildCallback buildCallback) {
    final double x = request.getX();
    final double y = request.getY();
    final Node<? extends View<?>, Edge> node = request.getNode();
    final Edge<? extends ViewConnector<?>, Node> inEdge = request.getInEdge();
    final Connection sourceConnection = request.getSourceConnection();
    final Connection targetConnection = request.getTargetConnection();
    if (null != node) {
        final Object nodeDef = node.getContent().getDefinition();
        final String nodeId = clientDefinitionManager.adapters().forDefinition().getId(nodeDef).value();
        final ElementBuilderControlImpl ebc = getElementBuilderControl();
        final Node<View<?>, Edge> parent = ebc.getParent(x, y);
        final Point2D childCoordinates = ebc.getComputedChildCoordinates(parent, x, y);
        final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
        ebc.getElementCommands(node, parent, ebc.getParentAssignment(parent, nodeDef), childCoordinates.getX(), childCoordinates.getY(), new AbstractElementBuilderControl.CommandsCallback() {

            @Override
            public void onComplete(final String uuid, final List<Command<AbstractCanvasHandler, CanvasViolation>> commands) {
                final CompositeCommand.Builder commandBuilder = new CompositeCommand.Builder().addCommands(commands);
                if (inEdge != null) {
                    final Object edgeDef = inEdge.getContent().getDefinition();
                    final String edgeId = clientDefinitionManager.adapters().forDefinition().getId(edgeDef).value();
                    // The commands to batch for the edge that connects both nodes.
                    commandBuilder.addCommand(commandFactory.addConnector(inEdge.getSourceNode(), inEdge, sourceConnection, ssid));
                    commandBuilder.addCommand(commandFactory.setTargetNode(node, inEdge, targetConnection));
                }
                final CommandResult<CanvasViolation> results = elementBuilderControl.getCommandManager().execute(canvasHandler, commandBuilder.build());
                if (!CommandUtils.isError(results)) {
                    updateConnectorShape(inEdge, node, sourceConnection, targetConnection);
                }
                buildCallback.onSuccess(uuid);
            }

            @Override
            public void onError(final ClientRuntimeError error) {
                buildCallback.onError(error);
            }
        });
    }
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) View(org.kie.workbench.common.stunner.core.graph.content.view.View) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 58 with Command

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

the class ResizeNodeCommand method getResizeCommands.

/**
 * It provides the necessary canvas commands in order to update the domain model with new values that will met
 * the new bounding box size.
 * It always updates the element's position, as resize can update it, and it updates as well some of the bean's properties.
 */
private List<Command<AbstractCanvasHandler, CanvasViolation>> getResizeCommands(final AbstractCanvasHandler canvasHandler, final double w, final double h) {
    final Definition content = candidate.getContent();
    final Object def = content.getDefinition();
    final DefinitionAdapter<Object> adapter = canvasHandler.getDefinitionManager().adapters().registry().getDefinitionAdapter(def.getClass());
    final List<Command<AbstractCanvasHandler, CanvasViolation>> result = new LinkedList<>();
    final String widthField = adapter.getMetaPropertyField(def, PropertyMetaTypes.WIDTH);
    if (null != widthField) {
        appendCommandForModelProperty(canvasHandler, widthField, w, result);
    }
    final String heightField = adapter.getMetaPropertyField(def, PropertyMetaTypes.HEIGHT);
    if (null != heightField) {
        appendCommandForModelProperty(canvasHandler, heightField, h, result);
    }
    final String radiusField = adapter.getMetaPropertyField(def, PropertyMetaTypes.RADIUS);
    if (null != radiusField) {
        final double r = w > h ? (h / 2) : (w / 2);
        appendCommandForModelProperty(canvasHandler, radiusField, r, result);
    }
    return result;
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) LinkedList(java.util.LinkedList)

Example 59 with Command

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

the class DeferredCompositeCommandTest method mockCommand.

@SuppressWarnings("unchecked")
private Command mockCommand(CommandResult<RuleViolation> allowResult, CommandResult<RuleViolation> executeResult) {
    Command command = mock(Command.class);
    when(command.allow(commandExecutionContext)).thenReturn(allowResult);
    when(command.execute(commandExecutionContext)).thenReturn(executeResult);
    when(command.undo(commandExecutionContext)).thenReturn(GraphCommandResultBuilder.SUCCESS);
    return command;
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command)

Example 60 with Command

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

the class DeferredCompositeCommandTest method testExecuteWithAllowFailure.

@Test
@SuppressWarnings("unchecked")
public void testExecuteWithAllowFailure() {
    // c1 command succeeded
    Command c1 = mockCommand(SUCCESS, SUCCESS);
    // c2 command allowance check failed
    Command c2 = mockCommand(failed(), SUCCESS);
    // no matter
    Command c3 = mockCommand(SUCCESS, SUCCESS);
    // no matter
    Command c4 = mockCommand(SUCCESS, SUCCESS);
    compositeCommand = buildCompositeCommand(c1, c2, c3, c4);
    compositeCommand.execute(commandExecutionContext);
    // c1 must have been allowed, executed and undone
    verifyAllowedExecutedAndUnDone(c1);
    // c2 must have been allowed but not executed nor undone
    verify(c2).allow(commandExecutionContext);
    verify(c2, never()).execute(commandExecutionContext);
    verify(c2, never()).undo(commandExecutionContext);
    verifyNeverUsed(c3);
    verifyNeverUsed(c4);
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) 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