Bug 373298 - Fixed font resource leak with context button pad tooltip
fonts
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButton.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButton.java
index b5249d2..2c91efa 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButton.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButton.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2012 SAP AG.
* 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
@@ -10,6 +10,7 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* Bug 336488 - DiagramEditor API
+ * mwenz - Bug 373298 - Possible Resource leaks in Graphiti
*
* </copyright>
*
@@ -629,6 +630,15 @@
getContextButtonPad().getContextButtonManagerForPad().hideContextButtonsInstantly();
}
+ /*
+ * Introduced to fix bug 373298
+ */
+ void dispose() {
+ if (tooltip != null) {
+ tooltip.dispose();
+ }
+ }
+
/**
* Returns all context button menu entries, which are executable.
*
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButtonPad.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButtonPad.java
index 5a83359..2431d25 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButtonPad.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButtonPad.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2012 SAP AG.
* 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
@@ -10,6 +10,7 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* Bug 336488 - DiagramEditor API
+ * mwenz - Bug 373298 - Possible Resource leaks in Graphiti
*
* </copyright>
*
@@ -540,6 +541,16 @@
control.removeMouseTrackListener(mouseTrackListener);
super.removeNotify();
+
+ // Notify the ContextButton children of this pad to free its resources
+ // (holds a font). Introduced to fix bug 373298
+ List<?> childrenList = getChildren();
+ for (Object object : childrenList) {
+ if (object instanceof ContextButton) {
+ ((ContextButton) object).dispose();
+ }
+
+ }
}
// ============================== painting ================================
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/DataTypeTransformation.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/DataTypeTransformation.java
index 637d4b1..b985843 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/DataTypeTransformation.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/DataTypeTransformation.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2012 SAP AG.
* 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
@@ -9,6 +9,7 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 373298 - Possible Resource leaks in Graphiti
*
* </copyright>
*
@@ -85,6 +86,18 @@
return pointList;
}
+ /**
+ * Checks if the given SWT {@link org.eclipse.swt.graphics.Font} defines the
+ * same font as the given Graphiti {@link Font}. If yes, the given SWT Font
+ * is simply returned, otherwise a new SWT Font is created using
+ * {@link #toSwtFont(Font)}. <b>In case the returned SWT Font is not -
+ * instance-wise - the same as the given one, users of this method are
+ * responsible for disposing the returned font again.</b>
+ *
+ * @param pictogramFont
+ * @param swtFont
+ * @return
+ */
public static org.eclipse.swt.graphics.Font syncToSwtFont(Font pictogramFont, org.eclipse.swt.graphics.Font swtFont) {
org.eclipse.swt.graphics.Font ret = swtFont;
@@ -129,6 +142,10 @@
}
/**
+ * Returns a <b>new</b> SWT {@link org.eclipse.swt.graphics.Font} for the
+ * given Graphiti {@link Font}. <b>Users of this method are responsible for
+ * disposing the font again!</b>
+ *
* @param pictogramFont
* @return
*/
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/Tooltip.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/Tooltip.java
index a9af47e..824d8b0 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/Tooltip.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/Tooltip.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2012 SAP AG.
* 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
@@ -9,6 +9,7 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 373298 - Possible Resource leaks in Graphiti
*
* </copyright>
*
@@ -86,8 +87,17 @@
return d;
}
- // TODO: move to service layer
- public static Font getBoldFont() {
+ /*
+ * Introduced to fix bug 373298
+ */
+ public void dispose() {
+ if (boldFont != null) {
+ boldFont.dispose();
+ boldFont = null;
+ }
+ }
+
+ private Font getBoldFont() {
if (boldFont == null) {
FontData fd = Display.getDefault().getSystemFont().getFontData()[0];
fd.setStyle(fd.getStyle() | SWT.BOLD);