KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > expression > ExpressionViewEventHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.debug.internal.ui.views.expression;
12
13
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.debug.core.DebugEvent;
18 import org.eclipse.debug.core.DebugPlugin;
19 import org.eclipse.debug.core.IExpressionsListener;
20 import org.eclipse.debug.core.ILaunch;
21 import org.eclipse.debug.core.model.IDebugElement;
22 import org.eclipse.debug.core.model.IDebugTarget;
23 import org.eclipse.debug.core.model.IExpression;
24 import org.eclipse.debug.core.model.IWatchExpression;
25 import org.eclipse.debug.internal.ui.views.variables.VariablesViewEventHandler;
26 import org.eclipse.debug.ui.AbstractDebugView;
27 import org.eclipse.debug.ui.DebugUITools;
28 import org.eclipse.jface.viewers.IContentProvider;
29 import org.eclipse.jface.viewers.ISelection;
30 import org.eclipse.jface.viewers.IStructuredSelection;
31 import org.eclipse.jface.viewers.StructuredSelection;
32  
33 /**
34  * Updates the expression view
35  */

36 public class ExpressionViewEventHandler extends VariablesViewEventHandler implements IExpressionsListener {
37
38     /**
39      * Also update expressions if a target terminates
40      *
41      * @see org.eclipse.debug.internal.ui.views.variables.VariablesViewEventHandler#doHandleTerminateEvent(org.eclipse.debug.core.DebugEvent)
42      */

43     protected void doHandleTerminateEvent(DebugEvent event) {
44         super.doHandleTerminateEvent(event);
45         if (event.getSource() instanceof IDebugTarget) {
46             IExpression[] expressions = DebugPlugin.getDefault().getExpressionManager().getExpressions();
47             IAdaptable object = DebugUITools.getDebugContext();
48             IDebugElement context= null;
49             if (object instanceof IDebugElement) {
50                 context= (IDebugElement) object;
51             } else if (object instanceof ILaunch) {
52                 context= ((ILaunch) object).getDebugTarget();
53             }
54             for (int i = 0; i < expressions.length; i++) {
55                 IExpression expression = expressions[i];
56                 if (expression instanceof IWatchExpression) {
57                     ((IWatchExpression)expression).setExpressionContext(context);
58                 }
59             }
60         }
61     }
62
63     /**
64      * Constructs a new event handler on the given view
65      *
66      * @param view variables view
67      */

68     public ExpressionViewEventHandler(AbstractDebugView view) {
69         super(view);
70         DebugPlugin plugin= DebugPlugin.getDefault();
71         plugin.getExpressionManager().addExpressionListener(this);
72     }
73     
74     /**
75      * De-registers this event handler from the debug model.
76      */

77     public void dispose() {
78         DebugPlugin plugin= DebugPlugin.getDefault();
79         plugin.getExpressionManager().removeExpressionListener(this);
80         super.dispose();
81     }
82     
83     /**
84      * @see IExpressionsListener#expressionsAdded(IExpression[])
85      */

86     public void expressionsAdded(final IExpression[] expressions) {
87         Runnable JavaDoc r = new Runnable JavaDoc() {
88             public void run() {
89                 if (isAvailable()) {
90                     getTreeViewer().refresh();
91                     if (expressions.length > 0) {
92                         ISelection selection = new StructuredSelection(expressions[0]);
93                         getTreeViewer().setSelection(selection, true);
94                     }
95                 }
96             }
97         };
98         getView().asyncExec(r);
99     }
100
101     /**
102      * @see IExpressionsListener#expressionsRemoved(IExpression[])
103      */

104     public void expressionsRemoved(final IExpression[] expressions) {
105         Runnable JavaDoc r = new Runnable JavaDoc() {
106             public void run() {
107                 if (isAvailable()) {
108                     getTreeViewer().getControl().setRedraw(false);
109                     for (int i = 0; i < expressions.length; i++) {
110                         IExpression expression = expressions[i];
111                         remove(expression);
112                         IContentProvider provider= getTreeViewer().getContentProvider();
113                         if (provider instanceof RemoteExpressionsContentProvider) {
114                             RemoteExpressionsContentProvider expressionProvider= (RemoteExpressionsContentProvider) provider;
115                             List JavaDoc decendants = expressionProvider.getCachedDecendants(expression);
116                             decendants.add(expression);
117                             // Remove the parent cache for the expression and its children
118
expressionProvider.removeCache(decendants.toArray());
119                             IExpression[] allExpressions= DebugPlugin.getDefault().getExpressionManager().getExpressions();
120                             if (allExpressions.length > 0) {
121                                 getTreeViewer().setSelection(new StructuredSelection(allExpressions[0]), true);
122                             }
123                         }
124                     }
125                     getTreeViewer().getControl().setRedraw(true);
126                 }
127             }
128         };
129         getView().asyncExec(r);
130     }
131
132     /**
133      * @see IExpressionsListener#expressionsChanged(IExpression[])
134      */

135     public void expressionsChanged(final IExpression[] expressions) {
136         Runnable JavaDoc r = new Runnable JavaDoc() {
137             public void run() {
138                 if (isAvailable()) {
139                     getTreeViewer().getControl().setRedraw(false);
140                     for (int i = 0; i < expressions.length; i++) {
141                         IExpression expression = expressions[i];
142                         refresh(expression);
143                         // update details if selected
144
IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection();
145                         if (selection.size() == 1 && selection.getFirstElement().equals(expression)) {
146                             getVariablesView().populateDetailPane();
147                         }
148                     }
149                     getTreeViewer().getControl().setRedraw(true);
150                 }
151             }
152         };
153         getView().asyncExec(r);
154     }
155     
156     /**
157      * Override the superclass method. Do nothing.
158      */

159     protected void doHandleResumeEvent(DebugEvent event) {
160     }
161     /**
162      * @see org.eclipse.debug.internal.ui.views.variables.VariablesViewEventHandler#doHandleChangeEvent(org.eclipse.debug.core.DebugEvent)
163      */

164     protected void doHandleChangeEvent(DebugEvent event) {
165         if (event.getSource() instanceof IExpression) {
166             refresh(event.getSource());
167             getVariablesView().populateDetailPane();
168         } else {
169             super.doHandleChangeEvent(event);
170         }
171     }
172
173     protected boolean isFiltered(DebugEvent event) {
174         // TODO Auto-generated method stub
175
return false;
176     }
177     
178     
179     
180 }
181
Popular Tags