| /*=============================================================================# |
| # Copyright (c) 2007, 2017 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.nico.ui.actions; |
| |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.swt.widgets.Display; |
| |
| import org.eclipse.statet.nico.core.runtime.ToolController; |
| import org.eclipse.statet.nico.core.runtime.ToolProcess; |
| import org.eclipse.statet.nico.core.util.IToolProvider; |
| |
| |
| /** |
| * Handler to cancel tool tasks. |
| */ |
| public class CancelHandler extends ToolRetargetableHandler { |
| |
| |
| public static final String MENU_ID = "org.eclipse.statet.nico.menus.Cancel"; //$NON-NLS-1$ |
| |
| public static final String PAR_OPTIONS = "options"; //$NON-NLS-1$ |
| |
| |
| private final int fOptions; |
| |
| |
| public CancelHandler(final IToolProvider toolProvider) { |
| super(toolProvider, null); |
| fOptions = 0; |
| init(); |
| } |
| |
| public CancelHandler(final IToolProvider toolProvider, final int options) { |
| super(toolProvider, null); |
| fOptions = options; |
| init(); |
| } |
| |
| |
| @Override |
| protected Object doExecute(final ExecutionEvent event) { |
| final String optionsParameter = event.getParameter(PAR_OPTIONS); |
| int options = fOptions; |
| if (optionsParameter != null) { |
| try { |
| options = Integer.decode(optionsParameter); |
| } |
| catch (final NumberFormatException e) { |
| } |
| } |
| |
| final ToolProcess tool = getCheckedTool(); |
| final ToolController controller = (tool != null) ? tool.getController() : null; |
| if (controller == null) { |
| return null; |
| } |
| |
| if (!controller.cancelTask(options)) { |
| Display.getCurrent().beep(); |
| } |
| |
| return null; |
| } |
| |
| } |