1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import java.util.Iterator ; 15 16 import org.eclipse.debug.core.DebugException; 17 import org.eclipse.debug.core.DebugPlugin; 18 import org.eclipse.debug.ui.IDebugUIConstants; 19 import org.eclipse.jdt.debug.core.IJavaValue; 20 import org.eclipse.jdt.debug.core.IJavaVariable; 21 import org.eclipse.jdt.debug.eval.IEvaluationResult; 22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 23 import org.eclipse.jdt.internal.debug.ui.display.IDataDisplay; 24 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression; 25 import org.eclipse.jdt.internal.debug.ui.snippeteditor.JavaSnippetEditor; 26 import org.eclipse.jface.viewers.IStructuredSelection; 27 import org.eclipse.swt.widgets.Display; 28 import org.eclipse.ui.IViewPart; 29 import org.eclipse.ui.IWorkbenchPage; 30 import org.eclipse.ui.IWorkbenchPart; 31 import org.eclipse.ui.PartInitException; 32 33 36 public class InspectAction extends EvaluateAction { 37 38 41 protected void displayResult(final IEvaluationResult result) { 42 final Display display= JDIDebugUIPlugin.getStandardDisplay(); 43 display.asyncExec(new Runnable () { 44 public void run() { 45 if (!display.isDisposed()) { 46 showExpressionView(); 47 JavaInspectExpression exp = new JavaInspectExpression(result); 48 DebugPlugin.getDefault().getExpressionManager().addExpression(exp); 49 } 50 evaluationCleanup(); 51 } 52 }); 53 } 54 55 59 protected void showExpressionView() { 60 if (getTargetPart().getSite().getId().equals(IDebugUIConstants.ID_EXPRESSION_VIEW)) { 61 return; 62 } 63 IWorkbenchPage page = JDIDebugUIPlugin.getActivePage(); 64 if (page != null) { 65 IViewPart part = page.findView(IDebugUIConstants.ID_EXPRESSION_VIEW); 66 if (part == null) { 67 try { 68 page.showView(IDebugUIConstants.ID_EXPRESSION_VIEW); 69 } catch (PartInitException e) { 70 reportError(e.getStatus().getMessage()); 71 } 72 } else { 73 page.bringToTop(part); 74 } 75 } 76 } 77 78 protected void run() { 79 IWorkbenchPart part= getTargetPart(); 80 if (part instanceof JavaSnippetEditor) { 81 ((JavaSnippetEditor)part).evalSelection(JavaSnippetEditor.RESULT_INSPECT); 82 return; 83 } 84 85 Object selection= getSelectedObject(); 86 if (!(selection instanceof IStructuredSelection)) { 87 super.run(); 88 return; 89 } 90 91 Iterator variables = ((IStructuredSelection)selection).iterator(); 93 while (variables.hasNext()) { 94 IJavaVariable var = (IJavaVariable)variables.next(); 95 try { 96 JavaInspectExpression expr = new JavaInspectExpression(var.getName(), (IJavaValue)var.getValue()); 97 DebugPlugin.getDefault().getExpressionManager().addExpression(expr); 98 } catch (DebugException e) { 99 JDIDebugUIPlugin.statusDialog(e.getStatus()); 100 } 101 } 102 103 showExpressionView(); 104 } 105 106 protected IDataDisplay getDataDisplay() { 107 return getDirectDataDisplay(); 108 } 109 } 110 | Popular Tags |