KickJava   Java API By Example, From Geeks To Geeks.

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


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.DebugException;
15 import org.eclipse.debug.core.DebugPlugin;
16 import org.eclipse.debug.core.ILaunch;
17 import org.eclipse.debug.core.ILaunchManager;
18 import org.eclipse.debug.core.model.IDebugElement;
19 import org.eclipse.debug.core.model.IDebugTarget;
20 import org.eclipse.debug.core.model.IStackFrame;
21 import org.eclipse.debug.core.model.IThread;
22 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
23 import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
24 import org.eclipse.jface.viewers.Viewer;
25
26 /**
27  * Default model proxy for a debug target.
28  *
29  * @since 3.2
30  */

31 public class DebugTargetProxy extends EventHandlerModelProxy {
32
33     private IDebugTarget fDebugTarget;
34
35     public DebugTargetProxy(IDebugTarget target) {
36         fDebugTarget = target;
37     }
38
39     /* (non-Javadoc)
40      * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#dispose()
41      */

42     public synchronized void dispose() {
43         super.dispose();
44         fDebugTarget = null;
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#containsEvent(org.eclipse.debug.core.DebugEvent)
49      */

50     protected boolean containsEvent(DebugEvent event) {
51         Object JavaDoc source = event.getSource();
52         if (source instanceof IDebugElement) {
53             IDebugTarget debugTarget = ((IDebugElement) source).getDebugTarget();
54             // an expression can return null for debug target
55
if (debugTarget != null) {
56                 return debugTarget.equals(fDebugTarget);
57             }
58         }
59         return false;
60     }
61
62     /* (non-Javadoc)
63      * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#createEventHandlers()
64      */

65     protected DebugEventHandler[] createEventHandlers() {
66         ThreadEventHandler threadEventHandler = new ThreadEventHandler(this);
67         return new DebugEventHandler[] { new DebugTargetEventHandler(this), threadEventHandler,
68                 new StackFrameEventHandler(this, threadEventHandler) };
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.debug.internal.ui.viewers.provisional.IModelProxy#installed(org.eclipse.jface.viewers.Viewer)
73      */

74     public void installed(Viewer viewer) {
75         // select any thread that is already suspended after installation
76
IDebugTarget target = fDebugTarget;
77         if (target != null) {
78             try {
79                 IThread[] threads = target.getThreads();
80                 ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
81                 ILaunch launch = target.getLaunch();
82                 int launchIndex = indexOf(manager.getLaunches(), target.getLaunch());
83                 for (int i = 0; i < threads.length; i++) {
84                     IThread thread = threads[i];
85                     if (thread.isSuspended()) {
86                         IStackFrame frame = thread.getTopStackFrame();
87                         if (frame != null) {
88                             ModelDelta delta = new ModelDelta(manager, IModelDelta.NO_CHANGE);
89                             ModelDelta node = delta.addNode(launch, launchIndex, IModelDelta.NO_CHANGE, target.getLaunch().getChildren().length);
90                             node = node.addNode(target, 0, IModelDelta.NO_CHANGE, threads.length);
91                             node = node.addNode(thread, i, IModelDelta.NO_CHANGE | IModelDelta.EXPAND, thread.getStackFrames().length);
92                             node = node.addNode(frame, 0, IModelDelta.NO_CHANGE | IModelDelta.SELECT, 0);
93                             fireModelChanged(delta);
94                             return;
95                         }
96                     }
97                 }
98                 // expand the target if no suspended thread
99
ModelDelta delta = new ModelDelta(manager, IModelDelta.NO_CHANGE);
100                 ModelDelta node = delta.addNode(launch, launchIndex, IModelDelta.NO_CHANGE, target.getLaunch().getChildren().length);
101                 node = node.addNode(target, 0, IModelDelta.EXPAND | IModelDelta.SELECT, threads.length);
102                 fireModelChanged(delta);
103             } catch (DebugException e) {
104             }
105         }
106     }
107     
108     
109
110 }
111
Popular Tags