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