KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > threadgroups > JavaThreadGroupContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
22  * @since 3.3
23  */

24 public class JavaThreadGroupContentProvider extends JavaElementContentProvider {
25
26     /* (non-Javadoc)
27      * @see org.eclipse.debug.internal.ui.viewers.model.provisional.elements.ElementContentProvider#getChildCount(java.lang.Object, org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext)
28      */

29     protected int getChildCount(Object JavaDoc 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     /* (non-Javadoc)
42      * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#getChildren(java.lang.Object, int, int, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.core.runtime.IProgressMonitor)
43      */

44     protected Object JavaDoc[] getChildren(Object JavaDoc 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 JavaDoc[] getChildren(IJavaThreadGroup group) throws CoreException {
52         if (isAvailable(group)) {
53             IJavaThreadGroup[] threadGroups = group.getThreadGroups();
54             IJavaThread[] threads = group.getThreads();
55             Object JavaDoc[] kids = new Object JavaDoc[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