1 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 28 public class MonitorsDebugEventHandler extends AbstractDebugEventHandler { 29 30 public MonitorsDebugEventHandler(MonitorsView view) { 31 super(view); 32 } 33 34 37 protected void doHandleDebugEvents(DebugEvent[] events) { 38 DebugEvent event; 39 Object 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(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")) { protected IStatus run(IProgressMonitor monitor) { 89 MonitorManager.getDefault().updatePartial(targets[0]); 90 Runnable r = new Runnable () { 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 111 public void refresh() { 112 ((MonitorsView)getView()).selectionChanged(null, getView().getSite().getPage().getSelection(IDebugUIConstants.ID_DEBUG_VIEW)); 113 } 114 115 } 116 | Popular Tags |