use of org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError 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.client.service.ClientRuntimeError in project kie-wb-common by kiegroup.
the class DeleteSelectionSessionCommand method execute.
@Override
@SuppressWarnings("unchecked")
public <V> void execute(final Callback<V> callback) {
checkNotNull("callback", callback);
if (null != getSession().getSelectionControl()) {
final AbstractCanvasHandler canvasHandler = (AbstractCanvasHandler) getSession().getCanvasHandler();
final SelectionControl<AbstractCanvasHandler, Element> selectionControl = getSession().getSelectionControl();
final Collection<String> selectedItems = selectionControl.getSelectedItems();
if (selectedItems != null && !selectedItems.isEmpty()) {
// Execute the commands.
final CommandResult<CanvasViolation> result = sessionCommandManager.execute(canvasHandler, canvasCommandFactory.delete(selectedItems.stream().map(uuid -> canvasHandler.getGraphIndex().get(uuid)).collect(Collectors.toList())));
// Check the results.
if (!CommandUtils.isError(result)) {
callback.onSuccess();
} else {
callback.onError((V) new ClientRuntimeError("Error deleing elements [message=" + result.toString() + "]"));
}
} else {
callback.onError((V) new ClientRuntimeError("Cannot delete element, no element selected on canvas"));
}
selectionControl.clearSelection();
clearSelectionEvent.fire(new CanvasClearSelectionEvent(getCanvasHandler()));
}
}
use of org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError in project kie-wb-common by kiegroup.
the class ClientSessionManagerImplTest method testHandleClientError.
@Test
public void testHandleClientError() {
tested.current = session;
ClientRuntimeError error = mock(ClientRuntimeError.class);
tested.handleClientError(error);
verify(sessionOpenedEventMock, times(0)).fire(any(SessionOpenedEvent.class));
verify(sessionPausedEventMock, times(0)).fire(any(SessionPausedEvent.class));
verify(sessionResumedEventMock, times(0)).fire(any(SessionResumedEvent.class));
verify(sessionErrorEventMock, times(1)).fire(any(OnSessionErrorEvent.class));
verify(sessionDestroyedEventMock, times(0)).fire(any(SessionDestroyedEvent.class));
}
use of org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError in project kie-wb-common by kiegroup.
the class DiagramsNavigatorImpl method show.
public DiagramsNavigatorImpl show() {
// Notify some processing starts.
fireProcessingStarted();
clear();
final DiagramLookupRequest request = new DiagramLookupRequest.Builder().build();
clientDiagramServices.lookup(request, new ServiceCallback<LookupManager.LookupResponse<DiagramRepresentation>>() {
@Override
public void onSuccess(final LookupManager.LookupResponse<DiagramRepresentation> response) {
final List<DiagramRepresentation> items = response.getResults();
if (null != items && !items.isEmpty()) {
for (final DiagramRepresentation diagram : items) {
addEntry(diagram);
}
}
// Notify some processing ends.
fireProcessingCompleted();
}
@Override
public void onError(final ClientRuntimeError error) {
showError(error);
}
});
return this;
}
Aggregations