KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > launch > DebugViewContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.debug.internal.ui.views.launch;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.ILaunch;
16 import org.eclipse.debug.core.ILaunchManager;
17 import org.eclipse.debug.core.model.IDebugTarget;
18 import org.eclipse.debug.core.model.IProcess;
19 import org.eclipse.debug.core.model.IStackFrame;
20 import org.eclipse.debug.core.model.IThread;
21 import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager;
22 import org.eclipse.ui.IWorkbenchPartSite;
23 import org.eclipse.ui.model.BaseWorkbenchContentProvider;
24 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
25
26 /**
27  * Provides deferred content for the debug view.
28  * @since 3.1
29  */

30 public class DebugViewContentProvider extends BaseWorkbenchContentProvider {
31     
32     private RemoteTreeContentManager fManager;
33     
34     public DebugViewContentProvider(LaunchViewer tree, IWorkbenchPartSite site) {
35         fManager = new RemoteTreeContentManager(this, tree, site);
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
40      */

41     public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
42         if (parentElement instanceof IStackFrame) {
43             return null;
44         }
45         Object JavaDoc[] children = fManager.getChildren(parentElement);
46         if (children == null) {
47             children = super.getChildren(parentElement);
48         }
49         return children;
50     }
51     
52     /* (non-Javadoc)
53      * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
54      */

55     public boolean hasChildren(Object JavaDoc element) {
56         if (element instanceof IStackFrame) {
57             return false;
58         }
59         if (element instanceof IDebugTarget) {
60             try {
61                 return ((IDebugTarget)element).hasThreads();
62             } catch (DebugException e) {
63                 return false;
64             }
65         }
66         if (element instanceof IThread) {
67             try {
68                 return ((IThread)element).hasStackFrames();
69             } catch (DebugException e) {
70                 return false;
71             }
72         }
73         if (element instanceof IProcess) {
74             return false;
75         }
76         if (element instanceof ILaunch) {
77             return ((ILaunch)element).hasChildren();
78         }
79         if (element instanceof ILaunchManager) {
80             return ((ILaunchManager) element).getLaunches().length > 0;
81         }
82         if (element instanceof IAdaptable) {
83             IAdaptable adaptable = (IAdaptable) element;
84             IDeferredWorkbenchAdapter adapter = (IDeferredWorkbenchAdapter) adaptable.getAdapter(IDeferredWorkbenchAdapter.class);
85             if (adapter != null) {
86                 return adapter.isContainer();
87             }
88         }
89         return super.hasChildren(element);
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.jface.viewers.IContentProvider#dispose()
94      */

95     public void dispose() {
96         fManager.cancel();
97         super.dispose();
98     }
99
100 }
101
Popular Tags