1 11 package org.eclipse.debug.internal.ui; 12 13 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 import org.eclipse.core.resources.IMarker; 19 import org.eclipse.core.runtime.IConfigurationElement; 20 import org.eclipse.core.runtime.IExtension; 21 import org.eclipse.core.runtime.IExtensionPoint; 22 import org.eclipse.core.runtime.Platform; 23 import org.eclipse.debug.core.DebugException; 24 import org.eclipse.debug.core.DebugPlugin; 25 import org.eclipse.debug.core.model.IBreakpoint; 26 import org.eclipse.debug.core.model.IDebugElement; 27 import org.eclipse.debug.core.model.IStackFrame; 28 import org.eclipse.debug.core.model.IThread; 29 import org.eclipse.debug.core.model.IValue; 30 import org.eclipse.debug.ui.DebugUITools; 31 import org.eclipse.debug.ui.IDebugEditorPresentation; 32 import org.eclipse.debug.ui.IDebugModelPresentation; 33 import org.eclipse.debug.ui.IDebugUIConstants; 34 import org.eclipse.debug.ui.IInstructionPointerPresentation; 35 import org.eclipse.debug.ui.IValueDetailListener; 36 import org.eclipse.jface.text.source.Annotation; 37 import org.eclipse.jface.viewers.IColorProvider; 38 import org.eclipse.jface.viewers.IFontProvider; 39 import org.eclipse.jface.viewers.ILabelProvider; 40 import org.eclipse.jface.viewers.ILabelProviderListener; 41 import org.eclipse.swt.graphics.Color; 42 import org.eclipse.swt.graphics.Font; 43 import org.eclipse.swt.graphics.Image; 44 import org.eclipse.ui.IEditorInput; 45 import org.eclipse.ui.IEditorPart; 46 47 54 public class DelegatingModelPresentation implements IDebugModelPresentation, IDebugEditorPresentation, IColorProvider, IFontProvider, IInstructionPointerPresentation { 55 56 60 private HashMap fAttributes= new HashMap (3); 61 64 private HashMap fLabelProviders= new HashMap (5); 65 66 69 private boolean fInitialized = false; 70 71 74 public void removeAnnotations(IEditorPart editorPart, IThread thread) { 75 IDebugModelPresentation presentation = getConfiguredPresentation(thread); 76 if (presentation instanceof IDebugEditorPresentation) { 77 ((IDebugEditorPresentation)presentation).removeAnnotations(editorPart, thread); 78 } 79 } 80 81 84 public boolean addAnnotations(IEditorPart editorPart, IStackFrame frame) { 85 IDebugModelPresentation presentation = getConfiguredPresentation(frame); 86 if (presentation instanceof IDebugEditorPresentation) { 87 return((IDebugEditorPresentation)presentation).addAnnotations(editorPart, frame); 88 } 89 return false; 90 } 91 92 96 public DelegatingModelPresentation() { 97 IExtensionPoint point= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.ID_DEBUG_MODEL_PRESENTATION); 98 if (point != null) { 99 IExtension[] extensions= point.getExtensions(); 100 for (int i= 0; i < extensions.length; i++) { 101 IExtension extension= extensions[i]; 102 IConfigurationElement[] configElements= extension.getConfigurationElements(); 103 for (int j= 0; j < configElements.length; j++) { 104 IConfigurationElement elt= configElements[j]; 105 String id= elt.getAttribute("id"); if (id != null) { 107 IDebugModelPresentation lp= new LazyModelPresentation(elt); 108 getLabelProviders().put(id, lp); 109 } 110 } 111 } 112 } 113 } 114 115 120 public void addListener(ILabelProviderListener listener) { 121 Iterator i= getLabelProviders().values().iterator(); 122 while (i.hasNext()) { 123 ((ILabelProvider) i.next()).addListener(listener); 124 } 125 } 126 127 132 public void dispose() { 133 Iterator i= getLabelProviders().values().iterator(); 134 while (i.hasNext()) { 135 ((ILabelProvider) i.next()).dispose(); 136 } 137 } 138 139 142 public Image getImage(Object item) { 143 initImageRegistries(); 144 IDebugModelPresentation lp= getConfiguredPresentation(item); 146 if (lp != null) { 147 Image image= lp.getImage(item); 148 if (image != null) { 149 return image; 150 } 151 } 152 return getDefaultImage(item); 154 } 155 156 159 public String getText(Object item) { 160 IDebugModelPresentation lp= getConfiguredPresentation(item); 161 if (lp != null) { 162 return lp.getText(item); 163 } 164 return getDefaultText(item); 165 } 166 167 170 public IEditorInput getEditorInput(Object item) { 171 IDebugModelPresentation lp= getConfiguredPresentation(item); 172 if (lp != null) { 173 return lp.getEditorInput(item); 174 } 175 return null; 176 } 177 178 181 public String getEditorId(IEditorInput input, Object objectInput) { 182 IDebugModelPresentation lp= getConfiguredPresentation(objectInput); 183 if (lp != null) { 184 return lp.getEditorId(input, objectInput); 185 } 186 return null; 187 } 188 189 190 193 protected String getDefaultText(Object element) { 194 return DebugUIPlugin.getDefaultLabelProvider().getText(element); 195 } 196 197 200 protected Image getDefaultImage(Object element) { 201 return DebugUIPlugin.getDefaultLabelProvider().getImage(element); 202 } 203 204 207 public void computeDetail(IValue value, IValueDetailListener listener) { 208 IDebugModelPresentation lp= getConfiguredPresentation(value); 209 if (lp != null) { 210 lp.computeDetail(value, listener); 211 } else { 212 listener.detailComputed(value, getText(value)); 213 } 214 } 215 216 221 public void removeListener(ILabelProviderListener listener) { 222 Iterator i= getLabelProviders().values().iterator(); 223 while (i.hasNext()) { 224 ((ILabelProvider) i.next()).removeListener(listener); 225 } 226 } 227 228 233 public boolean isLabelProperty(Object element, String property) { 234 if (element instanceof IDebugElement) { 235 IDebugModelPresentation lp= getConfiguredPresentation(element); 236 if (lp != null) { 237 return lp.isLabelProperty(element, property); 238 } 239 } 240 241 return true; 242 } 243 244 248 protected IDebugModelPresentation getConfiguredPresentation(Object element) { 249 String id= null; 250 if (element instanceof IDebugElement) { 251 IDebugElement de= (IDebugElement) element; 252 id= de.getModelIdentifier(); 253 } else if (element instanceof IMarker) { 254 IMarker m= (IMarker) element; 255 IBreakpoint bp = DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(m); 256 if (bp != null) { 257 id= bp.getModelIdentifier(); 258 } 259 } else if (element instanceof IBreakpoint) { 260 id = ((IBreakpoint)element).getModelIdentifier(); 261 } 262 if (id != null) { 263 return getPresentation(id); 264 } 265 266 return null; 267 } 268 269 273 public IDebugModelPresentation getPresentation(String id) { 274 return (IDebugModelPresentation) getLabelProviders().get(id); 275 } 276 277 280 public void setAttribute(String id, Object value) { 281 if (value == null) { 282 return; 283 } 284 getAttributes().put(id, value); 285 Iterator presentations = fLabelProviders.values().iterator(); 286 while (presentations.hasNext()) { 287 ((IDebugModelPresentation)presentations.next()).setAttribute(id, value); 288 } 289 } 290 291 296 protected boolean showVariableTypeNames() { 297 Boolean show= (Boolean ) fAttributes.get(DISPLAY_VARIABLE_TYPE_NAMES); 298 show= show == null ? Boolean.FALSE : show; 299 return show.booleanValue(); 300 } 301 302 public HashMap getAttributes() { 303 return fAttributes; 304 } 305 306 312 public Map getAttributeMap() { 313 return (Map ) getAttributes().clone(); 314 } 315 316 protected HashMap getLabelProviders() { 317 return fLabelProviders; 318 } 319 320 323 public Color getForeground(Object element) { 324 IDebugModelPresentation presentation = getConfiguredPresentation(element); 325 if (presentation instanceof IColorProvider) { 326 IColorProvider colorProvider = (IColorProvider) presentation; 327 return colorProvider.getForeground(element); 328 } 329 return null; 330 } 331 332 335 public Color getBackground(Object element) { 336 IDebugModelPresentation presentation = getConfiguredPresentation(element); 337 if (presentation instanceof IColorProvider) { 338 IColorProvider colorProvider = (IColorProvider) presentation; 339 return colorProvider.getBackground(element); 340 } 341 return null; 342 } 343 344 347 public Font getFont(Object element) { 348 IDebugModelPresentation presentation = getConfiguredPresentation(element); 349 if (presentation instanceof IFontProvider) { 350 IFontProvider fontProvider = (IFontProvider) presentation; 351 return fontProvider.getFont(element); 352 } 353 return null; 354 } 355 356 359 public Annotation getInstructionPointerAnnotation(IEditorPart editorPart, IStackFrame frame) { 360 IDebugModelPresentation presentation = getConfiguredPresentation(frame); 361 Annotation annotation = null; 362 String id = null; 363 Image image = null; 364 String text = null; 365 if (presentation instanceof IInstructionPointerPresentation) { 366 IInstructionPointerPresentation pointerPresentation = (IInstructionPointerPresentation) presentation; 368 annotation = pointerPresentation.getInstructionPointerAnnotation(editorPart, frame); 369 if (annotation == null) { 370 id = pointerPresentation.getInstructionPointerAnnotationType(editorPart, frame); 372 if (id == null) { 373 image = pointerPresentation.getInstructionPointerImage(editorPart, frame); 375 } 376 text = pointerPresentation.getInstructionPointerText(editorPart, frame); 377 } 378 } 379 if (annotation == null) { 380 boolean defaultAnnotation = id == null; 381 if (id == null || text == null || (defaultAnnotation && image == null)) { 382 IThread thread = frame.getThread(); 383 IStackFrame tos = null; 384 boolean top = false; 385 try { 386 tos = thread.getTopStackFrame(); 387 top = frame.equals(tos); 388 } catch (DebugException de) { 389 } 390 if (id == null) { 391 if (top) { 392 id = IDebugUIConstants.ANNOTATION_TYPE_INSTRUCTION_POINTER_CURRENT; 393 } else { 394 id = IDebugUIConstants.ANNOTATION_TYPE_INSTRUCTION_POINTER_SECONDARY; 395 } 396 } 397 if (text == null) { 398 if (top) { 399 text = DebugUIMessages.InstructionPointerAnnotation_0; 400 } else { 401 text = DebugUIMessages.InstructionPointerAnnotation_1; 402 } 403 } 404 if (defaultAnnotation && image == null) { 405 if (top) { 406 image = DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_INSTRUCTION_POINTER_TOP); 407 } else { 408 image = DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_INSTRUCTION_POINTER); 409 } 410 } 411 } 412 if (defaultAnnotation) { 413 annotation = new InstructionPointerAnnotation(frame, id, text, image); 414 } else { 415 annotation = new DynamicInstructionPointerAnnotation(frame, id, text); 416 } 417 } 418 return annotation; 419 } 420 421 424 public String getInstructionPointerAnnotationType(IEditorPart editorPart, IStackFrame frame) { 425 IDebugModelPresentation presentation = getConfiguredPresentation(frame); 426 if (presentation instanceof IInstructionPointerPresentation) { 427 return ((IInstructionPointerPresentation)presentation).getInstructionPointerAnnotationType(editorPart, frame); 428 } 429 return null; 430 } 431 432 435 public Image getInstructionPointerImage(IEditorPart editorPart, IStackFrame frame) { 436 IDebugModelPresentation presentation = getConfiguredPresentation(frame); 437 if (presentation instanceof IInstructionPointerPresentation) { 438 return ((IInstructionPointerPresentation)presentation).getInstructionPointerImage(editorPart, frame); 439 } 440 return null; 441 } 442 443 446 public String getInstructionPointerText(IEditorPart editorPart, IStackFrame frame) { 447 IDebugModelPresentation presentation = getConfiguredPresentation(frame); 448 if (presentation instanceof IInstructionPointerPresentation) { 449 return ((IInstructionPointerPresentation)presentation).getInstructionPointerText(editorPart, frame); 450 } 451 return null; 452 } 453 454 public boolean isInitialized(Object element) { 455 LazyModelPresentation configuredPresentation = (LazyModelPresentation) getConfiguredPresentation(element); 456 if (configuredPresentation != null) { 457 return configuredPresentation.isImageRegistryInitialized(); 458 } 459 return false; 460 } 461 462 465 private synchronized void initImageRegistries() { 466 if (!fInitialized && Thread.currentThread().equals(DebugUIPlugin.getStandardDisplay().getThread())) { 468 DebugUIPlugin.getDefault().getImageRegistry(); 470 fInitialized = true; 471 } 472 } 473 } 474 | Popular Tags |