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