1 11 package org.eclipse.jdt.internal.debug.ui.variables; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 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 36 public class JavaVariableLabelProvider extends VariableLabelProvider implements IPropertyChangeListener { 37 38 public static JDIModelPresentation fLabelProvider = new JDIModelPresentation(); 39 42 private Map fQualifiedNameSettings = new HashMap (); 43 private boolean fQualifiedNames = false; 44 45 public JavaVariableLabelProvider() { 46 JDIDebugUIPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(this); 47 } 48 49 52 protected String 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 62 protected String getValueTypeName(IVariable variable, IValue value, IPresentationContext context) throws CoreException { 63 String 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 76 protected String getVariableTypeName(IVariable variable, IPresentationContext context) throws CoreException { 77 String 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 92 private Boolean isShowQualfiiedNames(IPresentationContext context) { 93 Boolean qualified = (Boolean ) 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 104 protected String getColumnText(IVariable variable, IValue value, IPresentationContext context, String 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 buffer = new StringBuffer (); 110 buffer.append(uniqueId); 111 return buffer.toString(); 112 } 113 } 114 return ""; } 116 return super.getColumnText(variable, value, context, columnId); 117 } 118 119 122 protected void retrieveLabel(ILabelUpdate update) throws CoreException { 123 Boolean showQ = isShowQualfiiedNames(update.getPresentationContext()); 124 fQualifiedNames = showQ.booleanValue(); 125 fLabelProvider.setAttribute(JDIModelPresentation.DISPLAY_QUALIFIED_NAMES, showQ); 126 super.retrieveLabel(update); 127 } 128 129 132 public void propertyChange(PropertyChangeEvent event) { 133 if (event.getProperty().endsWith(IJDIPreferencesConstants.PREF_SHOW_QUALIFIED_NAMES)) { 134 fQualifiedNameSettings.clear(); 135 } 136 } 137 138 141 protected boolean requiresUIJob(ILabelUpdate[] updates) { 142 return !JDIModelPresentation.isInitialized(); 143 } 144 145 146 147 } 148 | Popular Tags |