Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2e8a0ffeb159bfabf0573bb774462f4b29327bc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.internal.debug.ui.actions;

import org.eclipse.debug.ui.DebugPopup;
import org.eclipse.debug.ui.InspectPopupDialog;
import org.eclipse.jdt.debug.eval.IEvaluationResult;
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.texteditor.ITextEditor;

public class PopupInspectAction extends InspectAction {

    public static final String ACTION_DEFININITION_ID = "org.eclipse.jdt.debug.ui.commands.Inspect"; //$NON-NLS-1$

    JavaInspectExpression expression;

    private ITextEditor fTextEditor;
    private ISelection fSelectionBeforeEvaluation;
    
    /**
     * @see EvaluateAction#displayResult(IEvaluationResult)
     */
    protected void displayResult(final IEvaluationResult result) {
        IWorkbenchPart part = getTargetPart();
        final StyledText styledText = getStyledText(part);
        if (styledText == null) {
            super.displayResult(result);
        } else {
        	expression = new JavaInspectExpression(result);
            JDIDebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
                public void run() {
                    showPopup(styledText);
                }
            });
        }
        evaluationCleanup();
    }

    protected void showPopup(StyledText textWidget) {
    	IWorkbenchPart part = getTargetPart();
        if (part instanceof ITextEditor) {
        	fTextEditor = (ITextEditor) part;
        	fSelectionBeforeEvaluation = getTargetSelection();
        }
        DebugPopup displayPopup = new InspectPopupDialog(getShell(), getPopupAnchor(textWidget), ACTION_DEFININITION_ID, expression){
        	public boolean close() {
        		boolean returnValue = super.close();
        		if (fTextEditor != null && fSelectionBeforeEvaluation != null){
        			fTextEditor.getSelectionProvider().setSelection(fSelectionBeforeEvaluation);
        			fTextEditor = null;
        			fSelectionBeforeEvaluation = null;
        		}
        		return returnValue;
        	}
        };
        displayPopup.open();
    }
}

Back to the top