01: /*****************************************************************************************
02: * Copyright (c) 2004 Andrei Loskutov. All rights reserved. This program and the
03: * accompanying materials are made available under the terms of the BSD License which
04: * accompanies this distribution, and is available at
05: * http://www.opensource.org/licenses/bsd-license.php Contributor: Andrei Loskutov -
06: * initial API and implementation
07: ****************************************************************************************/package de.loskutov.bco.ui.actions;
08:
09: import java.util.ArrayList;
10: import java.util.Iterator;
11:
12: import org.eclipse.core.runtime.IAdaptable;
13: import org.eclipse.jdt.core.IJavaElement;
14: import org.eclipse.jdt.core.IMember;
15: import org.eclipse.jface.action.IAction;
16: import org.eclipse.ui.IObjectActionDelegate;
17:
18: import de.loskutov.bco.BytecodeOutlinePlugin;
19:
20: /**
21: * @author Andrei
22: */
23: public class CompareMemberBytecodeAction extends BytecodeAction
24: implements IObjectActionDelegate {
25:
26: /**
27: * (non-Javadoc)
28: * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
29: */
30: public void run(IAction action) {
31: IJavaElement[] resources = getSelectedResources();
32: try {
33: exec(resources[0], resources[1]);
34: } catch (Exception e) {
35: BytecodeOutlinePlugin.error("Failed to run Compare: "
36: + e.getMessage(), e);
37: }
38: }
39:
40: protected IJavaElement[] getSelectedResources() {
41: ArrayList resources = null;
42: if (!selection.isEmpty()) {
43: resources = new ArrayList();
44: for (Iterator elements = selection.iterator(); elements
45: .hasNext();) {
46: Object next = elements.next();
47: if (next instanceof IMember) {
48: resources.add(next);
49: continue;
50: } else if (next instanceof IAdaptable) {
51: IAdaptable a = (IAdaptable) next;
52: Object adapter = a.getAdapter(IMember.class);
53: if (adapter instanceof IMember) {
54: resources.add(adapter);
55: continue;
56: }
57: }
58: }
59: }
60:
61: if (resources != null && !resources.isEmpty()) {
62: return (IJavaElement[]) resources
63: .toArray(new IJavaElement[resources.size()]);
64: }
65:
66: return new IJavaElement[0];
67: }
68: }
|