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