KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > expression > ExpressionViewContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 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.expression;
12
13
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.DebugPlugin;
16 import org.eclipse.debug.core.IExpressionManager;
17 import org.eclipse.debug.core.model.IErrorReportingExpression;
18 import org.eclipse.debug.core.model.IExpression;
19 import org.eclipse.debug.core.model.IValue;
20 import org.eclipse.debug.core.model.IVariable;
21 import org.eclipse.debug.internal.ui.DebugUIPlugin;
22 import org.eclipse.debug.internal.ui.views.variables.VariablesViewContentProvider;
23 import org.eclipse.debug.ui.IDebugView;
24  
25 /**
26  * Provides contents for the expression view
27  */

28 public class ExpressionViewContentProvider extends VariablesViewContentProvider {
29
30     public ExpressionViewContentProvider(IDebugView view) {
31         super(view);
32     }
33
34     /**
35      * @see ITreeContentProvider#getChildren(Object)
36      */

37     public Object JavaDoc[] getChildren(Object JavaDoc parent) {
38         Object JavaDoc[] children= null;
39         try {
40             if (parent instanceof IExpressionManager) {
41                 // do not cache parents
42
return ((IExpressionManager)parent).getExpressions();
43             } else if (parent instanceof IExpression) {
44                 if (parent instanceof IErrorReportingExpression) {
45                     IErrorReportingExpression expression= (IErrorReportingExpression) parent;
46                     if (expression.hasErrors()) {
47                         children= expression.getErrorMessages();
48                     }
49                 }
50                 if (children == null) {
51                     IExpression expression = (IExpression)parent;
52                     IValue value = expression.getValue();
53                     children = getModelSpecificChildren(expression, value);
54                 }
55             } else if (parent instanceof IVariable) {
56                 IVariable variable = (IVariable)parent;
57                 IValue value = variable.getValue();
58                 children = getModelSpecificChildren(variable, value);
59             }
60             if (children != null) {
61                 cache(parent, children);
62                 return children;
63             }
64         } catch (DebugException de) {
65             DebugUIPlugin.log(de);
66         }
67         return new Object JavaDoc[0];
68     }
69     
70     /**
71      * @see ITreeContentProvider#getParent(Object)
72      */

73     public Object JavaDoc getParent(Object JavaDoc item) {
74         if (item instanceof IExpression) {
75             return DebugPlugin.getDefault().getExpressionManager();
76         }
77         return super.getParent(item);
78     }
79     
80     /**
81      * @see ITreeContentProvider#hasChildren(Object)
82      */

83     public boolean hasChildren(Object JavaDoc element) {
84         if (element instanceof IExpressionManager) {
85             return ((IExpressionManager)element).hasExpressions();
86         } else if (element instanceof IExpression) {
87             if (element instanceof IErrorReportingExpression && ((IErrorReportingExpression) element).hasErrors()) {
88                 return true;
89             }
90             IValue v = ((IExpression)element).getValue();
91             if (v == null) {
92                 return false;
93             }
94             try {
95                 return v.hasVariables();
96             } catch (DebugException e) {
97                 DebugUIPlugin.log(e);
98                 return false;
99             }
100         }
101         return super.hasChildren(element);
102     }
103 }
104
Popular Tags