1 11 package org.eclipse.jdt.internal.debug.ui.threadgroups; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.debug.core.model.IDebugTarget; 15 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 16 import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; 17 import org.eclipse.jdt.debug.core.IJavaThread; 18 import org.eclipse.jdt.debug.core.IJavaThreadGroup; 19 import org.eclipse.jdt.internal.debug.ui.monitors.JavaElementContentProvider; 20 21 24 public class JavaThreadGroupContentProvider extends JavaElementContentProvider { 25 26 29 protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 30 int count = 0; 31 if (element instanceof IJavaThreadGroup) { 32 IJavaThreadGroup group = (IJavaThreadGroup) element; 33 if (isAvailable(group)) { 34 count += group.getThreadGroups().length; 35 count += group.getThreads().length; 36 } 37 } 38 return count; 39 } 40 41 44 protected Object [] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 45 if (parent instanceof IJavaThreadGroup) { 46 return getElements(getChildren((IJavaThreadGroup) parent), index, length); 47 } 48 return EMPTY; 49 } 50 51 protected Object [] getChildren(IJavaThreadGroup group) throws CoreException { 52 if (isAvailable(group)) { 53 IJavaThreadGroup[] threadGroups = group.getThreadGroups(); 54 IJavaThread[] threads = group.getThreads(); 55 Object [] kids = new Object [threadGroups.length + threads.length]; 56 int index = 0; 57 for (int i = 0; i < threads.length; i++) { 58 kids[index]= threads[i]; 59 index++; 60 } 61 for (int i = 0; i < threadGroups.length; i++) { 62 kids[index] = threadGroups[i]; 63 index++; 64 } 65 return kids; 66 } 67 return EMPTY; 68 } 69 70 protected boolean isAvailable(IJavaThreadGroup group) { 71 IDebugTarget debugTarget = group.getDebugTarget(); 72 return !(debugTarget.isTerminated() || debugTarget.isDisconnected()); 73 } 74 75 } 76 | Popular Tags |