1 11 12 package org.eclipse.debug.internal.ui.elements.adapters; 13 14 import java.math.BigInteger ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.model.MemoryByte; 18 import org.eclipse.debug.internal.ui.DebugPluginImages; 19 import org.eclipse.debug.internal.ui.DebugUIPlugin; 20 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 21 import org.eclipse.debug.internal.ui.memory.provisional.AbstractAsyncTableRendering; 22 import org.eclipse.debug.internal.ui.memory.provisional.MemoryViewPresentationContext; 23 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 24 import org.eclipse.debug.internal.ui.viewers.provisional.AsynchronousLabelAdapter; 25 import org.eclipse.debug.internal.ui.views.launch.DebugElementHelper; 26 import org.eclipse.debug.internal.ui.views.memory.renderings.AbstractBaseTableRendering; 27 import org.eclipse.debug.internal.ui.views.memory.renderings.MemorySegment; 28 import org.eclipse.debug.internal.ui.views.memory.renderings.TableRenderingContentDescriptor; 29 import org.eclipse.debug.ui.IDebugUIConstants; 30 import org.eclipse.debug.ui.memory.IMemoryBlockTablePresentation; 31 import org.eclipse.debug.ui.memory.MemoryRenderingElement; 32 import org.eclipse.jface.resource.ImageDescriptor; 33 import org.eclipse.jface.viewers.IColorProvider; 34 import org.eclipse.jface.viewers.IFontProvider; 35 import org.eclipse.jface.viewers.ILabelProvider; 36 import org.eclipse.swt.graphics.Color; 37 import org.eclipse.swt.graphics.Font; 38 import org.eclipse.swt.graphics.FontData; 39 import org.eclipse.swt.graphics.Image; 40 import org.eclipse.swt.graphics.RGB; 41 42 public class MemorySegmentLabelAdapter extends AsynchronousLabelAdapter { 43 44 protected String [] getLabels(Object element, IPresentationContext context) 45 throws CoreException { 46 47 if (context instanceof MemoryViewPresentationContext) 48 { 49 MemoryViewPresentationContext tableRenderingContext = (MemoryViewPresentationContext)context; 50 if (tableRenderingContext.getRendering() != null && tableRenderingContext.getRendering() instanceof AbstractAsyncTableRendering) 51 { 52 AbstractAsyncTableRendering tableRendering = (AbstractAsyncTableRendering)tableRenderingContext.getRendering(); 53 TableRenderingContentDescriptor descriptor = (TableRenderingContentDescriptor)tableRendering.getAdapter(TableRenderingContentDescriptor.class); 54 if (descriptor != null) 55 { 56 String addressStr = getColumnText(element, 0, tableRendering, descriptor); 57 int numColumns = tableRendering.getAddressableUnitPerLine() / tableRendering.getAddressableUnitPerColumn(); 58 59 String [] labels = new String [numColumns+2]; 60 labels[0] = addressStr; 61 62 for (int i=0; i<=numColumns; i++) 63 { 64 labels[i+1] = getColumnText(element, i+1, tableRendering, (TableRenderingContentDescriptor)tableRendering.getAdapter(TableRenderingContentDescriptor.class)); 65 } 66 67 labels[labels.length - 1 ] = ""; return labels; 69 } 70 } 71 } 72 return new String [0]; 73 } 74 75 private String getColumnText(Object element, int columnIndex, AbstractAsyncTableRendering tableRendering, TableRenderingContentDescriptor descriptor) { 76 String columnLabel = null; 77 78 if (columnIndex == 0) 79 { 80 IMemoryBlockTablePresentation presentation = (IMemoryBlockTablePresentation)tableRendering.getMemoryBlock().getAdapter(IMemoryBlockTablePresentation.class); 81 if (presentation != null) 82 { 83 String rowLabel = presentation.getRowLabel(tableRendering.getMemoryBlock(), ((MemorySegment)element).getAddress()); 84 if (rowLabel != null) 85 return rowLabel; 86 } 87 88 columnLabel = ((MemorySegment)element).getAddress().toString(16).toUpperCase(); 89 90 int addressSize = descriptor.getAddressSize(); 91 int prefillLength = addressSize * 2 - columnLabel.length(); 92 StringBuffer buf = new StringBuffer (); 93 if (prefillLength > 0) 94 { 95 for (int i=0; i<prefillLength; i++) 96 { 97 buf.append("0"); } 99 } 100 buf.append(columnLabel); 101 return buf.toString(); 102 103 } 104 else if (columnIndex > (tableRendering.getBytesPerLine()/tableRendering.getBytesPerColumn())) 105 { 106 columnLabel = " "; } 108 else 109 { 110 if (element instanceof MemorySegment) 111 { 112 MemorySegment segment = (MemorySegment)element; 113 if (segment.getBytes().length != tableRendering.getBytesPerLine()) 114 return ""; } 116 117 ILabelProvider labelProvider = (ILabelProvider)tableRendering.getAdapter(ILabelProvider.class); 118 if (labelProvider != null && columnIndex > 0) 119 { 120 MemoryRenderingElement renderingElement = getMemoryRenderingElement(element, columnIndex, tableRendering); 121 if (renderingElement != null) { 122 String label = labelProvider.getText(renderingElement); 123 if (label != null) 124 return label; 125 } 126 } 127 128 int start = (columnIndex-1)*tableRendering.getBytesPerColumn(); 129 MemoryByte[] bytes = ((MemorySegment)element).getBytes(start, tableRendering.getBytesPerColumn()); 130 BigInteger address = ((MemorySegment)element).getAddress(); 131 address = address.add(BigInteger.valueOf(start)); 132 133 columnLabel = tableRendering.getString(tableRendering.getRenderingId(), address, bytes); 134 } 135 return columnLabel; 136 } 137 138 protected ImageDescriptor[] getImageDescriptors(Object element, 139 IPresentationContext context) throws CoreException { 140 if (context instanceof MemoryViewPresentationContext) 141 { 142 MemoryViewPresentationContext tableRenderingContext = (MemoryViewPresentationContext)context; 143 if (tableRenderingContext.getRendering() != null && tableRenderingContext.getRendering() instanceof AbstractAsyncTableRendering) 144 { 145 AbstractAsyncTableRendering tableRendering = (AbstractAsyncTableRendering)tableRenderingContext.getRendering(); 146 int numColumns = tableRendering.getAddressableUnitPerLine() / tableRendering.getAddressableUnitPerColumn(); 147 148 ImageDescriptor[] images = new ImageDescriptor[numColumns+2]; 149 150 for (int i=0; i<=numColumns; i++) 151 { 152 images[i] = getColumnImageDescriptor(element, i, tableRendering); 153 } 154 155 images[images.length - 1 ] = null; 156 return images; 157 } 158 } 159 return new ImageDescriptor[0]; 160 } 161 162 private ImageDescriptor getColumnImageDescriptor(Object element, int columnIndex, AbstractAsyncTableRendering tableRendering) 163 { 164 if (columnIndex == 0) 165 return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_OBJECT_MEMORY); 166 167 if (element instanceof MemorySegment) 168 { 169 MemorySegment segment = (MemorySegment)element; 170 if (segment.getBytes().length != tableRendering.getBytesPerLine()) 171 return null; 172 173 ILabelProvider labelProvider = (ILabelProvider)tableRendering.getAdapter(ILabelProvider.class); 174 if (labelProvider != null && columnIndex > 0) 175 { 176 MemoryRenderingElement renderingElement = getMemoryRenderingElement(element, columnIndex, tableRendering); 177 if (renderingElement != null) { 178 Image image = labelProvider.getImage(renderingElement); 179 if (image != null) 180 { 181 return DebugElementHelper.getImageDescriptor(image); 182 } 183 } 184 } 185 186 int start = (columnIndex-1)*tableRendering.getBytesPerColumn(); 187 188 MemoryByte[] bytes = ((MemorySegment)element).getBytes(start, tableRendering.getBytesPerColumn()); 189 boolean allKnown = true; 190 boolean unchanged = true; 191 for (int i=0; i<bytes.length; i++) 192 { 193 if (!bytes[i].isHistoryKnown()) 194 allKnown = false; 195 196 if (bytes[i].isChanged()) 197 unchanged = false; 198 } 199 200 if (allKnown) 201 { 202 if (!unchanged) 204 return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_OBJECT_MEMORY_CHANGED); 205 206 } 207 } 208 return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_OBJECT_MEMORY); 209 } 210 211 protected FontData[] getFontDatas(Object element, 212 IPresentationContext context) throws CoreException { 213 if (context instanceof MemoryViewPresentationContext) 214 { 215 MemoryViewPresentationContext tableRenderingContext = (MemoryViewPresentationContext)context; 216 if (tableRenderingContext.getRendering() != null && tableRenderingContext.getRendering() instanceof AbstractAsyncTableRendering) 217 { 218 AbstractAsyncTableRendering tableRendering = (AbstractAsyncTableRendering)tableRenderingContext.getRendering(); 219 int numColumns = tableRendering.getAddressableUnitPerLine() / tableRendering.getAddressableUnitPerColumn(); 220 221 FontData[] fontData = new FontData[numColumns+2]; 222 223 for (int i=0; i<fontData.length-1; i++) 224 { 225 fontData[i] = getColumnFontData(element, i, tableRendering); 226 } 227 return fontData; 228 } 229 } 230 231 return new FontData[0]; 232 } 233 234 private FontData getColumnFontData(Object element, int columnIndex, AbstractAsyncTableRendering tableRendering) 235 { 236 if (element instanceof MemorySegment) 237 { 238 MemorySegment segment = (MemorySegment)element; 239 if (segment.getBytes().length != tableRendering.getBytesPerLine()) 240 return null; 241 242 IFontProvider fontProvider = (IFontProvider)tableRendering.getAdapter(IFontProvider.class); 243 if (fontProvider != null && columnIndex > 0) 244 { 245 MemoryRenderingElement renderingElement = getMemoryRenderingElement(element, columnIndex, tableRendering); 246 if (renderingElement != null) { 247 Font font = fontProvider.getFont(renderingElement); 248 if (font != null) 249 return font.getFontData()[0]; 250 } 251 } 252 } 253 return null; 254 } 255 256 protected RGB[] getForegrounds(Object element, IPresentationContext context) 257 throws CoreException { 258 259 if (context instanceof MemoryViewPresentationContext) 260 { 261 MemoryViewPresentationContext tableRenderingContext = (MemoryViewPresentationContext)context; 262 if (tableRenderingContext.getRendering() != null && tableRenderingContext.getRendering() instanceof AbstractAsyncTableRendering) 263 { 264 AbstractAsyncTableRendering tableRendering = (AbstractAsyncTableRendering)tableRenderingContext.getRendering(); 265 int numColumns = tableRendering.getAddressableUnitPerLine() / tableRendering.getAddressableUnitPerColumn(); 266 267 RGB[] colors = new RGB[numColumns+2]; 268 269 for (int i=0; i<colors.length-1; i++) 270 { 271 colors[i] = getColumnForeground(element, i, tableRendering); 272 } 273 274 colors[colors.length-1] = null; 275 276 return colors; 277 } 278 } 279 280 return new RGB[0]; 281 } 282 283 private RGB getColumnBackground(Object element, int columnIndex, AbstractAsyncTableRendering tableRendering) 284 { 285 if (columnIndex == 0) 286 return null; 287 288 if (element instanceof MemorySegment) 289 { 290 MemorySegment segment = (MemorySegment)element; 291 if (segment.getBytes().length != tableRendering.getBytesPerLine()) 292 return null; 293 294 IColorProvider colorProvider = (IColorProvider)tableRendering.getAdapter(IColorProvider.class); 295 if (colorProvider != null && columnIndex > 0) 296 { 297 MemoryRenderingElement renderingElement = getMemoryRenderingElement(element, columnIndex, tableRendering); 298 if (renderingElement != null) { 299 Color color = colorProvider.getBackground(renderingElement); 300 if (color != null) 301 return color.getRGB(); 302 } 303 } 304 } 305 return null; 306 } 307 308 private RGB getColumnForeground(Object element, int columnIndex, AbstractAsyncTableRendering tableRendering) 309 { 310 if (columnIndex == 0) 311 return null; 312 313 if (element instanceof MemorySegment) 314 { 315 MemorySegment segment = (MemorySegment)element; 316 if (segment.getBytes().length != tableRendering.getBytesPerLine()) 317 return null; 318 319 IColorProvider colorProvider = (IColorProvider)tableRendering.getAdapter(IColorProvider.class); 320 if (colorProvider != null && columnIndex > 0) 321 { 322 MemoryRenderingElement renderingElement = getMemoryRenderingElement(element, columnIndex, tableRendering); 323 if (renderingElement != null) { 324 Color color = colorProvider.getForeground(renderingElement); 325 if (color != null) 326 return color.getRGB(); 327 } 328 } 329 330 int start = (columnIndex-1)*tableRendering.getBytesPerColumn(); 331 MemoryByte[] bytes = segment.getBytes(start, tableRendering.getBytesPerColumn()); 332 boolean allKnown = true; 333 boolean unchanged = true; 334 for (int i=0; i<bytes.length; i++) 335 { 336 if (!bytes[i].isHistoryKnown()) 337 allKnown = false; 338 339 if (bytes[i].isChanged()) 340 unchanged = false; 341 } 342 343 if (allKnown) 344 { 345 if (!unchanged) 347 return DebugUIPlugin.getPreferenceColor(IDebugUIConstants.PREF_CHANGED_DEBUG_ELEMENT_COLOR).getRGB(); 348 349 return DebugUIPlugin.getPreferenceColor(IDebugUIConstants.PREF_MEMORY_HISTORY_KNOWN_COLOR).getRGB(); 350 } 351 352 return DebugUIPlugin.getPreferenceColor(IDebugUIConstants.PREF_MEMORY_HISTORY_UNKNOWN_COLOR).getRGB(); 353 354 } 355 return null; 356 } 357 358 protected RGB[] getBackgrounds(Object element, IPresentationContext context) 359 throws CoreException { 360 361 if (context instanceof MemoryViewPresentationContext) 362 { 363 MemoryViewPresentationContext tableRenderingContext = (MemoryViewPresentationContext)context; 364 if (tableRenderingContext.getRendering() != null && tableRenderingContext.getRendering() instanceof AbstractAsyncTableRendering) 365 { 366 AbstractAsyncTableRendering tableRendering = (AbstractAsyncTableRendering)tableRenderingContext.getRendering(); 367 int numColumns = tableRendering.getAddressableUnitPerLine() / tableRendering.getAddressableUnitPerColumn(); 368 369 RGB[] colors = new RGB[numColumns+2]; 370 371 for (int i=0; i<colors.length-1; i++) 372 { 373 colors[i] = getColumnBackground(element, i, tableRendering); 374 } 375 376 colors[colors.length-1] = null; 377 378 return colors; 379 } 380 } 381 382 return new RGB[0]; 383 } 384 385 393 private MemoryRenderingElement getMemoryRenderingElement(Object element, int columnIndex, AbstractBaseTableRendering rendering) { 394 if (element instanceof MemorySegment) { 395 MemorySegment line = (MemorySegment) element; 396 BigInteger address = line.getAddress(); 397 int offset = (columnIndex - 1) * rendering.getBytesPerColumn(); 398 if (offset < rendering.getBytesPerLine() && (offset + rendering.getBytesPerColumn()) <= rendering.getBytesPerLine()) { 399 return getMemoryRenderingElement(line, address, offset, rendering); 400 } 401 } 402 return null; 403 } 404 405 private MemoryRenderingElement getMemoryRenderingElement(MemorySegment line, BigInteger lineAddress, int offset, AbstractBaseTableRendering rendering) { 406 BigInteger cellAddress = lineAddress.add(BigInteger.valueOf(offset)); 407 MemoryByte[] bytes = line.getBytes(offset, rendering.getBytesPerColumn()); 408 MemoryByte[] copy = new MemoryByte[bytes.length]; 411 System.arraycopy(bytes, 0, copy, 0, bytes.length); 412 MemoryRenderingElement renderingElement = new MemoryRenderingElement( 413 rendering, cellAddress, copy); 414 return renderingElement; 415 } 416 417 } 418 | Popular Tags |