KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.debug.internal.ui.views.launch;
12
13  
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.DebugPlugin;
16 import org.eclipse.debug.core.ILaunch;
17 import org.eclipse.debug.core.ILaunchManager;
18 import org.eclipse.debug.core.model.IDebugElement;
19 import org.eclipse.debug.core.model.IDebugTarget;
20 import org.eclipse.debug.core.model.IProcess;
21 import org.eclipse.debug.core.model.IStackFrame;
22 import org.eclipse.debug.core.model.IThread;
23 import org.eclipse.debug.internal.ui.DebugUIPlugin;
24 import org.eclipse.jface.viewers.ITreeContentProvider;
25 import org.eclipse.jface.viewers.Viewer;
26
27 /**
28  * Provides content for the launch view.
29  */

30 public class LaunchViewContentProvider implements ITreeContentProvider {
31
32     /**
33      * @see ITreeContentProvider#getChildren(Object)
34      */

35     public Object JavaDoc[] getChildren(Object JavaDoc parent) {
36         try {
37             if (parent instanceof IDebugTarget) {
38                 return ((IDebugTarget)parent).getThreads();
39             }
40             if (parent instanceof IThread) {
41                 return ((IThread)parent).getStackFrames();
42             }
43         } catch (DebugException e) {
44             DebugUIPlugin.log(e);
45         }
46         if (parent instanceof ILaunch) {
47             return ((ILaunch)parent).getChildren();
48         }
49         if (parent instanceof ILaunchManager) {
50             return ((ILaunchManager) parent).getLaunches();
51         }
52         return new Object JavaDoc[0];
53     }
54
55     /**
56      * @see ITreeContentProvider#getParent(Object)
57      */

58     public Object JavaDoc getParent(Object JavaDoc element) {
59         if (element instanceof IStackFrame) {
60             return ((IStackFrame)element).getThread();
61         }
62         if (element instanceof IThread) {
63             return ((IThread)element).getDebugTarget();
64         }
65         if (element instanceof IDebugTarget) {
66             return ((IDebugElement)element).getLaunch();
67         }
68         if (element instanceof IProcess) {
69             return ((IProcess)element).getLaunch();
70         }
71         if (element instanceof ILaunch) {
72             return DebugPlugin.getDefault().getLaunchManager();
73         }
74         return null;
75     }
76
77     /**
78      * @see ITreeContentProvider#hasChildren(Object)
79      */

80     public boolean hasChildren(Object JavaDoc element) {
81         if (element instanceof IStackFrame) {
82             return false;
83         }
84         if (element instanceof IDebugTarget) {
85             try {
86                 return ((IDebugTarget)element).hasThreads();
87             } catch (DebugException e) {
88                 return false;
89             }
90         }
91         if (element instanceof IThread) {
92             try {
93                 return ((IThread)element).hasStackFrames();
94             } catch (DebugException e) {
95                 return false;
96             }
97         }
98         if (element instanceof IProcess) {
99             return false;
100         }
101         if (element instanceof ILaunch) {
102             return ((ILaunch)element).hasChildren();
103         }
104         if (element instanceof ILaunchManager) {
105             return ((ILaunchManager) element).getLaunches().length > 0;
106         }
107         return false;
108     }
109
110     /**
111      * @see IStructuredContentProvider#getElements(Object)
112      */

113     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
114         return getChildren(inputElement);
115     }
116
117     /**
118      * Nothing to dispose.
119      *
120      * @see IContentProvider#dispose()
121      */

122     public void dispose() {
123     }
124
125     /**
126      * @see IContentProvider#inputChanged(Viewer, Object, Object)
127      */

128     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
129     }
130
131 }
132
Popular Tags