1 11 package org.eclipse.jdt.internal.debug.ui.monitors; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.jobs.ISchedulingRule; 15 import org.eclipse.debug.core.DebugException; 16 import org.eclipse.debug.core.model.IDebugElement; 17 import org.eclipse.debug.core.model.IStackFrame; 18 import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate; 19 import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; 20 import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate; 21 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 22 import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; 23 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 24 import org.eclipse.jdt.debug.core.IJavaThread; 25 import org.eclipse.jdt.debug.ui.JavaDebugUtils; 26 import org.eclipse.jdt.internal.debug.core.model.JDIThread; 27 28 33 public class JavaThreadContentProvider extends JavaElementContentProvider { 34 35 38 protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 39 IJavaThread thread = (IJavaThread)element; 40 if (!thread.isSuspended()) { 41 return 0; 42 } 43 int childCount = thread.getFrameCount(); 44 if (isDisplayMonitors()) { 45 if (((IJavaDebugTarget) thread.getDebugTarget()).supportsMonitorInformation()) { 46 childCount+= thread.getOwnedMonitors().length; 47 if (thread.getContendedMonitor() != null) { 48 childCount++; 49 } 50 } else { 51 childCount++; 53 } 54 } 55 return childCount; 56 } 57 58 61 protected Object [] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 62 IJavaThread thread = (IJavaThread)parent; 63 if (!thread.isSuspended()) { 64 return EMPTY; 65 } 66 return getElements(getChildren(thread), index, length); 67 } 68 69 protected Object [] getChildren(IJavaThread thread) { 70 try { 71 IStackFrame[] frames = thread.getStackFrames(); 72 if (!isDisplayMonitors()) { 73 return frames; 74 } 75 76 Object [] children; 77 int length = frames.length; 78 if (((IJavaDebugTarget) thread.getDebugTarget()).supportsMonitorInformation()) { 79 IDebugElement[] ownedMonitors = JavaDebugUtils.getOwnedMonitors(thread); 80 IDebugElement contendedMonitor = JavaDebugUtils.getContendedMonitor(thread); 81 82 if (ownedMonitors != null) { 83 length += ownedMonitors.length; 84 } 85 if (contendedMonitor != null) { 86 length++; 87 } 88 children = new Object [length]; 89 if (ownedMonitors != null && ownedMonitors.length > 0) { 90 System.arraycopy(ownedMonitors, 0, children, 0, ownedMonitors.length); 91 } 92 if (contendedMonitor != null) { 93 children[ownedMonitors.length] = contendedMonitor; 95 } 96 } else { 97 children = new Object [length + 1]; 98 children[0] = new NoMonitorInformationElement(thread.getDebugTarget()); 99 } 100 int offset = children.length - frames.length; 101 System.arraycopy(frames, 0, children, offset, frames.length); 102 return children; 103 } catch (DebugException e) { 104 return EMPTY; 105 } 106 } 107 108 111 protected boolean hasChildren(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 112 return ((IJavaThread)element).hasStackFrames() || 113 (isDisplayMonitors() && ((IJavaThread)element).hasOwnedMonitors()); 114 } 115 116 119 protected ISchedulingRule getRule(IChildrenCountUpdate[] updates) { 120 return getThreadRule(updates); 121 } 122 123 126 protected ISchedulingRule getRule(IChildrenUpdate[] updates) { 127 return getThreadRule(updates); 128 } 129 130 133 protected ISchedulingRule getRule(IHasChildrenUpdate[] updates) { 134 return getThreadRule(updates); 135 } 136 137 145 private ISchedulingRule getThreadRule(IViewerUpdate[] updates) { 146 if (updates.length > 0) { 147 Object element = updates[0].getElement(); 148 if (element instanceof JDIThread) { 149 return ((JDIThread)element).getThreadRule(); 150 } 151 } 152 return null; 153 } 154 155 156 } 157 | Popular Tags |