1 11 package org.eclipse.debug.internal.ui.elements.adapters; 12 13 import java.util.Arrays ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.debug.core.DebugException; 17 import org.eclipse.debug.core.model.IValue; 18 import org.eclipse.debug.core.model.IVariable; 19 import org.eclipse.debug.internal.ui.DebugUIPlugin; 20 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 21 import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext; 22 import org.eclipse.debug.ui.IDebugUIConstants; 23 import org.eclipse.swt.graphics.RGB; 24 import org.eclipse.ui.IWorkbenchPart; 25 26 31 public class VariableLabelAdapter extends AsynchronousDebugLabelAdapter { 32 33 36 protected String [] getLabels(Object element, IPresentationContext context) throws CoreException { 37 IWorkbenchPart part = context.getPart(); 38 String [] ids = context.getColumns(); 39 if (part != null && ids != null) { 40 String viewId = part.getSite().getId(); 41 if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(viewId) || IDebugUIConstants.ID_REGISTER_VIEW.equals(viewId)) { 42 IVariable variable = (IVariable) element; 43 IValue value = variable.getValue(); 44 String [] columns = new String [ids.length]; 45 for (int i = 0; i < ids.length; i++) { 46 columns[i] = getColumnText(variable, value, ids[i], context); 47 } 48 return columns; 49 } 50 } 51 String [] labels = super.getLabels(element, context); 52 String [] escaped = new String [labels.length]; 53 for (int i = 0; i < escaped.length; i++) { 54 escaped[i] = escapeSpecialChars(labels[i]); 55 } 56 return escaped; 57 } 58 59 68 protected String getColumnText(IVariable variable, IValue value, String columnId, IPresentationContext context) throws CoreException { 69 if (VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(columnId)) { 70 return getVariableName(variable, context); 71 } else if (VariableColumnPresentation.COLUMN_VARIABLE_TYPE.equals(columnId)) { 72 return getVariableTypeName(variable, context); 73 } else if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(columnId)) { 74 return getValueText(variable, value, context); 75 } else if (VariableColumnPresentation.COLUMN_VALUE_TYPE.equals(columnId)) { 76 return getValueTypeName(variable, value, context); 77 } 78 return null; 79 } 80 81 88 protected String getVariableName(IVariable variable, IPresentationContext context) throws CoreException { 89 return variable.getName(); 90 } 91 92 99 protected String getVariableTypeName(IVariable variable, IPresentationContext context) throws CoreException { 100 return variable.getReferenceTypeName(); 101 } 102 103 111 protected String getValueTypeName(IVariable variable, IValue value, IPresentationContext context) throws CoreException { 112 return value.getReferenceTypeName(); 113 } 114 115 123 protected String getValueText(IVariable variable, IValue value, IPresentationContext context) throws CoreException { 124 return escapeSpecialChars(value.getValueString()); 125 } 126 127 130 protected RGB[] getForegrounds(Object element, IPresentationContext context) throws CoreException { 131 int numElements = getNumElements(context); 132 if (numElements == 1) { 133 if (element instanceof IVariable) { 134 IVariable variable = (IVariable) element; 135 try { 136 if (variable.hasValueChanged()) { 137 RGB[] rgbs = new RGB[numElements]; 138 Arrays.fill(rgbs, DebugUIPlugin.getPreferenceColor(IDebugUIConstants.PREF_CHANGED_DEBUG_ELEMENT_COLOR).getRGB()); 139 return rgbs; 140 } 141 } catch (DebugException e) { 142 } 143 } 144 } 145 return super.getForegrounds(element, context); 146 } 147 148 protected RGB[] getBackgrounds(Object element, IPresentationContext context) throws CoreException { 149 int numElements = getNumElements(context); 150 if (numElements > 1) { 151 if (element instanceof IVariable) { 152 IVariable variable = (IVariable) element; 153 try { 154 if (variable.hasValueChanged()) { 155 RGB[] rgbs = new RGB[numElements]; 156 Arrays.fill(rgbs, DebugUIPlugin.getPreferenceColor(IInternalDebugUIConstants.PREF_CHANGED_VALUE_BACKGROUND).getRGB()); 157 return rgbs; 158 } 159 } catch (DebugException e) { 160 } 161 } 162 } 163 return super.getBackgrounds(element, context); 164 } 165 166 protected String escapeSpecialChars(String label) { 167 if (label == null) { 168 return null; 169 } 170 StringBuffer escaped = new StringBuffer (); 171 for (int i = 0; i < label.length(); i++) { 172 char c = label.charAt(i); 173 switch (c) { 174 case '\b': 175 escaped.append("\\b"); break; 177 case '\f': 178 escaped.append("\\f"); break; 180 case '\n': 181 escaped.append("\\n"); break; 183 case '\r': 184 escaped.append("\\r"); break; 186 case '\t': 187 escaped.append("\\t"); break; 189 default: 190 escaped.append(c); 191 break; 192 } 193 } 194 return escaped.toString(); 195 } 196 197 198 } 199 | Popular Tags |