| /** |
| * Copyright (c) 2011, 2014 - 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.application.handler; |
| |
| import org.eclipse.core.commands.Command; |
| import org.eclipse.core.commands.ParameterizedCommand; |
| import org.eclipse.e4.core.contexts.Active; |
| import org.eclipse.e4.core.contexts.ContextInjectionFactory; |
| import org.eclipse.e4.core.contexts.IEclipseContext; |
| import org.eclipse.e4.core.di.annotations.CanExecute; |
| import org.eclipse.e4.ui.model.application.ui.MContext; |
| import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.di.EnabledState; |
| |
| /** |
| * The Class AbstractHandler. |
| */ |
| public class AbstractHandler { |
| |
| /** |
| * Instantiates a new abstract handler. |
| */ |
| public AbstractHandler() { |
| super(); |
| } |
| |
| /** |
| * Creates the callback context. |
| * |
| * @param context |
| * the context |
| * @param command |
| * the command |
| * @return the i eclipse context |
| */ |
| protected IEclipseContext createCallbackContext(MContext context, |
| Command command) { |
| final IEclipseContext pmContext = context.getContext().createChild(); |
| pmContext.set("commandId", command.getId()); |
| return pmContext; |
| } |
| |
| /** |
| * Can execute. |
| * |
| * @param context |
| * the context |
| * @param part |
| * the part |
| * @param command |
| * the command |
| * @return true, if successful |
| */ |
| @CanExecute |
| public boolean canExecute(@Active MContext context, @Active MPart part, |
| ParameterizedCommand command) { |
| final IEclipseContext pmContext = createCallbackContext(context, |
| command.getCommand()); |
| boolean result = (Boolean) ContextInjectionFactory.invoke(part.getObject(), EnabledState.class, |
| pmContext, Boolean.TRUE); |
| return result; |
| } |
| |
| } |