Search in sources :

Example 1 with CanvasCommandResultBuilder

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();
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 2 with CanvasCommandResultBuilder

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();
}
Also used : RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) Objects(java.util.Objects) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) CanvasViolationImpl(org.kie.workbench.common.stunner.core.client.command.CanvasViolationImpl)

Example 3 with CanvasCommandResultBuilder

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();
}
Also used : Session(org.kie.workbench.common.stunner.core.client.session.Session) Edge(org.kie.workbench.common.stunner.core.graph.Edge) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) HashMap(java.util.HashMap) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) View(org.kie.workbench.common.stunner.core.graph.content.view.View) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) Inject(javax.inject.Inject) AbstractClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.AbstractClientSessionCommand) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Map(java.util.Map) Observes(javax.enterprise.event.Observes) Element(org.kie.workbench.common.stunner.core.graph.Element) ClipboardControl(org.kie.workbench.common.stunner.core.client.canvas.controls.clipboard.ClipboardControl) StreamSupport(java.util.stream.StreamSupport) ClientFullSession(org.kie.workbench.common.stunner.core.client.session.ClientFullSession) Command(org.kie.workbench.common.stunner.core.command.Command) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Event(javax.enterprise.event.Event) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) CanvasCommandFactory(org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory) Collection(java.util.Collection) Key(org.kie.workbench.common.stunner.core.client.event.keyboard.KeyboardEvent.Key) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) Objects(java.util.Objects) Consumer(java.util.function.Consumer) KeysMatcher.doKeysMatch(org.kie.workbench.common.stunner.core.client.canvas.controls.keyboard.KeysMatcher.doKeysMatch) Stream(java.util.stream.Stream) Dependent(javax.enterprise.context.Dependent) CommandUtils(org.kie.workbench.common.stunner.core.command.util.CommandUtils) Optional(java.util.Optional) Counter(org.kie.workbench.common.stunner.core.util.Counter) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Collections(java.util.Collections) Node(org.kie.workbench.common.stunner.core.graph.Node) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) Edge(org.kie.workbench.common.stunner.core.graph.Edge) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)

Aggregations

CanvasCommandResultBuilder (org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder)3 Objects (java.util.Objects)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 DoubleSummaryStatistics (java.util.DoubleSummaryStatistics)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Dependent (javax.enterprise.context.Dependent)1 Event (javax.enterprise.event.Event)1 Observes (javax.enterprise.event.Observes)1 Inject (javax.inject.Inject)1 PortablePreconditions.checkNotNull (org.kie.soup.commons.validation.PortablePreconditions.checkNotNull)1 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1