Search in sources :

Example 6 with CommandResult

use of org.kie.workbench.common.stunner.core.command.CommandResult 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 7 with CommandResult

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

the class FormsCanvasSessionHandler method executeUpdateProperty.

@SuppressWarnings("unchecked")
public boolean executeUpdateProperty(final Element<? extends Definition<?>> element, final String fieldName, final Object value) {
    final Object definition = element.getContent().getDefinition();
    final HasProperties hasProperties = (HasProperties) DataBinder.forModel(definition).getModel();
    final String propertyId = getModifiedPropertyId(hasProperties, fieldName);
    canvasListener.startProcessing();
    final CommandResult result = featuresSessionProvider.getCommandManager(session).execute(getCanvasHandler(), commandFactory.updatePropertyValue(element, propertyId, value));
    canvasListener.endProcessing();
    return !CommandUtils.isError(result);
}
Also used : HasProperties(org.jboss.errai.databinding.client.HasProperties) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult)

Example 8 with CommandResult

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

the class CloneCanvasNodeCommand method execute.

@Override
public CommandResult<CanvasViolation> execute(AbstractCanvasHandler context) {
    commands = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().reverse().build();
    // first add the candidate clone
    commands.addCommand(createAddCanvasChildNodeCommand(getParent(), getCandidate(), getShapeSetId()));
    // process clone children nodes
    if (GraphUtils.hasChildren(getCandidate())) {
        Graph graph = context.getGraphIndex().getGraph();
        List<Edge> clonedEdges = new ArrayList<>();
        childrenTraverseProcessor.get().setRootUUID(getCandidate().getUUID()).traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {

            @Override
            public boolean startNodeTraversal(List<Node<View, Edge>> parents, Node<View, Edge> node) {
                commands.addCommand(createCloneCanvasNodeCommand(getCandidate(), node, getShapeSetId()));
                clonedEdges.addAll(node.getOutEdges());
                // just traverse the first level children of the root node
                return false;
            }
        });
        // process children edges -> connectors and dock
        clonedEdges.stream().filter(edge -> edge.getContent() instanceof Dock).forEach(edge -> commands.addCommand(new CanvasDockNodeCommand(edge.getSourceNode(), edge.getTargetNode())));
        clonedEdges.stream().filter(edge -> edge.getContent() instanceof ViewConnector).forEach(edge -> commands.addCommand(new AddCanvasConnectorCommand((Edge) edge, getShapeSetId())));
    }
    // process clone docked nodes on the root
    if (GraphUtils.hasDockedNodes(getCandidate())) {
        List<Edge> edges = getCandidate().getOutEdges();
        edges.stream().filter(edge -> edge.getContent() instanceof Dock).map(edge -> edge.getTargetNode()).forEach(targetNode -> {
            commands.addCommand(new AddCanvasChildNodeCommand(getParent(), targetNode, getShapeSetId()));
            commands.addCommand(new CanvasDockNodeCommand(getCandidate(), targetNode));
        });
    }
    return commands.execute(context);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) ChildrenTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ChildrenTraverseProcessor) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) ArrayList(java.util.ArrayList) GraphUtils(org.kie.workbench.common.stunner.core.graph.util.GraphUtils) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) AbstractChildrenTraverseCallback(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.AbstractChildrenTraverseCallback) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Node(org.kie.workbench.common.stunner.core.graph.Node) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) View(org.kie.workbench.common.stunner.core.graph.content.view.View) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 9 with CommandResult

use of org.kie.workbench.common.stunner.core.command.CommandResult 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);
        final ElementBuilderControlImpl ebc = getElementBuilderControl();
        final Node<View<?>, Edge> parent = ebc.getParent(x, y);
        final Point2D childCoordinates = ebc.getChildCoordinates(parent, x, y);
        final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
        ebc.getElementCommands(node, parent, 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);
                    // 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 10 with CommandResult

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

the class CreateNodeAction method onMouseClick.

@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
    // Obtain the connector and source node instances for proxying.
    final Element<View<?>> element = (Element<View<?>>) getElement(canvasHandler, uuid);
    final Node<View<?>, Edge> sourceNode = element.asNode();
    final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager.newElement(UUID.uuid(), edgeId).asEdge();
    final Node<View<?>, Edge> targetNode = (Node<View<?>, Edge>) clientFactoryManager.newElement(UUID.uuid(), nodeId).asNode();
    final DeferredCompositeCommand.Builder builder = new DeferredCompositeCommand.Builder().deferCommand(() -> addNode(canvasHandler, sourceNode, targetNode)).deferCommand(() -> updateNodeLocation(canvasHandler, sourceNode, targetNode)).deferCommand(() -> addEdge(canvasHandler, sourceNode, connector)).deferCommand(() -> setEdgeTarget(canvasHandler, connector, targetNode));
    final CommandResult result = sessionCommandManager.execute(canvasHandler, builder.build());
    if (!CommandUtils.isError(result)) {
        fireElementSelectedEvent(selectionEvent, canvasHandler, targetNode.getUUID());
    }
    return this;
}
Also used : DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult)

Aggregations

CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)18 Command (org.kie.workbench.common.stunner.core.command.Command)11 Test (org.junit.Test)7 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)7 Edge (org.kie.workbench.common.stunner.core.graph.Edge)7 Node (org.kie.workbench.common.stunner.core.graph.Node)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)7 Collectors (java.util.stream.Collectors)6 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)6 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)5 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)5 Objects (java.util.Objects)4 Event (javax.enterprise.event.Event)4 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)4 CanvasCommandFactory (org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory)4 CanvasCommandResultBuilder (org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder)4 SessionCommandManager (org.kie.workbench.common.stunner.core.client.command.SessionCommandManager)4 CommandUtils (org.kie.workbench.common.stunner.core.command.util.CommandUtils)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 ArrayList (java.util.ArrayList)3