KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.ILaunch;
16 import org.eclipse.debug.core.ILaunchManager;
17 import org.eclipse.debug.core.model.IProcess;
18 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
19 import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
20 import org.eclipse.jface.viewers.Viewer;
21
22 public class ProcessProxy extends EventHandlerModelProxy {
23
24     private IProcess fProcess;
25
26     private DebugEventHandler fProcessEventHandler = new DebugEventHandler(this) {
27         protected boolean handlesEvent(DebugEvent event) {
28             return event.getSource().equals(fProcess);
29         }
30
31         protected void handleChange(DebugEvent event) {
32             fireDelta(IModelDelta.STATE);
33         }
34
35         protected void handleCreate(DebugEvent event) {
36             // do nothing - Launch change notification handles this
37
}
38
39         protected void handleTerminate(DebugEvent event) {
40             fireDelta(IModelDelta.STATE | IModelDelta.UNINSTALL);
41         }
42         
43         private void fireDelta(int flags) {
44             ModelDelta delta = null;
45             synchronized (ProcessProxy.this) {
46                 if (!isDisposed()) {
47                     delta = new ModelDelta(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NO_CHANGE);
48                     ModelDelta node = delta;
49                     node = node.addNode(fProcess.getLaunch(), IModelDelta.NO_CHANGE);
50                     node.addNode(fProcess, flags);
51                 }
52             }
53             if (delta != null && !isDisposed()) {
54                 fireModelChanged(delta);
55             }
56         }
57         
58     };
59
60     /* (non-Javadoc)
61      * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#dispose()
62      */

63     public synchronized void dispose() {
64         super.dispose();
65         fProcess = null;
66     }
67
68     public ProcessProxy(IProcess process) {
69         fProcess = process;
70     }
71
72     protected synchronized boolean containsEvent(DebugEvent event) {
73         return event.getSource().equals(fProcess);
74     }
75
76     protected DebugEventHandler[] createEventHandlers() {
77         return new DebugEventHandler[] {fProcessEventHandler};
78     }
79
80     /* (non-Javadoc)
81      * @see org.eclipse.debug.internal.ui.viewers.AbstractModelProxy#installed()
82      */

83     public void installed(Viewer viewer) {
84         super.installed(viewer);
85         // select process if in run mode
86
IProcess process = fProcess;
87         if (process != null) {
88             ILaunch launch = process.getLaunch();
89             if (launch != null && ILaunchManager.RUN_MODE.equals(launch.getLaunchMode())) {
90                 // select the process
91
ModelDelta delta = new ModelDelta(DebugPlugin.getDefault().getLaunchManager(), IModelDelta.NO_CHANGE);
92                 ModelDelta node = delta.addNode(process.getLaunch(), IModelDelta.NO_CHANGE);
93                 node = node.addNode(process, IModelDelta.SELECT);
94                 fireModelChanged(delta);
95             }
96         }
97     }
98 }
99
Popular Tags