Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer simplified version to create LocalResourceManager #1213

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
* <code>LocalResourceManager(JFaceResources.getResources(), owner)</code>
*
* @param owner control whose disposal will trigger cleanup of everything in the
* registry.
*/
static LocalResourceManager managerFor(Control owner) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this package private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this package private?

Thanks for the catch. Will be fixed with
#1218

return new LocalResourceManager(getResources(), owner);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use control.getData/setData to cache the instance created so multiple calls could be performed without creating multiple managers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you estimate how often that will hit the cache?
Since the local-manager is a child from the global one caching would not save SWT-resources but mainly only another map.

}
/**
* Declare a private constructor to block instantiation.
*/
Expand Down