KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > variables > JavaVariableLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 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.jdt.internal.debug.ui.variables;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
18 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
19 import org.eclipse.debug.core.DebugException;
20 import org.eclipse.debug.core.model.IValue;
21 import org.eclipse.debug.core.model.IVariable;
22 import org.eclipse.debug.internal.ui.model.elements.VariableLabelProvider;
23 import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
24 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
25 import org.eclipse.jdt.debug.core.IJavaValue;
26 import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
27 import org.eclipse.jdt.internal.debug.ui.DebugUIMessages;
28 import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
29 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
30 import org.eclipse.jdt.internal.debug.ui.JDIModelPresentation;
31
32 /**
33  * Base implementation of a label provider for Java variables
34  * @since 3.2
35  */

36 public class JavaVariableLabelProvider extends VariableLabelProvider implements IPropertyChangeListener {
37     
38     public static JDIModelPresentation fLabelProvider = new JDIModelPresentation();
39     /**
40      * Map of view id to qualified name setting
41      */

42     private Map JavaDoc fQualifiedNameSettings = new HashMap JavaDoc();
43     private boolean fQualifiedNames = false;
44     
45     public JavaVariableLabelProvider() {
46         JDIDebugUIPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(this);
47     }
48     
49     /* (non-Javadoc)
50      * @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getValueText(org.eclipse.debug.core.model.IVariable, org.eclipse.debug.core.model.IValue)
51      */

52     protected String JavaDoc getValueText(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
53         if (value instanceof IJavaValue) {
54             return escapeSpecialChars(fLabelProvider.getFormattedValueText((IJavaValue) value));
55         }
56         return super.getValueText(variable, value, context);
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getValueTypeName(org.eclipse.debug.core.model.IVariable, org.eclipse.debug.core.model.IValue)
61      */

62     protected String JavaDoc getValueTypeName(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
63         String JavaDoc typeName= DebugUIMessages.JDIModelPresentation_unknown_type__2;
64         try {
65             typeName = value.getReferenceTypeName();
66             if (!fQualifiedNames) {
67                 return fLabelProvider.removeQualifierFromGenericName(typeName);
68             }
69         } catch (DebugException e) {}
70         return typeName;
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getVariableTypeName(org.eclipse.debug.core.model.IVariable)
75      */

76     protected String JavaDoc getVariableTypeName(IVariable variable, IPresentationContext context) throws CoreException {
77         String JavaDoc typeName= DebugUIMessages.JDIModelPresentation_unknown_type__2;
78         try {
79             typeName = variable.getReferenceTypeName();
80             if (!fQualifiedNames) {
81                 return fLabelProvider.removeQualifierFromGenericName(typeName);
82             }
83         } catch (DebugException e) {}
84         return typeName;
85     }
86
87     /**
88      * Returns if the the specified presentation context is showing qualified names or not
89      * @param context
90      * @return true if the presentation context is showing qualified names, false otherwise
91      */

92     private Boolean JavaDoc isShowQualfiiedNames(IPresentationContext context) {
93         Boolean JavaDoc qualified = (Boolean JavaDoc) fQualifiedNameSettings.get(context.getId());
94         if (qualified == null) {
95             qualified = Boolean.valueOf(JDIDebugUIPlugin.getDefault().getPluginPreferences().getBoolean(context.getId() + '.' + IJDIPreferencesConstants.PREF_SHOW_QUALIFIED_NAMES));
96             fQualifiedNameSettings.put(context.getId(), qualified);
97         }
98         return qualified;
99     }
100
101     /* (non-Javadoc)
102      * @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getColumnText(org.eclipse.debug.core.model.IVariable, org.eclipse.debug.core.model.IValue, java.lang.String, org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext)
103      */

104     protected String JavaDoc getColumnText(IVariable variable, IValue value, IPresentationContext context, String JavaDoc columnId) throws CoreException {
105         if (JavaVariableColumnPresentation.COLUMN_INSTANCE_ID.equals(columnId)) {
106             if (value instanceof JDIObjectValue) {
107                 long uniqueId = ((JDIObjectValue)value).getUniqueId();
108                 if (uniqueId >= 0) {
109                     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
110                     buffer.append(uniqueId);
111                     return buffer.toString();
112                 }
113             }
114             return ""; //$NON-NLS-1$
115
}
116         return super.getColumnText(variable, value, context, columnId);
117     }
118
119     /**
120      * Sets qualified name setting before building label
121      */

122     protected void retrieveLabel(ILabelUpdate update) throws CoreException {
123         Boolean JavaDoc showQ = isShowQualfiiedNames(update.getPresentationContext());
124         fQualifiedNames = showQ.booleanValue();
125         fLabelProvider.setAttribute(JDIModelPresentation.DISPLAY_QUALIFIED_NAMES, showQ);
126         super.retrieveLabel(update);
127     }
128
129     /* (non-Javadoc)
130      * @see org.eclipse.core.runtime.Preferences$IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
131      */

132     public void propertyChange(PropertyChangeEvent event) {
133         if (event.getProperty().endsWith(IJDIPreferencesConstants.PREF_SHOW_QUALIFIED_NAMES)) {
134             fQualifiedNameSettings.clear();
135         }
136     }
137
138     /* (non-Javadoc)
139      * @see org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider#requiresUIJob(org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate[])
140      */

141     protected boolean requiresUIJob(ILabelUpdate[] updates) {
142         return !JDIModelPresentation.isInitialized();
143     }
144     
145     
146
147 }
148
Popular Tags