KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > variables > VariablesViewEventHandler


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.variables;
12
13
14 import java.util.ArrayList JavaDoc;
15
16 import org.eclipse.debug.core.DebugEvent;
17 import org.eclipse.debug.core.model.IDebugTarget;
18 import org.eclipse.debug.core.model.IExpression;
19 import org.eclipse.debug.core.model.IStackFrame;
20 import org.eclipse.debug.core.model.ISuspendResume;
21 import org.eclipse.debug.core.model.IThread;
22 import org.eclipse.debug.core.model.IVariable;
23 import org.eclipse.debug.internal.ui.views.AbstractDebugEventHandler;
24 import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager;
25 import org.eclipse.debug.ui.AbstractDebugView;
26
27 /**
28  * Updates the variables view
29  */

30 public class VariablesViewEventHandler extends AbstractDebugEventHandler {
31     
32     private RemoteTreeContentManager fContentManager = null;
33     
34     /**
35      * Constructs a new event handler on the given view
36      *
37      * @param view variables view
38      */

39     public VariablesViewEventHandler(AbstractDebugView view) {
40         super(view);
41     }
42     
43     /**
44      * @see AbstractDebugEventHandler#handleDebugEvents(DebugEvent[])
45      */

46     protected void doHandleDebugEvents(DebugEvent[] events, Object JavaDoc data) {
47         for (int i = 0; i < events.length; i++) {
48             DebugEvent event = events[i];
49             switch (event.getKind()) {
50                 case DebugEvent.SUSPEND:
51                         doHandleSuspendEvent(event);
52                     break;
53                 case DebugEvent.CHANGE:
54                         doHandleChangeEvent(event);
55                     break;
56                 case DebugEvent.RESUME:
57                         doHandleResumeEvent(event);
58                     break;
59             }
60         }
61     }
62     
63     /**
64      * @see AbstractDebugEventHandler#updateForDebugEvents(DebugEvent[])
65      */

66     protected void updateForDebugEvents(DebugEvent[] events, Object JavaDoc data) {
67         for (int i = 0; i < events.length; i++) {
68             DebugEvent event = events[i];
69             switch (event.getKind()) {
70                 case DebugEvent.TERMINATE:
71                     doHandleTerminateEvent(event);
72                     break;
73             }
74         }
75     }
76
77     /**
78      * Clear cached variable expansion state
79      */

80     protected void doHandleResumeEvent(DebugEvent event) {
81         if (!event.isStepStart() && !event.isEvaluation()) {
82             // clear variable expansion state
83
getVariablesView().clearExpandedVariables(event.getSource());
84         }
85         if (!event.isEvaluation()) {
86             Object JavaDoc input = getVariablesView().getVariablesViewer().getInput();
87             if (input instanceof IStackFrame) {
88                 IStackFrame frame = (IStackFrame)input;
89                 if (event.getSource().equals(frame.getThread())) {
90                     fContentManager.cancel();
91                 }
92             }
93         }
94     }
95
96     /**
97      * Clear any cached variable expansion state for the
98      * terminated thread/target. Also, remove the part listener if there are
99      * no more active debug targets.
100      */

101     protected void doHandleTerminateEvent(DebugEvent event) {
102         getVariablesView().clearExpandedVariables(event.getSource());
103     }
104     
105     /**
106      * Process a SUSPEND event
107      */

108     protected void doHandleSuspendEvent(DebugEvent event) {
109         if (event.getDetail() != DebugEvent.EVALUATION_IMPLICIT) {
110             // Don't refresh everytime an implicit evaluation finishes
111
if (event.getSource() instanceof ISuspendResume) {
112                 if (!((ISuspendResume)event.getSource()).isSuspended()) {
113                     // no longer suspended
114
return;
115                 }
116             }
117             refresh();
118             getVariablesView().populateDetailPane();
119         }
120     }
121     
122     /**
123      * Process a CHANGE event
124      */

125     protected void doHandleChangeEvent(DebugEvent event) {
126         if (event.getDetail() == DebugEvent.STATE) {
127             // only process variable state changes
128
if (event.getSource() instanceof IVariable) {
129                 refresh(event.getSource());
130                 getVariablesView().populateDetailPane();
131             }
132         } else {
133             if (!(event.getSource() instanceof IExpression)) {
134                 if (event.getSource() instanceof IVariable) {
135                     refresh(event.getSource());
136                 } else {
137                     refresh();
138                 }
139                 getVariablesView().populateDetailPane();
140             }
141         }
142     }
143
144     /**
145      * Returns the view that event handler updates.
146      */

147     protected VariablesView getVariablesView() {
148         return (VariablesView)getView();
149     }
150     
151     /**
152      * Also update the details area.
153      *
154      * @see org.eclipse.debug.internal.ui.views.AbstractDebugEventHandler#viewBecomesVisible()
155      */

156     protected void viewBecomesVisible() {
157         super.viewBecomesVisible();
158         getVariablesView().populateDetailPane();
159     }
160
161     /* (non-Javadoc)
162      * @see org.eclipse.debug.internal.ui.views.AbstractDebugEventHandler#filterEvents(org.eclipse.debug.core.DebugEvent[])
163      */

164     protected DebugEvent[] filterEvents(DebugEvent[] events) {
165         ArrayList JavaDoc filtered = null;
166         for (int i=0; i<events.length; i++) {
167             if (isFiltered(events[i])) {
168                 if (events.length == 1) {
169                     return EMPTY_EVENT_SET;
170                 }
171                 if (filtered == null) {
172                     filtered = new ArrayList JavaDoc();
173                 }
174                 filtered.add(events[i]);
175             }
176         }
177         if (filtered == null) {
178             return events;
179         }
180         if (filtered.size() == events.length) {
181             return EMPTY_EVENT_SET;
182         }
183         ArrayList JavaDoc all = new ArrayList JavaDoc(events.length);
184         for (int i = 0; i < events.length; i++) {
185             all.add(events[i]);
186         }
187         all.removeAll(filtered);
188         return (DebugEvent[]) all.toArray(new DebugEvent[all.size()]);
189     }
190     
191     public void setContentManager(RemoteTreeContentManager manager) {
192         fContentManager = manager;
193     }
194
195     protected boolean isFiltered(DebugEvent event) {
196         if (event.getKind() == DebugEvent.CHANGE) {
197             Object JavaDoc source = event.getSource();
198             switch (event.getDetail()) {
199                 case DebugEvent.CONTENT:
200                     if (source instanceof IVariable ||
201                         source instanceof IStackFrame ||
202                         source instanceof IThread ||
203                         source instanceof IDebugTarget) {
204                         return false;
205                     }
206                     return true;
207                 case DebugEvent.STATE:
208                     if (source instanceof IVariable) {
209                         return false;
210                     }
211                     return true;
212                 default: // UNSPECIFIED
213
return true;
214             }
215         }
216         return false;
217     }
218 }
219
220
Popular Tags