From 5f47dacbc164b6f19e4ef26428611d28358dc732 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Wed, 11 Oct 2023 21:09:50 +0200 Subject: [PATCH] Offer simplified version to create LocalResourceManager Frequently LocalResourceManager(JFaceResources.getResources(), parent) is used in client code. This add a helper method on JFaceResource to simplify such call. Fixed #1208 --- .../eclipse/jface/resource/JFaceResources.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/JFaceResources.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/JFaceResources.java index 3bac94e1ef5..f5bcbd094af 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/JFaceResources.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/JFaceResources.java @@ -32,6 +32,7 @@ import org.eclipse.jface.wizard.Wizard; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkUtil; @@ -583,6 +584,23 @@ public static void setFontRegistry(FontRegistry registry) { fontRegistry = registry; } + + /** + * Creates a local registry that wraps the ResourceManager for the current + * display. Anything allocated by this registry will be automatically cleaned up + * with the given control is disposed. Note that registries created in this way + * should not be used to allocate any resource that must outlive the given + * control. + * + * shortcut for + * LocalResourceManager(JFaceResources.getResources(), owner) + * + * @param owner control whose disposal will trigger cleanup of everything in the + * registry. + */ + static LocalResourceManager managerFor(Control owner) { + return new LocalResourceManager(getResources(), owner); + } /** * Declare a private constructor to block instantiation. */