KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > monitors > MonitorsDebugEventHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.monitors;
12
13
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.core.runtime.jobs.Job;
18 import org.eclipse.debug.core.DebugEvent;
19 import org.eclipse.debug.internal.ui.views.AbstractDebugEventHandler;
20 import org.eclipse.debug.ui.IDebugUIConstants;
21 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
22 import org.eclipse.jdt.debug.core.IJavaThread;
23 import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
24
25 /**
26  * Listen to certain events in the debug view
27  */

28 public class MonitorsDebugEventHandler extends AbstractDebugEventHandler {
29
30     public MonitorsDebugEventHandler(MonitorsView view) {
31         super(view);
32     }
33
34     /**
35      * @see org.eclipse.debug.internal.ui.views.AbstractDebugEventHandler#doHandleDebugEvents(DebugEvent[])
36      */

37     protected void doHandleDebugEvents(DebugEvent[] events) {
38         DebugEvent event;
39         Object JavaDoc source;
40         boolean monitorInformationAvailable= true;
41         boolean updateNeeded= false;
42         final IJavaDebugTarget[] targets = new IJavaDebugTarget[1];
43         for (int i = 0; i < events.length; i++) {
44             event= events[i];
45             source= event.getSource();
46             
47             //if a thread is suspended in the debug view
48
if(event.getKind() == DebugEvent.SUSPEND) {
49                 if (source instanceof IJavaDebugTarget) {
50                     IJavaDebugTarget target= (IJavaDebugTarget)source;
51                     monitorInformationAvailable= target.supportsMonitorInformation();
52                     if (monitorInformationAvailable) {
53                         targets[0] = target;
54                         updateNeeded= true;
55                     }
56                 } else if (source instanceof IJavaThread) {
57                     IJavaDebugTarget target= (IJavaDebugTarget)((IJavaThread)source).getDebugTarget();
58                     monitorInformationAvailable= target.supportsMonitorInformation();
59                     if (monitorInformationAvailable) {
60                         targets[0] = target;
61                         updateNeeded= true;
62                     }
63                     
64                 }
65             } else if(event.getKind() == DebugEvent.RESUME) {
66                 if (source instanceof IJavaDebugTarget) {
67                     IJavaDebugTarget target= (IJavaDebugTarget)source;
68                     monitorInformationAvailable= target.supportsMonitorInformation();
69                     if (monitorInformationAvailable) {
70                         targets[0] = target;
71                         updateNeeded= true;
72                     }
73                 } else if (source instanceof IJavaThread) {
74                     IJavaDebugTarget target= (IJavaDebugTarget)((IJavaThread)source).getDebugTarget();
75                     monitorInformationAvailable= target.supportsMonitorInformation();
76                     if (monitorInformationAvailable) {
77                         targets[0] = target;
78                         updateNeeded= true;
79                     }
80                 }
81             } else if(event.getKind() == DebugEvent.TERMINATE && source instanceof IJavaDebugTarget) {
82                 MonitorManager.getDefault().removeMonitorInformation((IJavaDebugTarget)source);
83                 ((MonitorsView)getView()).refreshCurrentViewer(monitorInformationAvailable, false);
84             }
85         }
86         if (updateNeeded) {
87             Job job = new Job(MonitorMessages.getString("MonitorsView.4")) { //$NON-NLS-1$
88
protected IStatus run(IProgressMonitor monitor) {
89                     MonitorManager.getDefault().updatePartial(targets[0]);
90                     Runnable JavaDoc r = new Runnable JavaDoc() {
91                         public void run() {
92                             ((MonitorsView)getView()).refreshCurrentViewer(true, false);
93                         }
94                     };
95                     getView().asyncExec(r);
96                     return Status.OK_STATUS;
97                 }
98             };
99             job.setSystem(true);
100             IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) getView().getAdapter(IWorkbenchSiteProgressService.class);
101             if (service == null) {
102                 job.schedule();
103             } else {
104                 service.schedule(job);
105             }
106         }
107     }
108     /**
109      * @see org.eclipse.debug.internal.ui.views.AbstractDebugEventHandler#refresh()
110      */

111     public void refresh() {
112         ((MonitorsView)getView()).selectionChanged(null, getView().getSite().getPage().getSelection(IDebugUIConstants.ID_DEBUG_VIEW));
113     }
114
115 }
116
Popular Tags