1 11 package org.eclipse.jdt.internal.debug.ui.monitors; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.jdt.debug.core.IJavaObject; 18 import org.eclipse.jdt.debug.core.IJavaThread; 19 import org.eclipse.jface.viewers.ITreeContentProvider; 20 import org.eclipse.jface.viewers.TreeViewer; 21 import org.eclipse.jface.viewers.Viewer; 22 23 26 public class MonitorsViewContentProvider implements ITreeContentProvider { 27 28 protected TreeViewer fViewer= null; 29 30 34 public class ThreadWrapper{ 35 public static final int OWNING_THREAD = 1; 36 public static final int IN_CONTENTION_FOR_MONITOR = 2; 37 public IJavaThread thread; 38 public int state; 39 } 40 41 44 public Object [] getChildren(Object parentElement) { 45 46 if (parentElement instanceof IJavaObject) { 48 IJavaObject monitor= (IJavaObject)parentElement; 49 IJavaThread owningThread = MonitorManager.getDefault().getOwningThread(monitor); 51 52 List contendingThreads = MonitorManager.getDefault().getContendingThreads(monitor); 54 if (owningThread == null && contendingThreads == null) { 55 return null; 56 } 57 58 int size= 0; 60 if (contendingThreads != null) { 61 size= contendingThreads.size(); 62 } 63 if (owningThread != null) { 64 size= size + 1; 65 } 66 Object [] children= new Object [size]; 68 if (contendingThreads != null) { 69 List wrappedThreads = new ArrayList (); 70 for (int i = 0; i < contendingThreads.size(); i++) { 71 ThreadWrapper tw = new ThreadWrapper(); 72 tw.thread = (IJavaThread) contendingThreads.get(i); 73 tw.state = ThreadWrapper.IN_CONTENTION_FOR_MONITOR; 74 wrappedThreads.add(tw); 75 } 76 wrappedThreads.toArray(children); 77 wrappedThreads.toArray(children); 78 } 79 if (owningThread != null) { 80 ThreadWrapper tw = new ThreadWrapper(); 81 tw.thread = owningThread; 82 tw.state = ThreadWrapper.OWNING_THREAD; 83 children[children.length - 1] = tw; 84 } 85 return children; 86 } 87 88 return null; 89 } 90 91 94 public Object getParent(Object element) { 95 96 if (element instanceof IJavaThread) { 97 return MonitorManager.getDefault().getOwnedMonitors((IJavaThread)element); 98 } else if (element instanceof IJavaObject) { 99 return MonitorManager.getDefault().getOwningThread((IJavaObject)element); 100 } 101 return null; 102 } 103 104 107 public boolean hasChildren(Object element) { 108 109 if (element instanceof IJavaObject) { 110 IJavaObject monitor= (IJavaObject)element; 111 IJavaThread owningThread = MonitorManager.getDefault().getOwningThread(monitor); 112 List contendingThreads = MonitorManager.getDefault().getContendingThreads(monitor); 113 if (owningThread == null && contendingThreads == null) { 114 return false; 115 } else { 116 return true; 117 } 118 } 119 return false; 120 } 121 122 125 public Object [] getElements(Object inputElement) { 126 return MonitorManager.getDefault().getMonitors(); 127 } 128 129 132 public void dispose() { 133 fViewer= null; 134 } 135 136 139 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 140 fViewer= (TreeViewer)viewer; 141 } 142 } 143 | Popular Tags |