1 8 package de.loskutov.bco.ui.actions; 9 10 import java.util.ArrayList ; 11 import java.util.Iterator ; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.jdt.core.IJavaElement; 15 import org.eclipse.jdt.core.IMember; 16 import org.eclipse.jface.action.IAction; 17 import org.eclipse.ui.IObjectActionDelegate; 18 19 import de.loskutov.bco.BytecodeOutlinePlugin; 20 21 24 public class CompareMemberBytecodeAction extends BytecodeAction implements IObjectActionDelegate { 25 26 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 41 protected IJavaElement[] getSelectedResources() { 42 ArrayList resources = null; 43 if (!selection.isEmpty()) { 44 resources = new ArrayList (); 45 for (Iterator elements = selection.iterator(); elements.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.toArray(new IJavaElement[resources 63 .size()]); 64 } 65 66 return new IJavaElement[0]; 67 } 68 } | Popular Tags |