blob: 814ec0ff72a04e53aaf0163b194dafd9cf7758de [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011-2012 EclipseSource Muenchen GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eugen Neufeld - initial API and implementation
*
*******************************************************************************/
package org.eclipse.emf.ecp.ui.commands;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.ecp.core.util.ECPCheckoutSource;
import org.eclipse.emf.ecp.spi.ui.util.ECPHandlerHelper;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* This Handler uses the {@link ECPHandlerHelper#checkout(List, org.eclipse.swt.widgets.Shell)} method
* to checkout a project.
*
* @author Eugen Neufeld
*/
public class CheckoutHandler extends AbstractHandler {
/** {@inheritDoc} */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getActiveMenuSelection(event);
final IStructuredSelection ssel = (IStructuredSelection) selection;
final List<ECPCheckoutSource> checkouts = new ArrayList<ECPCheckoutSource>();
for (final Iterator<?> it = ssel.iterator(); it.hasNext();) {
final Object element = it.next();
if (element instanceof ECPCheckoutSource) {
final ECPCheckoutSource checkoutSource = (ECPCheckoutSource) element;
checkouts.add(checkoutSource);
}
}
ECPHandlerHelper.checkout(checkouts, HandlerUtil.getActiveShell(event));
return null;
}
}