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.runtime.CoreException; 19 import org.eclipse.core.runtime.IConfigurationElement; 20 import org.eclipse.core.runtime.ListenerList; 21 import org.eclipse.debug.core.DebugException; 22 import org.eclipse.debug.core.DebugPlugin; 23 import org.eclipse.debug.core.model.IBreakpoint; 24 import org.eclipse.debug.core.model.IExpression; 25 import org.eclipse.debug.core.model.IStackFrame; 26 import org.eclipse.debug.core.model.IThread; 27 import org.eclipse.debug.core.model.IValue; 28 import org.eclipse.debug.core.model.IVariable; 29 import org.eclipse.debug.internal.ui.views.variables.IndexedVariablePartition; 30 import org.eclipse.debug.ui.IDebugEditorPresentation; 31 import org.eclipse.debug.ui.IDebugModelPresentation; 32 import org.eclipse.debug.ui.IInstructionPointerPresentation; 33 import org.eclipse.debug.ui.IValueDetailListener; 34 import org.eclipse.jface.text.source.Annotation; 35 import org.eclipse.jface.text.source.SourceViewerConfiguration; 36 import org.eclipse.jface.viewers.IColorProvider; 37 import org.eclipse.jface.viewers.IFontProvider; 38 import org.eclipse.jface.viewers.ILabelProviderListener; 39 import org.eclipse.swt.graphics.Color; 40 import org.eclipse.swt.graphics.Font; 41 import org.eclipse.swt.graphics.Image; 42 import org.eclipse.ui.IEditorInput; 43 import org.eclipse.ui.IEditorPart; 44 45 49 50 public class LazyModelPresentation implements IDebugModelPresentation, IDebugEditorPresentation, IColorProvider, IFontProvider, IInstructionPointerPresentation { 51 52 56 protected HashMap fAttributes= new HashMap (3); 57 58 61 protected IConfigurationElement fConfig = null; 62 63 66 protected IDebugModelPresentation fPresentation = null; 67 68 72 protected ListenerList fListeners= new ListenerList(); 73 74 protected boolean fImageRegistryInitialized = false; 75 76 77 80 public void removeAnnotations(IEditorPart editorPart, IThread thread) { 81 IDebugModelPresentation presentation = getPresentation(); 82 if (presentation instanceof IDebugEditorPresentation) { 83 ((IDebugEditorPresentation)presentation).removeAnnotations(editorPart, thread); 84 } 85 } 86 87 90 public boolean addAnnotations(IEditorPart editorPart, IStackFrame frame) { 91 IDebugModelPresentation presentation = getPresentation(); 92 if (presentation instanceof IDebugEditorPresentation) { 93 return ((IDebugEditorPresentation)presentation).addAnnotations(editorPart, frame); 94 } 95 return false; 96 } 97 98 101 public LazyModelPresentation(IConfigurationElement configElement) { 102 fConfig = configElement; 103 } 104 105 108 public Image getImage(Object element) { 109 fImageRegistryInitialized = true; 110 Image image = getPresentation().getImage(element); 111 if (image == null) { 112 image = getDefaultImage(element); 113 } 114 if (image != null) { 115 int flags= computeAdornmentFlags(element); 116 if (flags > 0) { 117 CompositeDebugImageDescriptor descriptor= new CompositeDebugImageDescriptor(image, flags); 118 return DebugUIPlugin.getImageDescriptorRegistry().get(descriptor); 119 } 120 } 121 return image; 122 } 123 124 public boolean isImageRegistryInitialized() { 125 return fImageRegistryInitialized; 126 } 127 128 134 private int computeAdornmentFlags(Object element) { 135 if (element instanceof IBreakpoint) { 136 if (!DebugPlugin.getDefault().getBreakpointManager().isEnabled()) { 137 return CompositeDebugImageDescriptor.SKIP_BREAKPOINT; 138 } 139 } 140 return 0; 141 } 142 143 146 protected String getDefaultText(Object element) { 147 return DebugUIPlugin.getDefaultLabelProvider().getText(element); 148 } 149 150 153 protected Image getDefaultImage(Object element) { 154 return DebugUIPlugin.getDefaultLabelProvider().getImage(element); 155 } 156 157 160 public String getText(Object element) { 161 if (!(element instanceof IndexedVariablePartition)) { 162 String text = getPresentation().getText(element); 164 if (text != null) { 165 return text; 166 } 167 } 168 if (showVariableTypeNames()) { 170 try { 171 if (element instanceof IExpression) { 172 StringBuffer buf = new StringBuffer (); 173 IValue value = ((IExpression)element).getValue(); 174 if (value != null) { 175 buf.append(value.getReferenceTypeName()); 176 buf.append(' '); 177 } 178 buf.append(getDefaultText(element)); 179 return buf.toString(); 180 } else if (element instanceof IVariable) { 181 return new StringBuffer (((IVariable)element).getValue().getReferenceTypeName()).append(' ').append(getDefaultText(element)).toString(); 182 } 183 } catch (DebugException de) { 184 DebugUIPlugin.log(de); 185 } 186 } 187 return getDefaultText(element); 188 } 189 190 195 protected boolean showVariableTypeNames() { 196 Boolean show= (Boolean ) fAttributes.get(DISPLAY_VARIABLE_TYPE_NAMES); 197 show= show == null ? Boolean.FALSE : show; 198 return show.booleanValue(); 199 } 200 201 204 public void computeDetail(IValue value, IValueDetailListener listener) { 205 getPresentation().computeDetail(value, listener); 206 } 207 208 211 public IEditorInput getEditorInput(Object element) { 212 return getPresentation().getEditorInput(element); 213 } 214 215 218 public String getEditorId(IEditorInput input, Object inputObject) { 219 return getPresentation().getEditorId(input, inputObject); 220 } 221 222 225 public void addListener(ILabelProviderListener listener) { 226 if (fPresentation != null) { 227 getPresentation().addListener(listener); 228 } 229 fListeners.add(listener); 230 } 231 232 235 public void dispose() { 236 if (fPresentation != null) { 237 getPresentation().dispose(); 238 } 239 fListeners = null; 240 } 241 242 245 public boolean isLabelProperty(Object element, String property) { 246 if (fPresentation != null) { 247 return getPresentation().isLabelProperty(element, property); 248 } 249 return false; 250 } 251 252 255 public void removeListener(ILabelProviderListener listener) { 256 if (fPresentation != null) { 257 getPresentation().removeListener(listener); 258 } 259 ListenerList listeners = fListeners; 260 if (listeners != null) { 261 listeners.remove(listener); 262 } 263 } 264 265 268 protected IDebugModelPresentation getPresentation() { 269 if (fPresentation == null) { 270 synchronized (this) { 271 if (fPresentation != null) { 272 return fPresentation; 275 } 276 try { 277 IDebugModelPresentation tempPresentation= (IDebugModelPresentation) DebugUIPlugin.createExtension(fConfig, "class"); if (fListeners != null) { 280 Object [] list = fListeners.getListeners(); 281 for (int i= 0; i < list.length; i++) { 282 tempPresentation.addListener((ILabelProviderListener)list[i]); 283 } 284 } 285 Iterator keys= fAttributes.keySet().iterator(); 286 while (keys.hasNext()) { 287 String key= (String )keys.next(); 288 tempPresentation.setAttribute(key, fAttributes.get(key)); 289 } 290 fPresentation= tempPresentation; 294 } catch (CoreException e) { 295 DebugUIPlugin.log(e); 296 } 297 } 298 } 299 return fPresentation; 300 } 301 302 305 public void setAttribute(String id, Object value) { 306 if (value == null) { 307 return; 308 } 309 if (fPresentation != null) { 310 getPresentation().setAttribute(id, value); 311 } 312 313 fAttributes.put(id, value); 314 } 315 316 320 public String getDebugModelIdentifier() { 321 return fConfig.getAttribute("id"); } 323 324 333 public SourceViewerConfiguration newDetailsViewerConfiguration() throws CoreException { 334 String attr = fConfig.getAttribute("detailsViewerConfiguration"); if (attr != null) { 336 return (SourceViewerConfiguration)fConfig.createExecutableExtension("detailsViewerConfiguration"); } 338 return null; 339 } 340 341 347 public Map getAttributeMap() { 348 return (Map ) fAttributes.clone(); 349 } 350 351 public Map getAttributes() { 352 return fAttributes; 353 } 354 355 358 public Color getForeground(Object element) { 359 IDebugModelPresentation presentation = getPresentation(); 360 if (presentation instanceof IColorProvider) { 361 IColorProvider colorProvider = (IColorProvider) presentation; 362 return colorProvider.getForeground(element); 363 } 364 return null; 365 } 366 367 370 public Color getBackground(Object element) { 371 IDebugModelPresentation presentation = getPresentation(); 372 if (presentation instanceof IColorProvider) { 373 IColorProvider colorProvider = (IColorProvider) presentation; 374 return colorProvider.getBackground(element); 375 } 376 return null; 377 } 378 379 382 public Font getFont(Object element) { 383 IDebugModelPresentation presentation = getPresentation(); 384 if (presentation instanceof IFontProvider) { 385 IFontProvider fontProvider = (IFontProvider) presentation; 386 return fontProvider.getFont(element); 387 } 388 return null; 389 } 390 391 394 public Annotation getInstructionPointerAnnotation(IEditorPart editorPart, IStackFrame frame) { 395 IDebugModelPresentation presentation = getPresentation(); 396 if (presentation instanceof IInstructionPointerPresentation) { 397 IInstructionPointerPresentation pointerPresentation = (IInstructionPointerPresentation) presentation; 398 return pointerPresentation.getInstructionPointerAnnotation(editorPart, frame); 399 } 400 return null; 401 } 402 403 406 public String getInstructionPointerAnnotationType(IEditorPart editorPart, IStackFrame frame) { 407 IDebugModelPresentation presentation = getPresentation(); 408 if (presentation instanceof IInstructionPointerPresentation) { 409 IInstructionPointerPresentation pointerPresentation = (IInstructionPointerPresentation) presentation; 410 return pointerPresentation.getInstructionPointerAnnotationType(editorPart, frame); 411 } 412 return null; 413 } 414 415 418 public Image getInstructionPointerImage(IEditorPart editorPart, IStackFrame frame) { 419 IDebugModelPresentation presentation = getPresentation(); 420 if (presentation instanceof IInstructionPointerPresentation) { 421 IInstructionPointerPresentation pointerPresentation = (IInstructionPointerPresentation) presentation; 422 return pointerPresentation.getInstructionPointerImage(editorPart, frame); 423 } 424 return null; 425 } 426 427 430 public String getInstructionPointerText(IEditorPart editorPart, IStackFrame frame) { 431 IDebugModelPresentation presentation = getPresentation(); 432 if (presentation instanceof IInstructionPointerPresentation) { 433 IInstructionPointerPresentation pointerPresentation = (IInstructionPointerPresentation) presentation; 434 return pointerPresentation.getInstructionPointerText(editorPart, frame); 435 } 436 return null; 437 } 438 } 439 | Popular Tags |