1 11 package org.eclipse.jdt.internal.debug.ui.monitors; 12 13 14 import org.eclipse.jdt.debug.core.IJavaObject; 15 import org.eclipse.jdt.debug.core.IJavaThread; 16 import org.eclipse.jface.viewers.ITreeContentProvider; 17 import org.eclipse.jface.viewers.TreeViewer; 18 import org.eclipse.jface.viewers.Viewer; 19 20 23 public class ThreadsViewContentProvider implements ITreeContentProvider { 24 25 29 public class MonitorWrapper{ 30 public static final int OWNED_MONITOR = 1; 31 public static final int CONTENDED_MONITOR = 2; 32 public IJavaObject monitor; 33 public int state; 34 } 35 36 40 public class ThreadWrapper{ 41 public IJavaThread thread; 42 public boolean isCaughtInDeadlock; 43 } 44 45 protected TreeViewer fViewer= null; 46 47 50 public Object [] getChildren(Object parentElement) { 51 52 if (parentElement instanceof ThreadWrapper) { 54 IJavaThread thread= ((ThreadWrapper)parentElement).thread; 55 56 IJavaObject[] ownedMonitors= MonitorManager.getDefault().getOwnedMonitors(thread); 58 59 IJavaObject contendedMonitor= MonitorManager.getDefault().getContendedMonitor(thread); 61 if (ownedMonitors == null && contendedMonitor == null) { 62 return null; 63 } 64 65 int size= 0; 67 if (ownedMonitors != null) { 68 size= ownedMonitors.length; 69 } 70 if (contendedMonitor != null) { 71 size= size + 1; 72 } 73 Object [] children= new Object [size]; 75 if (ownedMonitors != null) { 76 for (int i = 0; i < ownedMonitors.length; i++) { 77 MonitorWrapper mw = new MonitorWrapper(); 78 mw.monitor = ownedMonitors[i]; 79 mw.state = MonitorWrapper.OWNED_MONITOR; 80 children[i]= mw; 81 } 82 } 83 if (contendedMonitor != null) { 84 MonitorWrapper mw = new MonitorWrapper(); 85 mw.monitor = contendedMonitor; 86 mw.state = MonitorWrapper.CONTENDED_MONITOR; 87 children[children.length - 1]= mw; 88 } 89 return children; 90 } 91 92 return null; 93 } 94 95 98 public Object getParent(Object element) { 99 100 if (element instanceof IJavaThread) { 101 return MonitorManager.getDefault().getOwnedMonitors((IJavaThread)element); 102 } else if (element instanceof IJavaObject) { 103 return MonitorManager.getDefault().getOwningThread((IJavaObject)element); 104 } 105 return null; 106 } 107 108 111 public boolean hasChildren(Object element) { 112 113 if (element instanceof IJavaThread) { 114 IJavaThread thread= (IJavaThread)element; 115 IJavaObject[] ownedMonitors= MonitorManager.getDefault().getOwnedMonitors(thread); 116 IJavaObject contendedMonitor= MonitorManager.getDefault().getContendedMonitor(thread); 117 if (ownedMonitors == null && contendedMonitor == null) { 118 return false; 119 } else { 120 return true; 121 } 122 } 123 return false; 124 } 125 126 129 public Object [] getElements(Object inputElement) { 130 131 IJavaThread[] allThreads= MonitorManager.getDefault().getThreads(); 133 Object [] res = new Object [allThreads.length]; 134 for (int i = 0; i < allThreads.length; i++) { 135 ThreadWrapper tw = new ThreadWrapper(); 136 tw.thread= allThreads[i]; 137 if(MonitorManager.getDefault().isCaughtInDeadlock(allThreads[i])) { 138 tw.isCaughtInDeadlock = true; 139 } else { 140 tw.isCaughtInDeadlock = false; 141 } 142 res[i] = tw; 143 } 144 return res; 145 } 146 147 150 public void dispose() { 151 fViewer= null; 152 } 153 154 157 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 158 fViewer= (TreeViewer)viewer; 159 } 160 } 161 | Popular Tags |