diff options
7 files changed, 134 insertions, 42 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java index dc7f8d2fc..66f873ddb 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -279,6 +279,15 @@ public class DebugPluginImages { } return imageRegistry; } + + /** + * Returns whether the image registry has been initialized. + * + * @return whether the image registry has been initialized + */ + public synchronized static boolean isInitialized() { + return imageRegistry != null; + } /** * Initialize the image registry by declaring all of the required diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DelegatingModelPresentation.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DelegatingModelPresentation.java index 6bd340fe1..8f3425e57 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DelegatingModelPresentation.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DelegatingModelPresentation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -30,6 +30,7 @@ import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugEditorPresentation; import org.eclipse.debug.ui.IDebugModelPresentation; +import org.eclipse.debug.ui.IDebugModelPresentationExtension; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.IInstructionPointerPresentation; import org.eclipse.debug.ui.IValueDetailListener; @@ -51,7 +52,8 @@ import org.eclipse.ui.IEditorPart; * asked to render an object from a debug model, this presentation delegates * to the extension registered for that debug model. */ -public class DelegatingModelPresentation implements IDebugModelPresentation, IDebugEditorPresentation, IColorProvider, IFontProvider, IInstructionPointerPresentation { +public class DelegatingModelPresentation implements IDebugModelPresentation, IDebugEditorPresentation, + IColorProvider, IFontProvider, IInstructionPointerPresentation, IDebugModelPresentationExtension { /** * A mapping of attribute ids to their values @@ -62,11 +64,6 @@ public class DelegatingModelPresentation implements IDebugModelPresentation, IDe * A table of label providers keyed by debug model identifiers. */ private HashMap fLabelProviders= new HashMap(5); - - /** - * Whether the image registry has been initialized. - */ - private boolean fInitialized = false; /* (non-Javadoc) * @see org.eclipse.debug.ui.IDebugEditorPresentation#removeAnnotations(org.eclipse.ui.IEditorPart, org.eclipse.debug.core.model.IThread) @@ -140,7 +137,6 @@ public class DelegatingModelPresentation implements IDebugModelPresentation, IDe * @see IDebugModelPresentation#getImage(Object) */ public Image getImage(Object item) { - initImageRegistries(); // Attempt to delegate IDebugModelPresentation lp= getConfiguredPresentation(item); if (lp != null) { @@ -465,23 +461,18 @@ public class DelegatingModelPresentation implements IDebugModelPresentation, IDe return null; } - public boolean isInitialized(Object element) { - LazyModelPresentation configuredPresentation = (LazyModelPresentation) getConfiguredPresentation(element); - if (configuredPresentation != null) { - return configuredPresentation.isImageRegistryInitialized(); - } - return false; - } - - /** - * Initialize image registries that this model presentation references to + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDebugModelPresentationExtension#requiresUIThread(java.lang.Object) */ - private synchronized void initImageRegistries() { - // if not initialized and this is called on the UI thread - if (!fInitialized && Thread.currentThread().equals(DebugUIPlugin.getStandardDisplay().getThread())) { - // force image registries to be created on the UI thread - DebugUIPlugin.getDefault().getImageRegistry(); - fInitialized = true; + public boolean requiresUIThread(Object element) { + IDebugModelPresentation presentation = getConfiguredPresentation(element); + if (presentation == null) { + // default label provider will be used + return !DebugPluginImages.isInitialized(); } + if (presentation instanceof IDebugModelPresentationExtension) { + return ((IDebugModelPresentationExtension)presentation).requiresUIThread(element); + } + return false; } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/LazyModelPresentation.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/LazyModelPresentation.java index 14a33949c..7e8723a9b 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/LazyModelPresentation.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/LazyModelPresentation.java @@ -29,6 +29,7 @@ import org.eclipse.debug.core.model.IVariable; import org.eclipse.debug.internal.ui.views.variables.IndexedVariablePartition; import org.eclipse.debug.ui.IDebugEditorPresentation; import org.eclipse.debug.ui.IDebugModelPresentation; +import org.eclipse.debug.ui.IDebugModelPresentationExtension; import org.eclipse.debug.ui.IInstructionPointerPresentation; import org.eclipse.debug.ui.IValueDetailListener; import org.eclipse.jface.text.source.Annotation; @@ -47,7 +48,8 @@ import org.eclipse.ui.IEditorPart; * when it is needed. */ -public class LazyModelPresentation implements IDebugModelPresentation, IDebugEditorPresentation, IColorProvider, IFontProvider, IInstructionPointerPresentation { +public class LazyModelPresentation implements IDebugModelPresentation, IDebugEditorPresentation, + IColorProvider, IFontProvider, IInstructionPointerPresentation, IDebugModelPresentationExtension { /** * A temporary mapping of attribute ids to their values @@ -71,8 +73,6 @@ public class LazyModelPresentation implements IDebugModelPresentation, IDebugEdi */ protected ListenerList fListeners= new ListenerList(); - protected boolean fImageRegistryInitialized = false; - /** * Non-null when nested inside a delegating model presentation */ @@ -123,7 +123,7 @@ public class LazyModelPresentation implements IDebugModelPresentation, IDebugEdi * @see IDebugModelPresentation#getImage(Object) */ public Image getImage(Object element) { - fImageRegistryInitialized = true; + initImageRegistry(); Image image = getPresentation().getImage(element); if (image == null) { image = getDefaultImage(element); @@ -138,8 +138,13 @@ public class LazyModelPresentation implements IDebugModelPresentation, IDebugEdi return image; } - public boolean isImageRegistryInitialized() { - return fImageRegistryInitialized; + /** + * Initializes the image registry + */ + private synchronized void initImageRegistry() { + if (!DebugPluginImages.isInitialized()) { + DebugUIPlugin.getDefault().getImageRegistry(); + } } /** @@ -460,4 +465,19 @@ public class LazyModelPresentation implements IDebugModelPresentation, IDebugEdi } return null; } + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.IDebugModelPresentationExtension#requiresUIThread(java.lang.Object) + */ + public boolean requiresUIThread(Object element) { + if (!DebugPluginImages.isInitialized()) { + // need UI thread for breakpoint adornment and default images + return true; + } + IDebugModelPresentation presentation = getPresentation(); + if (presentation instanceof IDebugModelPresentationExtension) { + return ((IDebugModelPresentationExtension) presentation).requiresUIThread(element); + } + return false; + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/DebugElementLabelProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/DebugElementLabelProvider.java index 32f408a6f..8dd7a59d3 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/DebugElementLabelProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/DebugElementLabelProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,10 +12,12 @@ package org.eclipse.debug.internal.ui.model.elements; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.internal.ui.DelegatingModelPresentation; +import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.views.DebugModelPresentationContext; import org.eclipse.debug.internal.ui.views.launch.DebugElementHelper; import org.eclipse.debug.ui.IDebugModelPresentation; +import org.eclipse.debug.ui.IDebugModelPresentationExtension; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.TreePath; import org.eclipse.swt.graphics.FontData; @@ -89,5 +91,28 @@ public class DebugElementLabelProvider extends ElementLabelProvider { } return null; } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider#requiresUIJob(org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate[]) + */ + protected boolean requiresUIJob(ILabelUpdate[] updates) { + if (updates.length > 0) { + ILabelUpdate update = updates[0]; + IPresentationContext context = update.getPresentationContext(); + if (context instanceof DebugModelPresentationContext) { + DebugModelPresentationContext debugContext = (DebugModelPresentationContext) context; + IDebugModelPresentation presentation = debugContext.getModelPresentation(); + if (presentation instanceof IDebugModelPresentationExtension) { + IDebugModelPresentationExtension extension = (IDebugModelPresentationExtension) presentation; + for (int i = 0; i < updates.length; i++) { + if (extension.requiresUIThread(updates[i].getElement())) { + return true; + } + } + } + } + } + return false; + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/provisional/AsynchronousLabelAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/provisional/AsynchronousLabelAdapter.java index 9ce1554b3..c2377e093 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/provisional/AsynchronousLabelAdapter.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/provisional/AsynchronousLabelAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -78,7 +78,7 @@ public abstract class AsynchronousLabelAdapter implements IAsynchronousLabelAdap * @return whether this label adapter requires to be run in the UI thread. */ protected boolean requiresUIJob(Object object) { - return !DebugElementHelper.isInitialized(object); + return !DebugElementHelper.requiresUIThread(object); } /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java index 27f4f0188..efafa7b7c 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -49,12 +49,6 @@ public class DebugElementHelper { } } - - public static boolean isInitialized(Object object) { - DelegatingModelPresentation presentation = getPresentation(); - return presentation.isInitialized(object); - } - /** * Returns an image descriptor for the given debug element. * @@ -229,5 +223,17 @@ public class DebugElementHelper { return font.getFontData()[0]; } return null; - } + } + + /** + * Returns whether the UI thread is required for computing the label for the + * given object. + * + * @param object object a label is being computed for + * @return whether the UI thread is required + */ + public static boolean requiresUIThread(Object object) { + DelegatingModelPresentation presentation = getPresentation(); + return presentation.requiresUIThread(object); + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugModelPresentationExtension.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugModelPresentationExtension.java new file mode 100644 index 000000000..144dad097 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugModelPresentationExtension.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.ui; + +/** + * Optional extension for an {@link IDebugModelPresentation}. Dynamically controls + * whether labels are computed in a UI thread. The debug platform calls debug model + * presentation label related methods that do not implement this interface in a + * <b>non-UI</b> thread. + * <p> + * For example, some models may require at least one access in a UI thread to initialize + * an image registry at which point they may be able to provide labels in a non-UI + * thread. + * </p> + * <p> + * Clients implementing a debug model presentation should also implement + * this interface to control which thread labels are generated in. + * </p> + * @since 3.4 + */ +public interface IDebugModelPresentationExtension extends IDebugModelPresentation { + + /** + * Returns whether the UI thread is required to retrieve a label (text, image, font, + * foreground, background, etc.), for the specified element. When <code>true</code> is + * returned, label related methods will be called in the UI thread, otherwise methods + * may be called in a non-UI thread. + * + * @param element the element a label is to be retrieved for + * @return whether label related methods should be called on the UI thread + */ + public boolean requiresUIThread(Object element); +} |