1 11 package org.eclipse.jdt.internal.debug.ui.monitors; 12 13 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.Set ; 17 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.core.runtime.jobs.Job; 22 import org.eclipse.debug.internal.ui.DebugUIPlugin; 23 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; 24 import org.eclipse.debug.internal.ui.views.AbstractDebugEventHandlerView; 25 import org.eclipse.debug.ui.IDebugUIConstants; 26 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 27 import org.eclipse.jdt.internal.debug.core.model.JDIDebugElement; 28 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds; 29 import org.eclipse.jface.action.IMenuManager; 30 import org.eclipse.jface.action.IToolBarManager; 31 import org.eclipse.jface.action.Separator; 32 import org.eclipse.jface.viewers.ISelection; 33 import org.eclipse.jface.viewers.IStructuredSelection; 34 import org.eclipse.jface.viewers.StructuredViewer; 35 import org.eclipse.jface.viewers.TreeViewer; 36 import org.eclipse.jface.viewers.Viewer; 37 import org.eclipse.swt.SWT; 38 import org.eclipse.swt.graphics.Color; 39 import org.eclipse.swt.widgets.Composite; 40 import org.eclipse.swt.widgets.Control; 41 import org.eclipse.swt.widgets.Display; 42 import org.eclipse.swt.widgets.Item; 43 import org.eclipse.swt.widgets.TreeItem; 44 import org.eclipse.ui.ISelectionListener; 45 import org.eclipse.ui.IWorkbenchActionConstants; 46 import org.eclipse.ui.IWorkbenchPart; 47 import org.eclipse.ui.part.Page; 48 import org.eclipse.ui.progress.IWorkbenchSiteProgressService; 49 50 53 public class MonitorsView extends AbstractDebugEventHandlerView implements ISelectionListener { 54 55 public static final int VIEW_ID_THREAD = 1; 56 public static final int VIEW_ID_MONITOR = 2; 57 public static final int VIEW_ID_DEADLOCK = 3; 58 59 private int fViewId = VIEW_ID_MONITOR; 60 61 private Viewer fDeadLocksViewer; 62 private Viewer fMonitorsViewer; 63 64 private boolean fMonitorInformationAvailable= true; 65 66 private boolean fValidSelection= false; 67 68 private IJavaDebugTarget fLastSelectedTarget; 69 70 74 class MonitorsViewerPage extends Page { 75 76 79 public void createControl(Composite parent) { 80 Viewer viewer = createMonitorsViewer(parent); 81 setMonitorsViewer(viewer); 82 } 83 84 87 public Control getControl() { 88 return getMonitorsViewer().getControl(); 89 } 90 91 94 public void setFocus() { 95 Viewer viewer= getMonitorsViewer(); 96 if (viewer != null) { 97 Control c = viewer.getControl(); 98 if (!c.isFocusControl()) { 99 c.setFocus(); 100 } 101 } 102 } 103 } 104 105 109 class DeadLocksViewerPage extends Page { 110 111 114 public void createControl(Composite parent) { 115 Viewer viewer = createDeadLocksViewer(parent); 116 setDeadLocksViewer(viewer); 117 } 118 119 122 public Control getControl() { 123 return getDeadLocksViewer().getControl(); 124 } 125 126 129 public void setFocus() { 130 Viewer viewer= getDeadLocksViewer(); 131 if (viewer != null) { 132 Control c = viewer.getControl(); 133 if (!c.isFocusControl()) { 134 c.setFocus(); 135 } 136 } 137 } 138 } 139 140 public MonitorsView(){ 141 setEventHandler(new MonitorsDebugEventHandler(this)); 142 } 143 144 148 public void setViewId(int viewerIndex) { 149 fViewId = viewerIndex; 150 refreshCurrentViewer(fMonitorInformationAvailable, true); 151 } 152 153 156 public int getViewId() { 157 return fViewId; 158 } 159 160 163 protected Viewer createViewer(Composite parent) { 164 StructuredViewer threadViewer = new TreeViewer(parent, SWT.MULTI); 165 threadViewer.setContentProvider(new ThreadsViewContentProvider()); 166 threadViewer.setLabelProvider(new MonitorModelPresentation()); 167 threadViewer.setInput(MonitorManager.getDefault()); 168 return threadViewer; 169 } 170 171 protected Viewer createMonitorsViewer(Composite parent) { 172 StructuredViewer monitorsViewer = new TreeViewer(parent, SWT.MULTI); 173 monitorsViewer.setContentProvider(new MonitorsViewContentProvider()); 174 monitorsViewer.setLabelProvider(new MonitorModelPresentation()); 175 monitorsViewer.setInput(MonitorManager.getDefault()); 176 return monitorsViewer; 177 } 178 179 protected Viewer createDeadLocksViewer(Composite parent) { 180 StructuredViewer deadLocksViewer = new TreeViewer(parent, SWT.MULTI) { 181 public void refresh() { 183 getControl().setRedraw(false); 184 super.refresh(); 185 186 Item[] children = getChildren(getControl()); 187 if (children != null) { 188 Color c= DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CHANGED_VARIABLE_COLOR); 190 for (int i = 0; i < children.length; i++) { 191 updateColor((TreeItem)children[i], c, 0); 192 } 193 } 194 getControl().setRedraw(true); 195 } 196 197 public void updateColor(TreeItem item, Color c, int count) { 199 Object data= item.getData(); 200 if (data instanceof DeadLocksViewContentProvider.ContentThreadWrapper) { 201 if(((DeadLocksViewContentProvider.ContentThreadWrapper)data).caughtInADeadLock) { 202 item.setForeground(c); 203 } 204 } 205 206 TreeItem[] children = item.getItems(); 207 for (int i = 0; i < children.length; i++) { 208 updateColor(children[i], c, (count+1)); 209 } 210 } 211 }; 212 deadLocksViewer.setContentProvider(new DeadLocksViewContentProvider()); 213 deadLocksViewer.setLabelProvider(new MonitorModelPresentation()); 214 deadLocksViewer.setInput(MonitorManager.getDefault()); 215 return deadLocksViewer; 216 } 217 218 221 public void createPartControl(Composite parent) { 222 super.createPartControl(parent); 223 225 DeadLocksViewerPage deadLocksPage = new DeadLocksViewerPage(); 226 deadLocksPage.createControl(getPageBook()); 227 initPage(deadLocksPage); 228 229 MonitorsViewerPage monitorsViewerPage = new MonitorsViewerPage(); 230 monitorsViewerPage.createControl(getPageBook()); 231 initPage(monitorsViewerPage); 232 233 createContextMenu(getDeadLocksViewer().getControl()); 234 createContextMenu(getMonitorsViewer().getControl()); 235 236 setViewId(VIEW_ID_MONITOR); 237 238 getSite().getPage().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); 240 } 241 242 245 protected void createActions() { 246 247 } 248 249 252 protected String getHelpContextId() { 253 return IJavaDebugHelpContextIds.MONITORS_VIEW; 254 } 255 256 259 protected void fillContextMenu(IMenuManager menu) { 260 menu.add(new Separator("vmGroup")); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); 262 } 263 264 267 protected void configureToolBar(IToolBarManager tbm) { 268 tbm.add(new Separator("vmGroup")); updateObjects(); 270 } 271 272 276 public Viewer getDeadLocksViewer() { 277 return fDeadLocksViewer; 278 } 279 280 284 public Viewer getMonitorsViewer() { 285 return fMonitorsViewer; 286 } 287 288 292 public void setDeadLocksViewer(Viewer deadLocksViewer) { 293 fDeadLocksViewer = deadLocksViewer; 294 } 295 296 300 public void setMonitorsViewer(Viewer monitorsViewer) { 301 fMonitorsViewer = monitorsViewer; 302 } 303 304 protected void refreshCurrentViewer(boolean monitorInformationAvailable, boolean showPage) { 305 if (getPageBook().isDisposed()) { 306 return; 307 } 308 if (!fValidSelection) { 309 showMessage(MonitorMessages.getString("MonitorsView.2")); updateObjects(); 311 return; 312 } 313 boolean changeFromShowMessagePage= monitorInformationAvailable && !fMonitorInformationAvailable; 314 fMonitorInformationAvailable= monitorInformationAvailable; 315 if (!monitorInformationAvailable) { 316 showMessage(MonitorMessages.getString("MonitorsView.1")); updateObjects(); 318 return; 319 } 320 Control page= null; 321 switch (fViewId) { 322 case VIEW_ID_THREAD: 323 page= getViewer().getControl(); 324 page.setRedraw(false); 325 getViewer().refresh(); 326 ((TreeViewer)getViewer()).expandAll(); 327 page.setRedraw(true); 328 break; 329 case VIEW_ID_DEADLOCK: 330 if(MonitorManager.getDefault().getNumberOfDeadlocks() == 0 && MonitorManager.getDefault().getThreads().length > 0) { 331 showMessage(MonitorMessages.getString("MonitorsView.3")); showPage= false; 333 break; 334 } 335 changeFromShowMessagePage= true; 336 page= getDeadLocksViewer().getControl(); 337 page.setRedraw(false); 338 getDeadLocksViewer().refresh(); 339 ((TreeViewer)getDeadLocksViewer()).expandAll(); 340 page.setRedraw(true); 341 break; 342 case VIEW_ID_MONITOR: 343 page= getMonitorsViewer().getControl(); 344 page.setRedraw(false); 345 getMonitorsViewer().refresh(); 346 ((TreeViewer)getMonitorsViewer()).expandAll(); 347 page.setRedraw(true); 348 break; 349 } 350 if ((showPage | changeFromShowMessagePage) && page != null) { 351 getPageBook().showPage(page); 352 } 353 updateObjects(); 354 } 355 356 359 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 360 if (selection instanceof IStructuredSelection) { 361 IStructuredSelection structuredSelection= (IStructuredSelection)selection; 362 Set targets= new HashSet (); 363 for (Iterator iter= structuredSelection.iterator(); iter.hasNext();) { 364 Object element= iter.next(); 365 if (element instanceof JDIDebugElement) { 366 targets.add(((JDIDebugElement)element).getDebugTarget()); 367 } 368 } 369 if (targets.size() == 1) { 370 final IJavaDebugTarget debugTarget= (IJavaDebugTarget)targets.toArray()[0]; 371 if (debugTarget != fLastSelectedTarget || !fValidSelection) { 372 Job job = new Job(MonitorMessages.getString("MonitorsView.4")) { protected IStatus run(IProgressMonitor monitor) { 374 final boolean monitorInformationAvailable= debugTarget.supportsMonitorInformation(); 375 if (monitorInformationAvailable) { 376 MonitorManager.getDefault().updatePartial(debugTarget); 377 } 378 fValidSelection= true; 379 Display.getDefault().asyncExec(new Runnable () { 380 public void run() { 381 refreshCurrentViewer(monitorInformationAvailable, true); 382 fLastSelectedTarget= debugTarget; 383 } 384 }); 385 386 return Status.OK_STATUS; 387 } 388 }; 389 IWorkbenchSiteProgressService progressService = (IWorkbenchSiteProgressService) getSite().getAdapter(IWorkbenchSiteProgressService.class); 390 job.setSystem(true); 391 if (progressService == null) { 392 job.schedule(); 393 } else { 394 progressService.schedule(job); 395 } 396 } 397 return; 398 } 399 } 400 if (fValidSelection) { 401 Display.getDefault().asyncExec(new Runnable () { 402 public void run() { 403 fValidSelection= false; 404 refreshCurrentViewer(false, true); 405 } 406 }); 407 } 408 } 409 410 413 public void dispose() { 414 getSite().getPage().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this); 415 super.dispose(); 416 } 417 418 } 419 | Popular Tags |