1 11 12 package org.eclipse.jdt.internal.debug.ui.heapwalking; 13 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.debug.core.DebugException; 17 import org.eclipse.debug.ui.IDebugView; 18 import org.eclipse.debug.ui.InspectPopupDialog; 19 import org.eclipse.jdt.debug.core.IJavaObject; 20 import org.eclipse.jdt.debug.core.IJavaVariable; 21 import org.eclipse.jdt.internal.debug.core.model.JDIReferenceListValue; 22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 23 import org.eclipse.jdt.internal.debug.ui.actions.ObjectActionDelegate; 24 import org.eclipse.jdt.internal.debug.ui.actions.PopupInspectAction; 25 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression; 26 import org.eclipse.jface.action.IAction; 27 import org.eclipse.jface.viewers.IStructuredSelection; 28 import org.eclipse.swt.graphics.Point; 29 import org.eclipse.swt.graphics.Rectangle; 30 import org.eclipse.swt.widgets.Control; 31 import org.eclipse.swt.widgets.Shell; 32 import org.eclipse.swt.widgets.Tree; 33 import org.eclipse.swt.widgets.TreeItem; 34 import org.eclipse.ui.IWorkbenchPart; 35 import org.eclipse.ui.IWorkbenchWindow; 36 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 37 38 import com.ibm.icu.text.MessageFormat; 39 40 45 public class AllReferencesActionDelegate extends ObjectActionDelegate implements IWorkbenchWindowActionDelegate{ 46 47 protected IWorkbenchWindow fWindow; 48 49 public void run(IAction action) { 50 IStructuredSelection currentSelection = getCurrentSelection(); 51 if (currentSelection != null && (currentSelection.getFirstElement() instanceof IJavaVariable)){ 52 IJavaVariable var = (IJavaVariable) currentSelection.getFirstElement(); 53 try { 54 JDIReferenceListValue referenceList = new JDIReferenceListValue((IJavaObject) var.getValue()); 55 InspectPopupDialog ipd = new InspectPopupDialog(getShell(), 56 getAnchor((IDebugView) getPart().getAdapter(IDebugView.class)), 57 PopupInspectAction.ACTION_DEFININITION_ID, 58 new JavaInspectExpression(MessageFormat.format(Messages.AllReferencesActionDelegate_1,new String []{var.getName()}),referenceList)); 59 ipd.open(); 60 } catch (DebugException e) { 61 JDIDebugUIPlugin.statusDialog(e.getStatus()); 62 } 63 } else { 64 JDIDebugUIPlugin.statusDialog(new Status(IStatus.WARNING,JDIDebugUIPlugin.getUniqueIdentifier(),Messages.AllReferencesActionDelegate_0)); 65 } 66 } 67 68 74 protected static Point getAnchor(IDebugView view) { 75 Control control = view.getViewer().getControl(); 76 if (control instanceof Tree) { 77 Tree tree = (Tree) control; 78 TreeItem[] selection = tree.getSelection(); 79 if (selection.length > 0) { 80 Rectangle bounds = selection[0].getBounds(); 81 return tree.toDisplay(new Point(bounds.x, bounds.y + bounds.height)); 82 } 83 } 84 return control.toDisplay(0, 0); 85 } 86 87 90 public void init(IWorkbenchWindow window) { 91 fWindow = window; 92 } 93 94 97 private Shell getShell(){ 98 if (fWindow != null){ 99 return fWindow.getShell(); 100 } 101 if (getWorkbenchWindow() != null){ 102 return getWorkbenchWindow().getShell(); 103 } 104 return null; 105 } 106 107 110 protected IWorkbenchPart getPart() { 111 IWorkbenchPart part = super.getPart(); 112 if (part != null){ 113 return part; 114 } else if (fWindow != null){ 115 return fWindow.getActivePage().getActivePart(); 116 } 117 return null; 118 } 119 120 } 121 | Popular Tags |