| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| */ |
| package org.eclipse.osbp.vaaclipse.addons.keybinding; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.core.commands.Command; |
| import org.eclipse.core.commands.ParameterizedCommand; |
| import org.eclipse.e4.core.commands.ECommandService; |
| import org.eclipse.e4.core.commands.EHandlerService; |
| import org.eclipse.e4.ui.model.application.commands.MCommand; |
| import org.eclipse.e4.ui.model.application.commands.MCommandParameter; |
| import org.eclipse.e4.ui.model.application.commands.MKeyBinding; |
| import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
| import org.eclipse.osbp.runtime.common.keystroke.KeyStrokeCallback; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.IE4Constants; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| import com.vaadin.ui.Component; |
| |
| /** |
| * The Class CommandKeyStrokeCallback. |
| */ |
| @SuppressWarnings("restriction") |
| public class CommandKeyStrokeCallback implements KeyStrokeCallback { |
| |
| /** The Constant LOGGER. */ |
| private static final Logger LOGGER = LoggerFactory |
| .getLogger(CommandKeyStrokeCallback.class); |
| |
| /** The command service. */ |
| private ECommandService commandService; |
| |
| /** The handler service. */ |
| private EHandlerService handlerService; |
| |
| /** The m key binding. */ |
| private MKeyBinding mKeyBinding; |
| |
| /** The m part. */ |
| @SuppressWarnings("unused") |
| private MPart mPart; |
| |
| /** |
| * Instantiates a new command key stroke callback. |
| * |
| * @param mKeyBinding |
| * the m key binding |
| * @param mPart |
| * the m part |
| * @param commandService |
| * the command service |
| * @param handlerService |
| * the handler service |
| */ |
| public CommandKeyStrokeCallback(MKeyBinding mKeyBinding, MPart mPart, |
| ECommandService commandService, EHandlerService handlerService) { |
| super(); |
| this.mKeyBinding = mKeyBinding; |
| this.mPart = mPart; |
| this.commandService = commandService; |
| this.handlerService = handlerService; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.common.keystroke.KeyStrokeCallback#callback(java.lang.Object, java.lang.Object) |
| */ |
| @Override |
| public void callback(Object source, Object target) { |
| Component sourceComponent = (Component) source; |
| Component targetComponent = (Component) target; |
| |
| MCommand mCommand = mKeyBinding.getCommand(); |
| if (mCommand != null) { |
| Command command = commandService |
| .getCommand(mCommand.getElementId()); |
| if (command != null) { |
| Map<String, Object> parameters = new HashMap<String, Object>(); |
| for(MCommandParameter param : mCommand.getParameters()) { |
| if(param.getName().equals(IE4Constants.KEYSTROKE_SOURCE)) { |
| parameters.put(IE4Constants.KEYSTROKE_SOURCE, sourceComponent |
| .getId() != null ? sourceComponent.getId() : ""); |
| } else if(param.getName().equals(IE4Constants.KEYSTROKE_TARGET)) { |
| parameters.put(IE4Constants.KEYSTROKE_TARGET, targetComponent |
| .getId() != null ? targetComponent.getId() : ""); |
| } |
| } |
| |
| ParameterizedCommand paramCommand = ParameterizedCommand |
| .generateCommand(command, parameters); |
| if (paramCommand != null) { |
| handlerService.executeHandler(paramCommand); |
| } else { |
| LOGGER.error("Can not execute command " + command.getId()); |
| } |
| } |
| } |
| } |
| } |