KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2006 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 org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.core.model.IValue;
16 import org.eclipse.debug.core.model.IVariable;
17 import org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter;
18 import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
19 import org.eclipse.jdt.debug.core.IJavaValue;
20 import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
21 import org.eclipse.jdt.internal.debug.ui.DebugUIMessages;
22 import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
23 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
24 import org.eclipse.jdt.internal.debug.ui.JDIModelPresentation;
25 import org.eclipse.ui.IWorkbenchPart;
26
27 /**
28  * @since 3.2
29  *
30  */

31 public class JavaVariableLabelAdapter extends VariableLabelAdapter {
32     
33     public static JDIModelPresentation fLabelProvider = new JDIModelPresentation();
34     
35     /* (non-Javadoc)
36      * @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getValueText(org.eclipse.debug.core.model.IVariable, org.eclipse.debug.core.model.IValue)
37      */

38     protected String JavaDoc getValueText(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
39         if (value instanceof IJavaValue) {
40             return escapeSpecialChars(fLabelProvider.getFormattedValueText((IJavaValue) value));
41         }
42         return super.getValueText(variable, value, context);
43     }
44
45     /* (non-Javadoc)
46      * @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getValueTypeName(org.eclipse.debug.core.model.IVariable, org.eclipse.debug.core.model.IValue)
47      */

48     protected String JavaDoc getValueTypeName(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
49         String JavaDoc typeName= DebugUIMessages.JDIModelPresentation_unknown_type__2;
50         try {
51             typeName = value.getReferenceTypeName();
52             if (!isShowQualfiiedNames(context)) {
53                 return fLabelProvider.removeQualifierFromGenericName(typeName);
54             }
55         } catch (DebugException e) {}
56         return typeName;
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter#getVariableTypeName(org.eclipse.debug.core.model.IVariable)
61      */

62     protected String JavaDoc getVariableTypeName(IVariable variable, IPresentationContext context) throws CoreException {
63         String JavaDoc typeName= DebugUIMessages.JDIModelPresentation_unknown_type__2;
64         try {
65             typeName = variable.getReferenceTypeName();
66             if (!isShowQualfiiedNames(context)) {
67                 return fLabelProvider.removeQualifierFromGenericName(typeName);
68             }
69         } catch (DebugException e) {}
70         return typeName;
71     }
72
73     private boolean isShowQualfiiedNames(IPresentationContext context) {
74         IWorkbenchPart part = context.getPart();
75         if (part != null) {
76             return JDIDebugUIPlugin.getDefault().getPluginPreferences().getBoolean(part.getSite().getId() + "." + IJDIPreferencesConstants.PREF_SHOW_QUALIFIED_NAMES); //$NON-NLS-1$
77
}
78         return false;
79     }
80
81     /* (non-Javadoc)
82      * @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)
83      */

84     protected String JavaDoc getColumnText(IVariable variable, IValue value, String JavaDoc columnId, IPresentationContext context) throws CoreException {
85         if (JavaVariableColumnPresentation.COLUMN_INSTANCE_ID.equals(columnId)) {
86             if (value instanceof JDIObjectValue) {
87                 long uniqueId = ((JDIObjectValue)value).getUniqueId();
88                 StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
89                 buffer.append(uniqueId);
90                 return buffer.toString();
91             } else {
92                 return ""; //$NON-NLS-1$
93
}
94         }
95         return super.getColumnText(variable, value, columnId, context);
96     }
97     
98     
99
100 }
101
Popular Tags