Skip to content

Commit b277e87

Browse files
committed
fix: Reworked resource handling for the ToolBarMenuManager
1 parent 2e25cc9 commit b277e87

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

plugins/de.ovgu.featureide.fm.ui/src/de/ovgu/featureide/fm/ui/editors/ToolBarMenuManager.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* FeatureIDE - A Framework for Feature-Oriented Software Development
22
* Copyright (C) 2005-2019 FeatureIDE team, University of Magdeburg, Germany
3+
* 2025 Malte Grave, VaSiCS, LIT CPS Lab, Johannes Kepler University, Linz
34
*
45
* This file is part of FeatureIDE.
56
*
@@ -38,26 +39,38 @@
3839
* @author Jonas Weigt
3940
* @author Christian Harnisch
4041
* @author Marcus Pinnecke
42+
* @author Malte Grave
4143
*/
4244

4345
public class ToolBarMenuManager extends MenuManager {
4446

45-
private Image image;
47+
private ImageDescriptor imageDescriptor;
4648

4749
public ToolBarMenuManager(String text) {
4850
super(text);
4951
}
5052

51-
public ToolBarMenuManager(String text, ImageDescriptor image, String id) {
52-
super(text, image, id);
53-
this.image = image.createImage();
53+
public ToolBarMenuManager(String text, ImageDescriptor imageDescriptor, String id) {
54+
super(text, imageDescriptor, id);
55+
this.imageDescriptor = imageDescriptor;
5456
}
5557

5658
@Override
5759
public void fill(final ToolBar toolbar, int index) {
5860
final ToolItem toolItem = (index >= 0) ? new ToolItem(toolbar, SWT.DROP_DOWN, index) : new ToolItem(toolbar, SWT.DROP_DOWN);
5961
toolItem.setText(getMenuText());
60-
toolItem.setImage(image);
62+
63+
if (imageDescriptor != null) {
64+
final Image img = imageDescriptor.createImage();
65+
toolItem.setImage(img);
66+
67+
toolItem.addDisposeListener(e -> {
68+
if ((img != null) && !img.isDisposed()) {
69+
img.dispose();
70+
}
71+
});
72+
}
73+
6174
toolItem.addSelectionListener(new SelectionListener() {
6275

6376
@Override
@@ -73,15 +86,4 @@ public void widgetSelected(SelectionEvent e) {
7386
public void widgetDefaultSelected(SelectionEvent e) {}
7487
});
7588
}
76-
77-
/*
78-
* (non-Javadoc)
79-
* @see org.eclipse.jface.action.MenuManager#dispose()
80-
*/
81-
@Override
82-
public void dispose() {
83-
image.dispose();
84-
super.dispose();
85-
}
86-
8789
}

0 commit comments

Comments
 (0)