1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 16 import org.eclipse.debug.core.DebugException; 17 import org.eclipse.debug.core.model.IValue; 18 import org.eclipse.debug.ui.DebugUITools; 19 import org.eclipse.debug.ui.IDebugUIConstants; 20 import org.eclipse.debug.ui.IValueDetailListener; 21 import org.eclipse.jdt.debug.core.IJavaType; 22 import org.eclipse.jdt.debug.core.IJavaValue; 23 import org.eclipse.jdt.debug.eval.IEvaluationResult; 24 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 25 import org.eclipse.jdt.internal.debug.ui.display.IDataDisplay; 26 import org.eclipse.jdt.internal.debug.ui.snippeteditor.JavaSnippetEditor; 27 import org.eclipse.swt.widgets.Display; 28 import org.eclipse.ui.IWorkbenchPart; 29 30 33 public class DisplayAction extends EvaluateAction { 34 35 38 protected void displayResult(final IEvaluationResult evaluationResult) { 39 if (evaluationResult.hasErrors()) { 40 final Display display = JDIDebugUIPlugin.getStandardDisplay(); 41 display.asyncExec(new Runnable () { 42 public void run() { 43 if (display.isDisposed()) { 44 return; 45 } 46 reportErrors(evaluationResult); 47 evaluationCleanup(); 48 } 49 }); 50 return; 51 } 52 53 final String snippet= evaluationResult.getSnippet(); 54 IJavaValue resultValue= evaluationResult.getValue(); 55 try { 56 String sig= null; 57 IJavaType type= resultValue.getJavaType(); 58 if (type != null) { 59 sig= type.getSignature(); 60 } 61 if ("V".equals(sig)) { displayStringResult(snippet, ActionMessages.DisplayAction_no_result_value); 63 } else { 64 final String resultString; 65 if (sig != null) { 66 resultString= MessageFormat.format(ActionMessages.DisplayAction_type_name_pattern, new Object [] { resultValue.getReferenceTypeName() }); 67 } else { 68 resultString= ""; } 70 getDebugModelPresentation().computeDetail(resultValue, new IValueDetailListener() { 71 public void detailComputed(IValue value, String result) { 72 displayStringResult(snippet, MessageFormat.format(ActionMessages.DisplayAction_result_pattern, new Object [] { resultString, trimDisplayResult(result)})); 73 } 74 }); 75 } 76 } catch (DebugException x) { 77 displayStringResult(snippet, getExceptionMessage(x)); 78 } 79 } 80 81 protected void displayStringResult(final String snippet,final String resultString) { 82 final IDataDisplay directDisplay= getDirectDataDisplay(); 83 final Display display= JDIDebugUIPlugin.getStandardDisplay(); 84 display.asyncExec(new Runnable () { 85 public void run() { 86 if (!display.isDisposed()) { 87 IDataDisplay dataDisplay= getDataDisplay(); 88 if (dataDisplay != null) { 89 if (directDisplay == null) { 90 dataDisplay.displayExpression(snippet); 91 } 92 dataDisplay.displayExpressionValue(trimDisplayResult(resultString)); 93 } 94 } 95 evaluationCleanup(); 96 } 97 }); 98 } 99 100 protected void run() { 101 IWorkbenchPart part= getTargetPart(); 102 if (part instanceof JavaSnippetEditor) { 103 ((JavaSnippetEditor) part).evalSelection(JavaSnippetEditor.RESULT_DISPLAY); 104 return; 105 } 106 super.run(); 107 } 108 109 115 public static String trimDisplayResult(String result) { 116 int max = DebugUITools.getPreferenceStore().getInt(IDebugUIConstants.PREF_MAX_DETAIL_LENGTH); 117 if (max > 0 && result.length() > max) { 118 result = result.substring(0, max) + "..."; } 120 return result; 121 } 122 123 } 124 | Popular Tags |