KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.model.IValue;
15 import org.eclipse.debug.core.model.IVariable;
16 import org.eclipse.debug.internal.ui.DebugUIPlugin;
17 import org.eclipse.debug.internal.ui.DefaultLabelProvider;
18 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19 import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnPresentation;
20 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
21 import org.eclipse.debug.ui.IDebugUIConstants;
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.jface.resource.JFaceResources;
24 import org.eclipse.jface.viewers.TreePath;
25 import org.eclipse.swt.graphics.FontData;
26 import org.eclipse.swt.graphics.RGB;
27
28 /**
29  * Provides context sensitive labels for debug variables.
30  *
31  * @since 3.3
32  */

33 public class VariableLabelProvider extends DebugElementLabelProvider {
34
35     /* (non-Javadoc)
36      * @see org.eclipse.debug.internal.ui.model.elements.DebugElementLabelProvider#getBackground(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String)
37      */

38     protected RGB getBackground(TreePath elementPath, IPresentationContext presentationContext, String JavaDoc columnId) throws CoreException {
39         Object JavaDoc element = elementPath.getLastSegment();
40         if (columnId != null) {
41             if (element instanceof IVariable) {
42                 IVariable variable = (IVariable) element;
43                 if (variable.hasValueChanged()) {
44                     return DebugUIPlugin.getPreferenceColor(IInternalDebugUIConstants.PREF_CHANGED_VALUE_BACKGROUND).getRGB();
45                 }
46             }
47         }
48         return super.getBackground(elementPath, presentationContext, columnId);
49     }
50
51     /* (non-Javadoc)
52      * @see org.eclipse.debug.internal.ui.model.elements.DebugElementLabelProvider#getForeground(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String)
53      */

54     protected RGB getForeground(TreePath elementPath, IPresentationContext presentationContext, String JavaDoc columnId) throws CoreException {
55         Object JavaDoc element = elementPath.getLastSegment();
56         if (columnId == null) {
57             if (element instanceof IVariable) {
58                 IVariable variable = (IVariable) element;
59                 if (variable.hasValueChanged()) {
60                     return DebugUIPlugin.getPreferenceColor(IDebugUIConstants.PREF_CHANGED_DEBUG_ELEMENT_COLOR).getRGB();
61                 }
62             }
63         }
64         return super.getForeground(elementPath, presentationContext, columnId);
65     }
66
67     /* (non-Javadoc)
68      * @see org.eclipse.debug.internal.ui.model.elements.DebugElementLabelProvider#getImageDescriptor(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String)
69      */

70     protected ImageDescriptor getImageDescriptor(TreePath elementPath, IPresentationContext presentationContext, String JavaDoc columnId) throws CoreException {
71         if (columnId == null || VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(columnId)) {
72             return super.getImageDescriptor(elementPath, presentationContext, columnId);
73         }
74         return null;
75     }
76
77     /* (non-Javadoc)
78      * @see org.eclipse.debug.internal.ui.model.elements.DebugElementLabelProvider#getFontData(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String)
79      */

80     protected FontData getFontData(TreePath elementPath, IPresentationContext presentationContext, String JavaDoc columnId) throws CoreException {
81         return JFaceResources.getFontDescriptor(IInternalDebugUIConstants.VARIABLE_TEXT_FONT).getFontData()[0];
82     }
83     
84     /* (non-Javadoc)
85      * @see org.eclipse.debug.internal.ui.model.elements.DebugElementLabelProvider#getLabel(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String)
86      */

87     protected String JavaDoc getLabel(TreePath elementPath, IPresentationContext context, String JavaDoc columnId) throws CoreException {
88         if (columnId == null) {
89             return super.getLabel(elementPath, context, columnId);
90         } else {
91             IVariable variable = (IVariable) elementPath.getLastSegment();
92             IValue value = variable.getValue();
93             return getColumnText(variable, value, context, columnId);
94         }
95     }
96     
97     /**
98      * Returns text for a specific columns for the variable/value.
99      *
100      * @param variable variable to retrieve text for
101      * @param value the value associated with the variable
102      * @param context presentation context specifying how to display the text
103      * @param columnId the column to get the text for
104      * @return the label text
105      * @throws CoreException
106      */

107     protected String JavaDoc getColumnText(IVariable variable, IValue value, IPresentationContext context, String JavaDoc columnId) throws CoreException {
108         if (VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(columnId)) {
109             return getVariableName(variable, context);
110         } else if (VariableColumnPresentation.COLUMN_VARIABLE_TYPE.equals(columnId)) {
111             return getVariableTypeName(variable, context);
112         } else if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(columnId)) {
113             return getValueText(variable, value, context);
114         } else if (VariableColumnPresentation.COLUMN_VALUE_TYPE.equals(columnId)) {
115             return getValueTypeName(variable, value, context);
116         }
117         return null;
118     }
119
120     /**
121      * Returns the name of the given variable to display in <code>COLUMN_VARIABLE_NAME</code>.
122      *
123      * @param variable
124      * @return variable name
125      * @throws CoreException
126      */

127     protected String JavaDoc getVariableName(IVariable variable, IPresentationContext context) throws CoreException {
128         return variable.getName();
129     }
130     
131     /**
132      * Returns the type name of the given variable to display in <code>COLUMN_VARIABLE_TYPE</code>.
133      *
134      * @param variable
135      * @return variable type name
136      * @throws CoreException
137      */

138     protected String JavaDoc getVariableTypeName(IVariable variable, IPresentationContext context) throws CoreException {
139         return variable.getReferenceTypeName();
140     }
141     
142     /**
143      * Returns the label for the given value's type to display in <code>COLUMN_VARIABLE_VALUE</code>
144      *
145      * @param variable
146      * @param value
147      * @return value label
148      * @throws CoreException
149      */

150     protected String JavaDoc getValueTypeName(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
151         return value.getReferenceTypeName();
152     }
153     
154     /**
155      * Returns the label for the given value to display in <code>COLUMN_VALUE_TYPE</code>
156      *
157      * @param variable
158      * @param value
159      * @return value label
160      * @throws CoreException
161      */

162     protected String JavaDoc getValueText(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
163         return escapeSpecialChars(value.getValueString());
164     }
165     
166     /**
167      * Escapes special characters using the default label provider
168      *
169      * @param label the text to escape
170      * @return the string with special characters escaped
171      */

172     protected String JavaDoc escapeSpecialChars(String JavaDoc label) {
173         return DefaultLabelProvider.escapeSpecialChars(label);
174     }
175 }
176
Popular Tags