KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2006 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.internal.ui.viewers.provisional.AsynchronousContentAdapter;
15 import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
16 import org.eclipse.debug.ui.IDebugUIConstants;
17 import org.eclipse.jdt.debug.core.IJavaThread;
18 import org.eclipse.jdt.debug.core.IJavaThreadGroup;
19
20 /**
21  * Content adapter for thread groups.
22  *
23  * @since 3.2
24  */

25 public class JavaThreadGroupContentAdapter extends AsynchronousContentAdapter {
26
27     protected Object JavaDoc[] getChildren(Object JavaDoc parent, IPresentationContext context) throws CoreException {
28         if (parent instanceof IJavaThreadGroup) {
29             IJavaThreadGroup group = (IJavaThreadGroup) parent;
30             IJavaThreadGroup[] threadGroups = group.getThreadGroups();
31             IJavaThread[] threads = group.getThreads();
32             Object JavaDoc[] kids = new Object JavaDoc[threadGroups.length + threads.length];
33             int index = 0;
34             for (int i = 0; i < threads.length; i++) {
35                 kids[index]= threads[i];
36                 index++;
37             }
38             for (int i = 0; i < threadGroups.length; i++) {
39                 kids[index] = threadGroups[i];
40                 index++;
41             }
42             return kids;
43         }
44         return EMPTY;
45     }
46
47     protected boolean hasChildren(Object JavaDoc element, IPresentationContext context) throws CoreException {
48         if (element instanceof IJavaThreadGroup) {
49             IJavaThreadGroup group = (IJavaThreadGroup) element;
50             return group.hasThreads() || group.hasThreadGroups();
51         }
52         return false;
53     }
54
55     protected boolean supportsPartId(String JavaDoc id) {
56         return IDebugUIConstants.ID_DEBUG_VIEW.equals(id);
57     }
58
59 }
60
Popular Tags