Search in sources :

Example 26 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.

the class GenerateSelectedFormsSessionCommand method call.

private void call(final FormGenerationService service) {
    final AbstractCanvasHandler canvasHandler = getCanvasHandler();
    final Index index = canvasHandler.getGraphIndex();
    final String[] selectedItems = getSelectedItems().stream().map(index::get).filter(acceptor).map(Element::getUUID).toArray(String[]::new);
    if (selectedItems.length > 0) {
        service.generateSelectedForms(getCanvasHandler().getDiagram(), selectedItems);
    } else {
        formGenerationNotifier.showNotification(translationService.getValue(FormsClientConstants.FormsNoItemsSelectedForGeneration));
    }
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index)

Example 27 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler 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 28 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.

the class DrawCanvasCommand method execute.

@Override
@SuppressWarnings("unchecked")
public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) {
    final Graph graph = context.getGraphIndex().getGraph();
    final String shapeSetId = getShapeSetId(context);
    final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward();
    // Aggregate all nodes in the parent-child-dock hierarchy.
    childrenTraverseProcessor.traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() {

        @Override
        public void startNodeTraversal(final Node<View, Edge> node) {
            super.startNodeTraversal(node);
            if (!isCanvasRoot().test(context, node.getUUID())) {
                addNode(node);
            }
        }

        @Override
        public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) {
            super.startNodeTraversal(parents, node);
            final Optional<Edge> dockEdge = node.getInEdges().stream().filter(e -> e.getContent() instanceof Dock).findAny();
            final Node parent = dockEdge.map(Edge::getSourceNode).orElseGet(() -> parents.get(parents.size() - 1));
            if (dockEdge.isPresent()) {
                addDockedNode(parent, node);
            } else if (isCanvasRoot().test(context, parent.getUUID())) {
                addNode(node);
            } else {
                addChildNode(parent, node);
            }
            return true;
        }

        private void addNode(final Node node) {
            commandBuilder.addCommand(new AddCanvasNodeCommand(node, shapeSetId));
        }

        private void addChildNode(final Node<View, Edge> parent, final Node<View, Edge> node) {
            commandBuilder.addCommand(new AddCanvasChildNodeCommand(parent, node, shapeSetId));
        }

        private void addDockedNode(final Node<View, Edge> parent, final Node<View, Edge> node) {
            commandBuilder.addCommand(new AddCanvasDockedNodeCommand(parent, node, shapeSetId));
        }
    });
    // Aggregate all connectors.
    viewTraverseProcessor.traverse(graph, new AbstractContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() {

        @Override
        public void startEdgeTraversal(final Edge<View<?>, Node> edge) {
            super.startEdgeTraversal(edge);
            commandBuilder.addCommand(new AddCanvasConnectorCommand(edge, shapeSetId));
        }
    });
    return commandBuilder.build().execute(context);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Optional(java.util.Optional) Node(org.kie.workbench.common.stunner.core.graph.Node) 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 29 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.

the class AbstractElementBuilderControl method getElementCommands.

@SuppressWarnings("unchecked")
public void getElementCommands(final Element element, final Node<View<?>, Edge> parent, final double x, final double y, final CommandsCallback commandsCallback) {
    Command<AbstractCanvasHandler, CanvasViolation> command = null;
    if (element instanceof Node) {
        if (null != parent) {
            command = canvasCommandFactory.addChildNode(parent, (Node) element, getShapeSetId());
        } else {
            command = canvasCommandFactory.addNode((Node) element, getShapeSetId());
        }
    } else if (element instanceof Edge && null != parent) {
        command = canvasCommandFactory.addConnector(parent, (Edge) element, MagnetConnection.Builder.forElement(parent), getShapeSetId());
    } else {
        throw new RuntimeException("Unrecognized element type for " + element);
    }
    // Execute both add element and move commands in batch, so undo will be done in batch as well.
    Command<AbstractCanvasHandler, CanvasViolation> moveCanvasElementCommand = canvasCommandFactory.updatePosition((Node<View<?>, Edge>) element, new Point2D(x, y));
    final List<Command<AbstractCanvasHandler, CanvasViolation>> commandList = new LinkedList<Command<AbstractCanvasHandler, CanvasViolation>>();
    commandList.add(command);
    commandList.add(moveCanvasElementCommand);
    commandsCallback.onComplete(element.getUUID(), commandList);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) 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) Node(org.kie.workbench.common.stunner.core.graph.Node) Edge(org.kie.workbench.common.stunner.core.graph.Edge) View(org.kie.workbench.common.stunner.core.graph.content.view.View) LinkedList(java.util.LinkedList)

Example 30 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.

the class RequestCommandManager method complete.

/**
 * Completes the current client request. It registers the composite command into the
 * session's registry.
 */
private void complete() {
    if (isRequestStarted()) {
        final boolean hasCommands = !commands.isEmpty();
        if (hasCommands && roolback) {
            LOGGER.log(Level.FINEST, "Performing rollback for commands in current requrest.");
            final AbstractCanvasHandler canvasHandler = getCurrentSession().getCanvasHandler();
            commands.forEach(c -> c.undo(canvasHandler));
        } else if (hasCommands) {
            // If any commands have been aggregated, let's composite them and add into the registry.
            LOGGER.log(Level.FINEST, "Adding commands for current request into registry [size=" + commands.size() + "]");
            getRegistry().register(new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward().addCommands(commands.stream().collect(Collectors.toList())).build());
        }
        clear();
        LOGGER.log(Level.FINEST, "Current client request completed.");
    } else {
        LOGGER.log(Level.WARNING, "Current client request has not been started.");
    }
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)

Aggregations

AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)60 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)37 Test (org.junit.Test)30 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)15 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)10 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Command (org.kie.workbench.common.stunner.core.command.Command)9 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)9 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)9 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)8 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)7 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)6 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)6 Collectors (java.util.stream.Collectors)5 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)5 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)5 CanvasCommandFactory (org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory)5