summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2012-10-26 12:09:18 (EDT)
committerKaren Butzke2012-10-26 14:09:02 (EDT)
commit50b9c9bb28a5e9b3fe4196ef5387433ec0c9d2ca (patch)
tree41473611030bb164fd116ff672e08a8a43350404
parent0423dd93718288c1e086564cada8476053510e9d (diff)
downloadwebtools.dali-50b9c9bb28a5e9b3fe4196ef5387433ec0c9d2ca.zip
webtools.dali-50b9c9bb28a5e9b3fe4196ef5387433ec0c9d2ca.tar.gz
webtools.dali-50b9c9bb28a5e9b3fe4196ef5387433ec0c9d2ca.tar.bz2
Use a DisposeListener instead of manually disposing
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/AssociationsListComposite.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableAssociationsWizardPage.java10
2 files changed, 25 insertions, 15 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/AssociationsListComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/AssociationsListComposite.java
index 1b1c043..02485b5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/AssociationsListComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/AssociationsListComposite.java
@@ -20,9 +20,10 @@ import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jpt.jpa.gen.internal.Association;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
/**
* A Draw2d figure representing list of associations between two database tables
@@ -35,6 +36,12 @@ public class AssociationsListComposite extends FigureCanvas {
TableAssociationsWizardPage tableAssociationsWizardPage; //the parent wizard page
AssociationFigure selectedAssociationFigure ;
+ /**
+ * A listener that allows us to stop listening to stuff when the control
+ * is disposed. (Critical for preventing memory leaks.)
+ */
+ private final DisposeListener disposeListener;
+
protected final ResourceManager resourceManager;
public AssociationsListComposite(Composite parent, TableAssociationsWizardPage tableAssociationsWizardPage, ResourceManager resourceManager){
@@ -50,7 +57,10 @@ public class AssociationsListComposite extends FigureCanvas {
Figure figure = new Figure();
figure.setLayoutManager(new ToolbarLayout());
figure.setBorder(new LineBorder(1));
- this.listener = new AssociationToggleSelectionListener();
+ this.listener = new AssociationToggleSelectionListener();
+
+ this.disposeListener = new ControlDisposeListener();
+ this.addDisposeListener(this.disposeListener);
this.setContents(figure);
}
@@ -103,10 +113,9 @@ public class AssociationsListComposite extends FigureCanvas {
return ret==null?null:ret.getAssociation();
}
- @Override
- public void dispose() {
+ protected void controlDisposed() {
this.disposeFigure((Figure) getContents());
- super.dispose();
+ this.removeDisposeListener(this.disposeListener);
}
@SuppressWarnings("unchecked")
@@ -134,4 +143,15 @@ public class AssociationsListComposite extends FigureCanvas {
selectedAssociationFigure.setSelected( true );
}
}
+
+ private class ControlDisposeListener
+ implements DisposeListener {
+ public void widgetDisposed(DisposeEvent e) {
+ AssociationsListComposite.this.controlDisposed();
+ }
+ @Override
+ public String toString() {
+ return "control dispose listener"; //$NON-NLS-1$
+ }
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableAssociationsWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableAssociationsWizardPage.java
index 18dc270..e428cb9 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableAssociationsWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TableAssociationsWizardPage.java
@@ -757,14 +757,4 @@ public class TableAssociationsWizardPage extends WizardPage {
protected final IWorkbenchHelpSystem getHelpSystem() {
return PlatformUI.getWorkbench().getHelpSystem();
}
-
- @Override
- public void dispose() {
- //when the JPA project wizard page is shown first, the other wizard pages are lazily built, thus
- //associationList can be null - bug 307894
- if (this.associationList != null) {
- this.associationList.dispose();
- }
- super.dispose();
- }
}