KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > elements > adapters > DeferredStackFrame


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.elements.adapters;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.model.IStackFrame;
16 import org.eclipse.debug.core.model.IValue;
17 import org.eclipse.debug.core.model.IVariable;
18 import org.eclipse.debug.internal.ui.views.variables.RemoteVariableContentManager;
19 import org.eclipse.debug.ui.DeferredDebugElementWorkbenchAdapter;
20 import org.eclipse.ui.progress.IElementCollector;
21
22
23 /**
24  * Default deferred workbench adapter for a stack frame
25  */

26 public class DeferredStackFrame extends DeferredDebugElementWorkbenchAdapter {
27     
28     /* (non-Javadoc)
29      * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
30      */

31     public Object JavaDoc[] getChildren(Object JavaDoc parent) {
32         if (parent instanceof IStackFrame) {
33             IStackFrame frame = (IStackFrame) parent;
34             try {
35                 return frame.getVariables();
36             } catch (DebugException e) {
37                 return new Object JavaDoc[]{e};
38             }
39         }
40         return EMPTY;
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
45      */

46     public Object JavaDoc getParent(Object JavaDoc element) {
47         return ((IStackFrame)element).getThread();
48     }
49     
50     /* (non-Javadoc)
51      * @see org.eclipse.ui.progress.IDeferredWorkbenchAdapter#fetchDeferredChildren(java.lang.Object, org.eclipse.ui.progress.IElementCollector, org.eclipse.core.runtime.IProgressMonitor)
52      */

53     public void fetchDeferredChildren(Object JavaDoc object, IElementCollector collector, IProgressMonitor monitor) {
54         if (monitor.isCanceled()) {
55             return;
56         }
57         Object JavaDoc[] children = getChildren(object);
58         if (monitor.isCanceled()) {
59             return;
60         }
61         if (children.length > 0) {
62             if (collector instanceof RemoteVariableContentManager.VariableCollector) {
63                 RemoteVariableContentManager.VariableCollector remoteCollector = (RemoteVariableContentManager.VariableCollector) collector;
64                 for (int i = 0; i < children.length; i++) {
65                     if (monitor.isCanceled()) {
66                         return;
67                     }
68                     Object JavaDoc child = children[i];
69                     remoteCollector.setHasChildren(child, hasChildren(child));
70                 }
71             }
72             collector.add(children, monitor);
73         }
74         collector.done();
75     }
76     
77     /**
78      * Returns whether the given child has children.
79      * Subclasses should override for different type of children.
80      *
81      * @param child child fetched from getChildren()
82      * @return whether the given child has children
83      */

84     protected boolean hasChildren(Object JavaDoc child) {
85         if (child instanceof IVariable) {
86             IVariable variable = (IVariable) child;
87             try {
88                 IValue value = variable.getValue();
89                 return value.hasVariables();
90             } catch (DebugException e) {
91             }
92         }
93         return false;
94     }
95
96 }
97
Popular Tags