KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > InspectAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.actions;
12
13  
14 import java.util.Iterator JavaDoc;
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 /**
34  * Places the result of an evaluation in the debug expression view.
35  */

36 public class InspectAction extends EvaluateAction {
37     
38     /**
39      * @see EvaluateAction#displayResult(IEvaluationResult)
40      */

41     protected void displayResult(final IEvaluationResult result) {
42         final Display display= JDIDebugUIPlugin.getStandardDisplay();
43         display.asyncExec(new Runnable JavaDoc() {
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     /**
56      * Make the expression view visible or open one
57      * if required.
58      */

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 JavaDoc selection= getSelectedObject();
86         if (!(selection instanceof IStructuredSelection)) {
87             super.run();
88             return;
89         }
90         
91         //inspecting from the context of the variables view
92
Iterator JavaDoc 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