Author: yradtsevich
Date: 2011-11-25 09:42:23 -0500 (Fri, 25 Nov 2011)
New Revision: 36661
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/SwtUtil.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.resref/src/org/jboss/tools/vpe/resref/core/VpeResourcesDialog.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/SplitToolBar.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeDropDownMenu.java
Log:
https://issues.jboss.org/browse/JBIDE-10221 /
https://issues.jboss.org/browse/JBIDE-10249 : org.jboss.tools.vpe plugin has Image leak
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/SwtUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/SwtUtil.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/SwtUtil.java 2011-11-25
14:42:23 UTC (rev 36661)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.util;
+
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Resource;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class SwtUtil {
+
+ /**
+ * Adds a dispose listener to {@code widget}
+ * which when invoked disposes given {@code resource}
+ *
+ * @param resource resource to be disposed
+ * @param widget widget to which disposal bind disposal of {@code resource}
+ */
+ public static void bindDisposal(final Resource resource, Widget widget) {
+ widget.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ resource.dispose();
+ System.out.println("Resource Disposed: " + resource);
+ }
+ });
+ }
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java 2011-11-25
13:21:37 UTC (rev 36660)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeEditAnyDialog.java 2011-11-25
14:42:23 UTC (rev 36661)
@@ -40,6 +40,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.jboss.tools.common.model.ui.ModelUIImages;
+import org.jboss.tools.common.util.SwtUtil;
import org.jboss.tools.jst.css.CSSPlugin;
import org.jboss.tools.jst.css.dialog.CSSStyleDialog;
import org.jboss.tools.jst.css.dialog.common.Util;
@@ -96,8 +97,10 @@
*/
getShell().setText(VpeUIMessages.TEMPLATE);
setTitle(VpeUIMessages.TAG_ATTRIBUTES);
- setTitleImage(ModelUIImages.getImageDescriptor(
- ModelUIImages.WIZARD_DEFAULT).createImage(null));
+ final Image titleImage = ModelUIImages.getImageDescriptor(
+ ModelUIImages.WIZARD_DEFAULT).createImage(null);
+ setTitleImage(titleImage);
+ SwtUtil.bindDisposal(titleImage, getShell());
setMessage(VpeUIMessages.USER_SPECIFIED_TAG_DIALOG_DESCRIPTION);
/*
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/SplitToolBar.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/SplitToolBar.java 2011-11-25
13:21:37 UTC (rev 36660)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/SplitToolBar.java 2011-11-25
14:42:23 UTC (rev 36661)
@@ -102,7 +102,9 @@
// coolBar.layout();
// final Button button = new Button(parent, SWT.FLAT|SWT.PUSH);
-// button.setImage(ImageDescriptor.createFromFile(MozillaEditor.class,
"icons/arrow_more.gif").createImage());
+// Image arrowMoreImage = ImageDescriptor.createFromFile(MozillaEditor.class,
"icons/arrow_more.gif").createImage();
+// button.setImage(arrowMoreImage);
+// SWTUtil.bindDisposal(arrowMoreImage, button);
// button.setVisible(false);
//
// button.addListener(SWT.Selection, new Listener() {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeDropDownMenu.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeDropDownMenu.java 2011-11-25
13:21:37 UTC (rev 36660)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/toolbar/VpeDropDownMenu.java 2011-11-25
14:42:23 UTC (rev 36661)
@@ -16,11 +16,13 @@
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
+import org.jboss.tools.common.util.SwtUtil;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
/**
@@ -34,8 +36,10 @@
public VpeDropDownMenu(ToolBar bar, String toolTipText) {
ToolItem item = new ToolItem(bar, SWT.MENU);
item.setToolTipText(toolTipText);
- item.setImage(ImageDescriptor.createFromFile(MozillaEditor.class,
- "icons/arrow.gif").createImage()); //$NON-NLS-1$
+ final Image arrowImage = ImageDescriptor.createFromFile(MozillaEditor.class,
+ "icons/arrow.gif").createImage(); //$NON-NLS-1$
+ item.setImage(arrowImage);
+ SwtUtil.bindDisposal(arrowImage, item);
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.resref/src/org/jboss/tools/vpe/resref/core/VpeResourcesDialog.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.resref/src/org/jboss/tools/vpe/resref/core/VpeResourcesDialog.java 2011-11-25
13:21:37 UTC (rev 36660)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.resref/src/org/jboss/tools/vpe/resref/core/VpeResourcesDialog.java 2011-11-25
14:42:23 UTC (rev 36661)
@@ -36,6 +36,7 @@
import org.jboss.tools.common.model.ui.ModelUIImages;
import org.jboss.tools.common.model.ui.action.CommandBar;
import org.jboss.tools.common.resref.core.ResourceReference;
+import org.jboss.tools.common.util.SwtUtil;
public class VpeResourcesDialog extends TitleAreaDialog {
@@ -76,11 +77,7 @@
final Image wizardDefaultImage = ModelUIImages.getImageDescriptor(
ModelUIImages.WIZARD_DEFAULT).createImage(null);
setTitleImage(wizardDefaultImage);
- parent.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- wizardDefaultImage.dispose();
- }
- });
+ SwtUtil.bindDisposal(wizardDefaultImage, parent);
setMessage(Messages.VRD_PAGE_DESIGN_OPTIONS_ABOUT);
Composite composite = new Composite(parent, SWT.NONE);