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));
}
}
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);
}
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);
}
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);
}
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.");
}
}
Aggregations