1 /******************************************************************************* 2 * Copyright (c) 2000, 2015 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.debug.ui.actions; 15 16 import org.eclipse.debug.ui.DebugPopup; 17 import org.eclipse.debug.ui.InspectPopupDialog; 18 import org.eclipse.jdt.debug.eval.IEvaluationResult; 19 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 20 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression; 21 import org.eclipse.jface.viewers.ISelection; 22 import org.eclipse.swt.custom.StyledText; 23 import org.eclipse.ui.IWorkbenchPart; 24 import org.eclipse.ui.texteditor.ITextEditor; 25 26 public class PopupInspectAction extends InspectAction { 27 28 public static final String ACTION_DEFININITION_ID = "org.eclipse.jdt.debug.ui.commands.Inspect"; //$NON-NLS-1$ 29 30 JavaInspectExpression expression; 31 32 private ITextEditor fTextEditor; 33 private ISelection fSelectionBeforeEvaluation; 34 35 /** 36 * @see EvaluateAction#displayResult(IEvaluationResult) 37 */ 38 @Override displayResult(final IEvaluationResult result)39 protected void displayResult(final IEvaluationResult result) { 40 IWorkbenchPart part = getTargetPart(); 41 final StyledText styledText = getStyledText(part); 42 if (styledText == null) { 43 super.displayResult(result); 44 } else { 45 expression = new JavaInspectExpression(result); 46 JDIDebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() { 47 @Override 48 public void run() { 49 showPopup(styledText); 50 } 51 }); 52 } 53 evaluationCleanup(); 54 } 55 showPopup(StyledText textWidget)56 protected void showPopup(StyledText textWidget) { 57 IWorkbenchPart part = getTargetPart(); 58 if (part instanceof ITextEditor) { 59 fTextEditor = (ITextEditor) part; 60 fSelectionBeforeEvaluation = getTargetSelection(); 61 } 62 DebugPopup displayPopup = new InspectPopupDialog(getShell(), getPopupAnchor(textWidget), ACTION_DEFININITION_ID, expression){ 63 @Override 64 public boolean close() { 65 boolean returnValue = super.close(); 66 if (fTextEditor != null && fTextEditor.getSelectionProvider() != null && fSelectionBeforeEvaluation != null) { 67 fTextEditor.getSelectionProvider().setSelection(fSelectionBeforeEvaluation); 68 fTextEditor = null; 69 fSelectionBeforeEvaluation = null; 70 } 71 return returnValue; 72 } 73 }; 74 displayPopup.open(); 75 } 76 } 77