Skip to content

Commit c3716d0

Browse files
committed
Bug 154145 - [Palette] PaletteEditPart should use JFace resource manager
Currently the PaletteEditPart creates images and stores them in a static map, These images are never disposed. By using the JFace resource manager, they are now bound to the lifecycle of the underlying viewer. Closes https://bugs.eclipse.org/bugs/show_bug.cgi?id=154145
1 parent 1f5cf49 commit c3716d0

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

org.eclipse.gef/src/org/eclipse/gef/ui/palette/editparts/PaletteEditPart.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -25,6 +25,7 @@
2525
import org.eclipse.swt.widgets.Display;
2626

2727
import org.eclipse.jface.resource.ImageDescriptor;
28+
import org.eclipse.jface.resource.ResourceManager;
2829
import org.eclipse.ui.IMemento;
2930

3031
import org.eclipse.draw2d.Border;
@@ -58,6 +59,11 @@ public abstract class PaletteEditPart extends AbstractGraphicalEditPart implemen
5859
*/
5960
public static final String XML_NAME = "entry"; //$NON-NLS-1$
6061
private static final Border TOOLTIP_BORDER = new MarginBorder(0, 2, 1, 0);
62+
/**
63+
* @deprecated Use {@code getViewer().getResourceManager()} instead. This field
64+
* will be removed after the 2025-12 release.
65+
*/
66+
@Deprecated(forRemoval = true, since = "2025-12")
6167
private static ImageCache globalImageCache;
6268
private AccessibleEditPart acc;
6369
private final PropertyChangeListener childListener = evt -> {
@@ -206,7 +212,10 @@ public DragTracker getDragTracker(Request request) {
206212
* the same image in different palettes is only ever created once.
207213
*
208214
* @return the image cache.
215+
* @deprecated Use {@code getViewer().getResourceManager()} instead. This method
216+
* will be removed after the 2025-12 release.
209217
*/
218+
@Deprecated(forRemoval = true, since = "2025-12")
210219
protected static ImageCache getImageCache() {
211220
ImageCache cache = globalImageCache;
212221
if (cache == null) {
@@ -419,8 +428,12 @@ protected void setImageDescriptor(ImageDescriptor desc) {
419428
if (desc == imgDescriptor) {
420429
return;
421430
}
431+
ResourceManager resourceManager = getViewer().getResourceManager();
432+
if (imgDescriptor != null) {
433+
resourceManager.destroy(imgDescriptor);
434+
}
422435
imgDescriptor = desc;
423-
setImageInFigure(getImageCache().getImage(imgDescriptor));
436+
setImageInFigure(resourceManager.create(imgDescriptor));
424437
}
425438

426439
/**
@@ -450,7 +463,11 @@ private void traverseChildren(List<? extends PaletteEntry> children, boolean add
450463

451464
/**
452465
* The image cache for this edit part.
466+
*
467+
* @deprecated Use {@code getViewer().getResourceManager()} instead. This class
468+
* will be removed after the 2025-12 release.
453469
*/
470+
@Deprecated(forRemoval = true, since = "2025-12")
454471
protected static class ImageCache {
455472
/** Map from ImageDescriptor to Image */
456473
private final Map<ImageDescriptor, Image> images = new HashMap<>(11);

0 commit comments

Comments
 (0)