1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 243907 - AbstractCPropertyTab#dispose() never called

- AbstractPage leaks Tab icon SWT Images
    - AbstractCPropertyTab uses reflection for setGrayed API
This commit is contained in:
James Blackburn 2009-10-20 16:40:30 +00:00
parent 353d1d0875
commit ae5e0a74f3
2 changed files with 32 additions and 17 deletions

View file

@ -8,10 +8,10 @@
* Contributors: * Contributors:
* Intel Corporation - initial API and implementation * Intel Corporation - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* James Blackburn (Broadcom Corp.)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.newui; package org.eclipse.cdt.ui.newui;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
@ -533,6 +533,7 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab {
if (canBeVisible()) configChanged((ICResourceDescription)data); if (canBeVisible()) configChanged((ICResourceDescription)data);
break; break;
case ICPropertyTab.DISPOSE: case ICPropertyTab.DISPOSE:
dispose();
break; break;
case ICPropertyTab.VISIBLE: case ICPropertyTab.VISIBLE:
if (canBeVisible()) if (canBeVisible())
@ -607,16 +608,11 @@ public abstract class AbstractCPropertyTab implements ICPropertyTab {
* *
* @param b * @param b
* @param value * @param value
* @deprecated call {@link Button#setGrayed(boolean)} instead
*/ */
@Deprecated
public static void setGrayed(Button b, boolean value) { public static void setGrayed(Button b, boolean value) {
// TODO: uncomment before M5 b.setGrayed(value);
// b.setGrayed(value);
if (GRAY_METHOD != null)
try {
GRAY_METHOD.invoke(b, new Object[] { new Boolean(value) });
}
catch (InvocationTargetException e) {}
catch (IllegalAccessException e) {}
} }
/** /**

View file

@ -10,6 +10,7 @@
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Andrew Gvozdev * Andrew Gvozdev
* QNX Software Systems - [271628] NPE in configs for project that failed to convert * QNX Software Systems - [271628] NPE in configs for project that failed to convert
* James Blackburn (Broadcom Corp.)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.newui; package org.eclipse.cdt.ui.newui;
@ -20,8 +21,10 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
@ -145,6 +148,8 @@ implements
private static final String PREF_ASK_REINDEX = "askReindex"; //$NON-NLS-1$ private static final String PREF_ASK_REINDEX = "askReindex"; //$NON-NLS-1$
private Map<URL, Image> loadedIcons = new HashMap<URL, Image>();
private final Image IMG_WARN = CPluginImages.get(CPluginImages.IMG_OBJS_REFACTORING_WARNING); private final Image IMG_WARN = CPluginImages.get(CPluginImages.IMG_OBJS_REFACTORING_WARNING);
/* /*
* Dialog widgets * Dialog widgets
@ -961,7 +966,13 @@ implements
@Override @Override
public void dispose() { public void dispose() {
if (displayedConfig) forEach(ICPropertyTab.DISPOSE); // Dispose the tabs
if (displayedConfig)
forEach(ICPropertyTab.DISPOSE);
// Dispose any loaded images
for (Image img : loadedIcons.values())
img.dispose();
loadedIcons.clear();
if (!isNewOpening) if (!isNewOpening)
handleResize(false); // save page size handleResize(false); // save page size
@ -1093,14 +1104,22 @@ implements
private Image getIcon(IConfigurationElement config) { private Image getIcon(IConfigurationElement config) {
ImageDescriptor idesc = null; ImageDescriptor idesc = null;
URL url = null;
try { try {
String iconName = config.getAttribute(IMAGE_NAME); String iconName = config.getAttribute(IMAGE_NAME);
if (iconName != null) { if (iconName != null) {
URL pluginInstallUrl = Platform.getBundle(config.getDeclaringExtension().getContributor().getName()).getEntry("/"); //$NON-NLS-1$ URL pluginInstallUrl = Platform.getBundle(config.getDeclaringExtension().getContributor().getName()).getEntry("/"); //$NON-NLS-1$
idesc = ImageDescriptor.createFromURL(new URL(pluginInstallUrl, iconName)); url = new URL(pluginInstallUrl, iconName);
if (loadedIcons.containsKey(url))
return loadedIcons.get(url);
idesc = ImageDescriptor.createFromURL(url);
} }
} catch (MalformedURLException exception) {} } catch (MalformedURLException exception) {}
return (idesc == null) ? null : idesc.createImage(); if (idesc == null)
return null;
Image img = idesc.createImage();
loadedIcons.put(url, img);
return img;
} }
public void informAll(int code, Object data) { public void informAll(int code, Object data) {