diff options
author | Boris Bokowski | 2008-05-09 13:44:01 +0000 |
---|---|---|
committer | Boris Bokowski | 2008-05-09 13:44:01 +0000 |
commit | a224c33b671041590d88061bc9bc7b86a1fbcf8f (patch) | |
tree | 77e397e67e763117eb202f96968e0aabf69a5420 /bundles | |
parent | 6880de0669e9af04c9568a8295f6ae729af08fcc (diff) | |
download | eclipse.platform.ui-a224c33b671041590d88061bc9bc7b86a1fbcf8f.tar.gz eclipse.platform.ui-a224c33b671041590d88061bc9bc7b86a1fbcf8f.tar.xz eclipse.platform.ui-a224c33b671041590d88061bc9bc7b86a1fbcf8f.zip |
Fix for Bug 231175 [Workbench] WorkbenchLabelProvider leaks
Diffstat (limited to 'bundles')
3 files changed, 13 insertions, 118 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java index 4dbb8f4d932..4121767beb8 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPlugin.java @@ -60,7 +60,6 @@ import org.eclipse.ui.internal.themes.IThemeRegistry; import org.eclipse.ui.internal.themes.ThemeRegistry; import org.eclipse.ui.internal.themes.ThemeRegistryReader; import org.eclipse.ui.internal.util.BundleUtility; -import org.eclipse.ui.internal.util.SWTResourceUtil; import org.eclipse.ui.internal.wizards.ExportWizardRegistry; import org.eclipse.ui.internal.wizards.ImportWizardRegistry; import org.eclipse.ui.internal.wizards.NewWizardRegistry; @@ -1102,7 +1101,6 @@ public class WorkbenchPlugin extends AbstractUIPlugin { // TODO normally super.stop(*) would be the last statement in this // method super.stop(context); - SWTResourceUtil.shutdown(); } /** diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/SWTResourceUtil.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/SWTResourceUtil.java deleted file mode 100644 index 7701c95abe8..00000000000 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/SWTResourceUtil.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.ui.internal.util; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; - -/** - * SWTResourceUtil is a class that holds onto Colors, Fonts and Images and - * disposes them on shutdown. - */ -public class SWTResourceUtil { - - /** - * The cache of images that have been dispensed by this provider. Maps - * ImageDescriptor->Image. Caches are all static to avoid creating extra - * system resources for very common images, font and colors. - */ - private static Map imageTable = new Hashtable(40); - - /** - * The cache of colors that have been dispensed by this provider. Maps - * RGB->Color. - */ - private static Map colorTable = new Hashtable(7); - - /** - * The cache of fonts that have been dispensed by this provider. Maps - * FontData->Font. - */ - private static Map fontTable = new Hashtable(7); - - /** - * Disposes of all allocated images, colors and fonts when shutting down the - * plug-in. - */ - public static final void shutdown() { - if (imageTable != null) { - for (Iterator i = imageTable.values().iterator(); i.hasNext();) { - ((Image) i.next()).dispose(); - } - imageTable = null; - } - if (colorTable != null) { - for (Iterator i = colorTable.values().iterator(); i.hasNext();) { - ((Color) i.next()).dispose(); - } - colorTable = null; - } - if (fontTable != null) { - for (Iterator i = fontTable.values().iterator(); i.hasNext();) { - ((Font) i.next()).dispose(); - } - fontTable = null; - } - } - - /** - * Get the Map of RGBs to Colors. - * @return Returns the colorTable. - */ - public static Map getColorTable() { - return colorTable; - } - - /** - * Return the map of FontDatas to Fonts. - * @return Returns the fontTable. - */ - public static Map getFontTable() { - return fontTable; - } - - /** - * Return the map of ImageDescriptors to Images. - * @return Returns the imageTable. - */ - public static Map getImageTable() { - return imageTable; - } -} diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/model/WorkbenchLabelProvider.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/model/WorkbenchLabelProvider.java index 6e9d28c063c..8cc1f7d6b73 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/model/WorkbenchLabelProvider.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/model/WorkbenchLabelProvider.java @@ -10,7 +10,12 @@ *******************************************************************************/ package org.eclipse.ui.model; +import org.eclipse.jface.resource.ColorDescriptor; +import org.eclipse.jface.resource.FontDescriptor; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.jface.resource.ResourceManager; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IFontProvider; @@ -22,11 +27,9 @@ import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.IPropertyListener; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.internal.util.SWTResourceUtil; import org.eclipse.ui.internal.util.Util; /** @@ -63,13 +66,15 @@ public class WorkbenchLabelProvider extends LabelProvider implements fireLabelProviderChanged(new LabelProviderChangedEvent(WorkbenchLabelProvider.this)); } } - }; + }; + private ResourceManager resourceManager; /** * Creates a new workbench label provider. */ public WorkbenchLabelProvider() { PlatformUI.getWorkbench().getEditorRegistry().addPropertyListener(editorRegistryListener); + this.resourceManager = new LocalResourceManager(JFaceResources.getResources()); } /** @@ -110,6 +115,8 @@ public class WorkbenchLabelProvider extends LabelProvider implements */ public void dispose() { PlatformUI.getWorkbench().getEditorRegistry().removePropertyListener(editorRegistryListener); + resourceManager.dispose(); + resourceManager = null; super.dispose(); } @@ -152,12 +159,7 @@ public class WorkbenchLabelProvider extends LabelProvider implements //add any annotations to the image descriptor descriptor = decorateImage(descriptor, element); - Image image = (Image) SWTResourceUtil.getImageTable().get(descriptor); - if (image == null) { - image = descriptor.createImage(); - SWTResourceUtil.getImageTable().put(descriptor, image); - } - return image; + return resourceManager.createImage(descriptor); } /* (non-Javadoc) @@ -203,12 +205,7 @@ public class WorkbenchLabelProvider extends LabelProvider implements return null; } - Font font = (Font) SWTResourceUtil.getFontTable().get(descriptor); - if (font == null) { - font = new Font(Display.getCurrent(), descriptor); - SWTResourceUtil.getFontTable().put(descriptor, font); - } - return font; + return resourceManager.createFont(FontDescriptor.createFrom(descriptor)); } private Color getColor(Object element, boolean forground) { @@ -222,11 +219,6 @@ public class WorkbenchLabelProvider extends LabelProvider implements return null; } - Color color = (Color) SWTResourceUtil.getColorTable().get(descriptor); - if (color == null) { - color = new Color(Display.getCurrent(), descriptor); - SWTResourceUtil.getColorTable().put(descriptor, color); - } - return color; + return resourceManager.createColor(ColorDescriptor.createFrom(descriptor)); } } |