KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > viewers > update > DebugEventHandler


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.viewers.update;
12
13 import org.eclipse.debug.core.DebugEvent;
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
16 import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
17 import org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy;
18
19 /**
20  * Handles debug events for an event update policy in a viewer.
21  *
22  * @since 3.2
23  */

24 public abstract class DebugEventHandler {
25     
26     private AbstractModelProxy fModelProxy;
27
28     /**
29      * Constructs an event handler for the given model proxy.
30      *
31      * @param policy
32      */

33     public DebugEventHandler(AbstractModelProxy proxy) {
34         fModelProxy = proxy;
35     }
36     
37     /**
38      * Disposes this event handler
39      */

40     public synchronized void dispose() {
41         fModelProxy = null;
42     }
43         
44     /**
45      * Returns the model proxy this event handler working for,
46      * or <code>null</code> if disposed.
47      *
48      * @return
49      */

50     protected synchronized AbstractModelProxy getModelProxy() {
51         return fModelProxy;
52     }
53
54     /**
55      * Returns whether this event handler handles the given event
56      *
57      * @param event event to handle
58      * @return whether this event handler handles the given event
59      */

60     protected abstract boolean handlesEvent(DebugEvent event);
61     
62     /**
63      * Handles a create event.
64      *
65      * @param event
66      */

67     protected void handleCreate(DebugEvent event) {
68         refreshRoot(event);
69     }
70         
71     /**
72      * Handles a terminate event.
73      *
74      * @param event
75      */

76     protected void handleTerminate(DebugEvent event) {
77         refreshRoot(event);
78     }
79     
80     /**
81      * Handles a suspend event.
82      *
83      * @param event
84      */

85     protected void handleSuspend(DebugEvent event) {
86         refreshRoot(event);
87     }
88     
89     /**
90      * Handles a resume event for which a suspend is expected shortly (<500ms).
91      *
92      * @param event
93      */

94     protected void handleResumeExpectingSuspend(DebugEvent event) {
95         // do nothing unless the suspend times out
96
}
97     
98     /**
99      * Handles a resume event that is not expecting an immediate suspend event
100      *
101      * @param event
102      */

103     protected void handleResume(DebugEvent event) {
104         refreshRoot(event);
105     }
106     
107     /**
108      * Handles a change event.
109      *
110      * @param event
111      */

112     protected void handleChange(DebugEvent event) {
113         refreshRoot(event);
114     }
115
116     /**
117      * Handles an unknown event.
118      *
119      * @param event
120      */

121     protected void handleOther(DebugEvent event) {
122         refreshRoot(event);
123     }
124     
125     /**
126      * Notification that a pending suspend event was not received for the given
127      * resume event within the timeout period.
128      *
129      * @param resume resume event with missing suspend event
130      */

131     protected void handleSuspendTimeout(DebugEvent event) {
132         refreshRoot(event);
133     }
134     
135     /**
136      * Handles the given suspend event which caused a timeout. It is
137      * parired with its original resume event.
138      *
139      * @param suspend suspend event
140      * @param resume resume event
141      */

142     protected void handleLateSuspend(DebugEvent suspend, DebugEvent resume) {
143         refreshRoot(suspend);
144     }
145
146     /**
147      * Fires a model delta to indicate that the launch manager should be refreshed.
148      * Subclasses should override individual handle events to provide deltas that
149      * better reflect the actual change in the model.
150      */

151     protected void refreshRoot(DebugEvent event) {
152         ModelDelta delta = new ModelDelta(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.CONTENT);
153         fireDelta(delta);
154     }
155     
156     /**
157      * Fires the given delta, unless this handler has been disposed.
158      *
159      * @param delta
160      */

161     protected void fireDelta(IModelDelta delta) {
162         AbstractModelProxy modelProxy = getModelProxy();
163         if (modelProxy != null) {
164             modelProxy.fireModelChanged(delta);
165         }
166     }
167     
168     /**
169      * Returns whether this handler has been disposed.
170      *
171      * @return whether this handler has been disposed
172      */

173     protected synchronized boolean isDisposed() {
174         return fModelProxy == null;
175     }
176     
177     protected int indexOf(Object JavaDoc[] list, Object JavaDoc element) {
178         for (int i = 0; i < list.length; i++) {
179             if (element.equals(list[i])) {
180                 return i;
181             }
182         }
183         return -1;
184     }
185     
186 }
187
Popular Tags