blob: 08f41d026ab2536337f9cc3fa032b72071e42ecb [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.ui.examples.contributions.view;
import java.util.Iterator;
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.examples.contributions.model.Person;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* Swap 2 elements around in the the view.
*
* @since 3.3
*/
public class SwapInfoHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
InfoView view = (InfoView) HandlerUtil.getActivePartChecked(event);
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
if (selection.size() != 2) {
return null;
}
Iterator i = selection.iterator();
Person p1 = (Person) i.next();
Person p2 = (Person) i.next();
view.swap(p1, p2);
}
return null;
}
}