01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.ui.examples.contributions.view;
11:
12: import java.util.Iterator;
13:
14: import org.eclipse.core.commands.AbstractHandler;
15: import org.eclipse.core.commands.ExecutionEvent;
16: import org.eclipse.core.commands.ExecutionException;
17: import org.eclipse.jface.viewers.ISelection;
18: import org.eclipse.jface.viewers.IStructuredSelection;
19: import org.eclipse.ui.examples.contributions.model.Person;
20: import org.eclipse.ui.handlers.HandlerUtil;
21:
22: /**
23: * Swap 2 elements around in the the view.
24: *
25: * @since 3.3
26: */
27: public class SwapInfoHandler extends AbstractHandler {
28:
29: /*
30: * (non-Javadoc)
31: *
32: * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
33: */
34: public Object execute(ExecutionEvent event)
35: throws ExecutionException {
36: InfoView view = (InfoView) HandlerUtil
37: .getActivePartChecked(event);
38: ISelection sel = HandlerUtil.getCurrentSelection(event);
39: if (sel instanceof IStructuredSelection) {
40: IStructuredSelection selection = (IStructuredSelection) sel;
41: if (selection.size() != 2) {
42: return null;
43: }
44: Iterator i = selection.iterator();
45: Person p1 = (Person) i.next();
46: Person p2 = (Person) i.next();
47: view.swap(p1, p2);
48: }
49: return null;
50: }
51:
52: }
|