KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > model > elements > ExpressionContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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.model.elements;
12
13 import java.util.LinkedHashSet JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.debug.core.model.IErrorReportingExpression;
17 import org.eclipse.debug.core.model.IExpression;
18 import org.eclipse.debug.core.model.IValue;
19 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
20 import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
21
22 /**
23  * @since 3.3
24  */

25 public class ExpressionContentProvider extends VariableContentProvider {
26
27     protected Object JavaDoc[] getAllChildren(Object JavaDoc parent, IPresentationContext context) throws CoreException {
28        if (parent instanceof IErrorReportingExpression) {
29             IErrorReportingExpression expression = (IErrorReportingExpression) parent;
30             if (expression.hasErrors()) {
31                 String JavaDoc[] messages = expression.getErrorMessages();
32                 LinkedHashSet JavaDoc set = new LinkedHashSet JavaDoc(messages.length);
33                 for (int i = 0; i < messages.length; i++) {
34                     set.add(messages[i]);
35                 }
36                 return set.toArray();
37             }
38         }
39         if (parent instanceof IExpression) {
40             IExpression expression = (IExpression) parent;
41             IValue value = expression.getValue();
42             if (value != null) {
43                 return getValueChildren(expression, value, context);
44             }
45         }
46         return EMPTY;
47     }
48     
49     protected boolean hasChildren(Object JavaDoc element, IPresentationContext context, IViewerUpdate monitor) throws CoreException {
50         if (element instanceof IErrorReportingExpression) {
51             IErrorReportingExpression expression = (IErrorReportingExpression) element;
52             if (expression.hasErrors()) {
53                 return true;
54             }
55         }
56         IValue value = ((IExpression)element).getValue();
57         if (value == null) {
58             return false;
59         }
60         return value.hasVariables();
61     }
62 }
63
Popular Tags