gov.redhawk.sca.internal.ui.handlers.StopResourceOpHandler.java Source code

Java tutorial

Introduction

Here is the source code for gov.redhawk.sca.internal.ui.handlers.StopResourceOpHandler.java

Source

/**
 * This file is protected by Copyright. 
 * Please refer to the COPYRIGHT file distributed with this source distribution.
 * 
 * This file is part of REDHAWK IDE.
 * 
 * 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.
 *
 */
package gov.redhawk.sca.internal.ui.handlers;

import gov.redhawk.sca.ui.actions.StopAction;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;

// TODO: Auto-generated Javadoc
/**
 * The Class StopResourceOpHandler.
 */
public class StopResourceOpHandler extends AbstractHandler {

    private final StopAction action = new StopAction();

    /**
     * {@inheritDoc}
     */

    @Override
    public Object execute(final ExecutionEvent event) throws ExecutionException {
        ISelection selection = HandlerUtil.getActiveMenuSelection(event);
        if (selection == null) {
            selection = HandlerUtil.getCurrentSelection(event);
        }
        if (selection instanceof IStructuredSelection) {
            final IStructuredSelection ss = (IStructuredSelection) selection;
            for (final Object obj : ss.toArray()) {
                stop(obj);
            }
        } else {
            final IEditorPart editor = HandlerUtil.getActiveEditor(event);
            stop(editor);
        }
        // TODO Auto-generated method stub
        return null;
    }

    private void stop(final Object obj) {
        this.action.setContext(obj);
        this.action.run();
    }

    /**
     * {@inheritDoc}
     */

    @Override
    public void setEnabled(final Object evaluationContext) {
        // TODO Auto-generated method stub
        super.setEnabled(evaluationContext);
    }

}