Search in sources :

Example 6 with CanvasClearSelectionEvent

use of org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent 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)

Aggregations

CanvasClearSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent)6 Test (org.junit.Test)5 Element (org.kie.workbench.common.stunner.core.graph.Element)3 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)2 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 Dependent (javax.enterprise.context.Dependent)1 Event (javax.enterprise.event.Event)1 Inject (javax.inject.Inject)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 PortablePreconditions.checkNotNull (org.kie.soup.commons.validation.PortablePreconditions.checkNotNull)1 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)1