1 12 package org.eclipse.jdt.internal.ui.callhierarchy; 13 14 import java.util.Iterator ; 15 16 import org.eclipse.jface.viewers.ISelection; 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 19 import org.eclipse.ui.IWorkbenchSite; 20 21 import org.eclipse.jdt.ui.actions.SelectionDispatchAction; 22 23 import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation; 24 import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper; 25 26 class OpenLocationAction extends SelectionDispatchAction { 27 private CallHierarchyViewPart fPart; 28 29 public OpenLocationAction(CallHierarchyViewPart part, IWorkbenchSite site) { 30 super(site); 31 fPart= part; 32 setText(CallHierarchyMessages.OpenLocationAction_label); 33 setToolTipText(CallHierarchyMessages.OpenLocationAction_tooltip); 34 } 35 36 private boolean checkEnabled(IStructuredSelection selection) { 37 if (selection.isEmpty()) { 38 return false; 39 } 40 41 for (Iterator iter = selection.iterator(); iter.hasNext();) { 42 Object element = iter.next(); 43 44 if (element instanceof MethodWrapper) { 45 continue; 46 } else if (element instanceof CallLocation) { 47 continue; 48 } 49 50 return false; 51 } 52 53 return true; 54 } 55 56 59 public ISelection getSelection() { 60 return fPart.getSelection(); 61 } 62 63 66 public void run(IStructuredSelection selection) { 67 if (!checkEnabled(selection)) { 68 return; 69 } 70 for (Iterator iter= selection.iterator(); iter.hasNext();) { 71 boolean noError= CallHierarchyUI.openInEditor(iter.next(), getShell(), getDialogTitle()); 72 if (! noError) 73 return; 74 } 75 } 76 77 private String getDialogTitle() { 78 return CallHierarchyMessages.OpenLocationAction_error_title; 79 } 80 } 81 | Popular Tags |