Search in sources :

Example 1 with Counter

use of org.kie.workbench.common.stunner.core.util.Counter in project kie-wb-common by kiegroup.

the class AbstractEdgeBuilder method buildControlPoints.

private void buildControlPoints(BuilderContext context, T edge, GraphCommandFactory commandFactory) {
    if (dockers.size() > 2) {
        Counter indexCounter = new Counter(0);
        ControlPoint[] controlPoints = dockers.subList(1, dockers.size() - 1).stream().sequential().map(docker -> (docker.length == 2 ? new Point2D(docker[0], docker[1]) : null)).filter(Objects::nonNull).map(point -> new ControlPointImpl(point, indexCounter.increment())).toArray(ControlPoint[]::new);
        CommandResult<RuleViolation> addControlPointsResult = context.execute(commandFactory.addControlPoint(edge, controlPoints));
        if (hasErrors(addControlPointsResult)) {
            throw new RuntimeException("Error building BPMN graph. Command 'AddControlPointCommand' execution failed." + addControlPointsResult);
        }
    }
}
Also used : AddControlPointCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddControlPointCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) BPMNDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNDefinition) Edge(org.kie.workbench.common.stunner.core.graph.Edge) MutableIndex(org.kie.workbench.common.stunner.core.graph.processing.index.MutableIndex) Collectors(java.util.stream.Collectors) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Objects(java.util.Objects) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) CommandUtils(org.kie.workbench.common.stunner.core.command.util.CommandUtils) Bpmn2OryxManager(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.Bpmn2OryxManager) Counter(org.kie.workbench.common.stunner.core.util.Counter) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SetConnectionTargetNodeCommand) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Node(org.kie.workbench.common.stunner.core.graph.Node) Counter(org.kie.workbench.common.stunner.core.util.Counter) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Objects(java.util.Objects) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 2 with Counter

use of org.kie.workbench.common.stunner.core.util.Counter 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)

Example 3 with Counter

use of org.kie.workbench.common.stunner.core.util.Counter in project kie-wb-common by kiegroup.

the class PasteSelectionSessionCommand method execute.

@Override
public <V> void execute(final Callback<V> callback) {
    checkNotNull("callback", callback);
    if (clipboardControl.hasElements()) {
        final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> nodesCommandBuilder = createCommandBuilder();
        Counter processedNodesCountdown = new Counter((int) clipboardControl.getElements().stream().filter(element -> element instanceof Node).count());
        // first processing nodes
        nodesCommandBuilder.addCommands(clipboardControl.getElements().stream().filter(element -> element instanceof Node).filter(Objects::nonNull).map(node -> (Node<View<?>, Edge>) node).map(node -> {
            String newParentUUID = getNewParentUUID(node);
            return canvasCommandFactory.cloneNode(node, newParentUUID, calculateNewLocation(node, newParentUUID), cloneNodeCallback(node, processedNodesCountdown));
        }).collect(Collectors.toList()));
        if (Objects.equals(nodesCommandBuilder.size(), 0)) {
            return;
        }
        // Execute the command for cloning nodes
        CommandResult<CanvasViolation> finalResult;
        if (wasNodesDeletedFromGraph()) {
            // in case of a cut command the source elements were deleted from graph, so first undo the command to take node back into canvas
            clipboardControl.getRollbackCommands().forEach(command -> command.undo(getCanvasHandler()));
            finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown);
            // after the clone execution than delete source elements again
            clipboardControl.getRollbackCommands().forEach(command -> command.execute(getCanvasHandler()));
        } else {
            // if elements are still on the graph, in case copy command, just execute the clone commands
            finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown);
        }
        if (CommandUtils.isError(finalResult)) {
            LOGGER.severe("Error pasting selection." + getCanvasViolations(finalResult));
            return;
        }
        fireSelectedElementEvent();
        callback.onSuccess();
        clear();
        // copy the cloned node to the clipboard to allow pasting several times
        copySelectionSessionCommand.execute();
    }
}
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) Counter(org.kie.workbench.common.stunner.core.util.Counter) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Node(org.kie.workbench.common.stunner.core.graph.Node) Objects(java.util.Objects) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)

Aggregations

Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)3 CommandUtils (org.kie.workbench.common.stunner.core.command.util.CommandUtils)3 Edge (org.kie.workbench.common.stunner.core.graph.Edge)3 Node (org.kie.workbench.common.stunner.core.graph.Node)3 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)3 View (org.kie.workbench.common.stunner.core.graph.content.view.View)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 DoubleSummaryStatistics (java.util.DoubleSummaryStatistics)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Consumer (java.util.function.Consumer)2 Logger (java.util.logging.Logger)2 Stream (java.util.stream.Stream)2 StreamSupport (java.util.stream.StreamSupport)2 Dependent (javax.enterprise.context.Dependent)2 Event (javax.enterprise.event.Event)2