1 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 33 public class VariableLabelProvider extends DebugElementLabelProvider { 34 35 38 protected RGB getBackground(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException { 39 Object 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 54 protected RGB getForeground(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException { 55 Object 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 70 protected ImageDescriptor getImageDescriptor(TreePath elementPath, IPresentationContext presentationContext, String 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 80 protected FontData getFontData(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException { 81 return JFaceResources.getFontDescriptor(IInternalDebugUIConstants.VARIABLE_TEXT_FONT).getFontData()[0]; 82 } 83 84 87 protected String getLabel(TreePath elementPath, IPresentationContext context, String 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 107 protected String getColumnText(IVariable variable, IValue value, IPresentationContext context, String 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 127 protected String getVariableName(IVariable variable, IPresentationContext context) throws CoreException { 128 return variable.getName(); 129 } 130 131 138 protected String getVariableTypeName(IVariable variable, IPresentationContext context) throws CoreException { 139 return variable.getReferenceTypeName(); 140 } 141 142 150 protected String getValueTypeName(IVariable variable, IValue value, IPresentationContext context) throws CoreException { 151 return value.getReferenceTypeName(); 152 } 153 154 162 protected String getValueText(IVariable variable, IValue value, IPresentationContext context) throws CoreException { 163 return escapeSpecialChars(value.getValueString()); 164 } 165 166 172 protected String escapeSpecialChars(String label) { 173 return DefaultLabelProvider.escapeSpecialChars(label); 174 } 175 } 176 | Popular Tags |