use of org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder in project kie-wb-common by kiegroup.
the class AbstractCanvasGraphCommand method performOperationOnGraph.
private CommandResult<CanvasViolation> performOperationOnGraph(final AbstractCanvasHandler context, final CommandOperation op) {
// Ensure the canvas command is initialized before updating the element on the graph side.
getCanvasCommand(context);
// Obtain the graph execution context and execute the graph command updates.
final GraphCommandExecutionContext graphContext = context.getGraphExecutionContext();
if (Objects.isNull(graphContext)) {
// skipping command in case there is no graph execution context
return CanvasCommandResultBuilder.SUCCESS;
}
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = getGraphCommand(context);
CommandResult<RuleViolation> graphResult = null;
switch(op) {
case ALLOW:
graphResult = graphCommand.allow(graphContext);
break;
case EXECUTE:
graphResult = graphCommand.execute(graphContext);
break;
case UNDO:
graphResult = graphCommand.undo(graphContext);
break;
}
return new CanvasCommandResultBuilder(graphResult).build();
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder in project kie-wb-common by kiegroup.
the class AddCanvasControlPointCommand method allow.
@Override
public CommandResult<CanvasViolation> allow(AbstractCanvasHandler context) {
if (checkExistingControlPoints(ShapeUtils.getControlPoints(candidate, context))) {
return buildResult();
}
ShapeUtils.hideControlPoints(candidate, context);
List<ControlPoint> addedControlPoints = ShapeUtils.addControlPoints(candidate, context, this.controlPoints);
if (addedControlPoints.stream().map(ControlPoint::getIndex).anyMatch(Objects::isNull)) {
return new CanvasCommandResultBuilder().setType(CommandResult.Type.ERROR).addViolation(new CanvasViolationImpl.Builder().build(new RuleViolationImpl("Control Point out of connector"))).build();
}
ShapeUtils.showControlPoints(candidate, context);
allowed = Boolean.TRUE;
return buildResult();
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder in project kie-wb-common by kiegroup.
the class PasteSelectionSessionCommand method processConnectors.
private CommandResult<CanvasViolation> processConnectors(Counter processedNodesCountdown) {
if (processedNodesCountdown.equalsToValue(0)) {
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = createCommandBuilder();
commandBuilder.addCommands(clipboardControl.getElements().stream().filter(element -> element instanceof Edge).filter(Objects::nonNull).map(edge -> (Edge) edge).filter(edge -> Objects.nonNull(edge.getSourceNode()) && Objects.nonNull(clonedElements.get(edge.getSourceNode().getUUID())) && Objects.nonNull(edge.getTargetNode()) && Objects.nonNull(clonedElements.get(edge.getTargetNode().getUUID()))).map(edge -> canvasCommandFactory.cloneConnector(edge, clonedElements.get(edge.getSourceNode().getUUID()), clonedElements.get(edge.getTargetNode().getUUID()), getCanvasHandler().getDiagram().getMetadata().getShapeSetId(), cloneEdgeCallback(edge))).collect(Collectors.toList()));
return sessionCommandManager.execute(getCanvasHandler(), commandBuilder.build());
}
return new CanvasCommandResultBuilder().build();
}
Aggregations