Search in sources :

Example 16 with ClientRuntimeError

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);
            }
        });
    }
}
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 17 with ClientRuntimeError

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()));
    }
}
Also used : Event(javax.enterprise.event.Event) CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Session(org.kie.workbench.common.stunner.core.client.session.Session) CanvasCommandFactory(org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory) Collection(java.util.Collection) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasElementsClearEvent(org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasElementsClearEvent) Logger(java.util.logging.Logger) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Collectors(java.util.stream.Collectors) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) Level(java.util.logging.Level) Inject(javax.inject.Inject) KeysMatcher(org.kie.workbench.common.stunner.core.client.canvas.controls.keyboard.KeysMatcher) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Dependent(javax.enterprise.context.Dependent) CommandUtils(org.kie.workbench.common.stunner.core.command.util.CommandUtils) Element(org.kie.workbench.common.stunner.core.graph.Element) KeyboardEvent(org.kie.workbench.common.stunner.core.client.event.keyboard.KeyboardEvent) ClientFullSession(org.kie.workbench.common.stunner.core.client.session.ClientFullSession) SelectionControl(org.kie.workbench.common.stunner.core.client.canvas.controls.select.SelectionControl) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Element(org.kie.workbench.common.stunner.core.graph.Element) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)

Example 18 with ClientRuntimeError

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));
}
Also used : OnSessionErrorEvent(org.kie.workbench.common.stunner.core.client.session.event.OnSessionErrorEvent) SessionOpenedEvent(org.kie.workbench.common.stunner.core.client.session.event.SessionOpenedEvent) SessionResumedEvent(org.kie.workbench.common.stunner.core.client.session.event.SessionResumedEvent) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) SessionDestroyedEvent(org.kie.workbench.common.stunner.core.client.session.event.SessionDestroyedEvent) SessionPausedEvent(org.kie.workbench.common.stunner.core.client.session.event.SessionPausedEvent) Test(org.junit.Test)

Example 19 with ClientRuntimeError

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;
}
Also used : DiagramRepresentation(org.kie.workbench.common.stunner.core.lookup.diagram.DiagramRepresentation) LookupManager(org.kie.workbench.common.stunner.core.lookup.LookupManager) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) List(java.util.List) LinkedList(java.util.LinkedList) DiagramLookupRequest(org.kie.workbench.common.stunner.core.lookup.diagram.DiagramLookupRequest)

Aggregations

ClientRuntimeError (org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)19 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)4 Test (org.junit.Test)3 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)3 OnSessionErrorEvent (org.kie.workbench.common.stunner.core.client.session.event.OnSessionErrorEvent)3 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)3 PathPlaceRequest (org.uberfire.mvp.impl.PathPlaceRequest)3 Collection (java.util.Collection)2 Level (java.util.logging.Level)2 Logger (java.util.logging.Logger)2 Event (javax.enterprise.event.Event)2 Inject (javax.inject.Inject)2 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)2 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)2 ServiceCallback (org.kie.workbench.common.stunner.core.client.service.ServiceCallback)2 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)2 LookupManager (org.kie.workbench.common.stunner.core.lookup.LookupManager)2 DiagramLookupRequest (org.kie.workbench.common.stunner.core.lookup.diagram.DiagramLookupRequest)2 DiagramRepresentation (org.kie.workbench.common.stunner.core.lookup.diagram.DiagramRepresentation)2 Path (org.uberfire.backend.vfs.Path)2