Revision: 3558
Author: [email protected]
Date: Wed May 26 14:48:19 2010
Log: The listeners from Relationships were not being removed when the
relationship was removed. Now the relationship listeners
are removed on removal from the container and added back in by a call to
connect.
http://code.google.com/p/power-architect/source/detail?r=3558
Modified:
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenContentPane.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/Relationship.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
Fri May 7 08:33:40 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenComponent.java
Wed May 26 14:48:19 2010
@@ -717,4 +717,14 @@
}
}
}
-}
+
+ /**
+ * You must call this method when you are adding a TablePane component
after
+ * the parent is defined. It will register the necessary listeners to
all
+ * necessary parties.
+ */
+ public void connect() {
+ //by default do nothing.
+ }
+
+}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenContentPane.java
Thu May 13 08:32:46 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenContentPane.java
Wed May 26 14:48:19 2010
@@ -242,9 +242,7 @@
if (getPlayPen() != null) {
ppc.addSelectionListener(getPlayPen());
}
- if (ppc instanceof TablePane) {
- ((TablePane) ppc).connect();
- }
+ ppc.connect();
fireChildAdded(ppc.getClass(), ppc, pos);
ppc.revalidate();
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/Relationship.java
Tue Apr 6 14:44:35 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/Relationship.java
Wed May 26 14:48:19 2010
@@ -109,12 +109,24 @@
private boolean selected;
- private TablePaneBehaviourListener tpbListener = new
TablePaneBehaviourListener();
+ private final TablePaneBehaviourListener tpbListener = new
TablePaneBehaviourListener();
/**
* The colour to highlight related columns with when this relationship is
selected.
*/
private Color columnHighlightColour = ColourScheme.SQLPOWER_ORANGE;
+
+ /**
+ * This listener will disconnect this pane from the model if the pane
is removed from the
+ * container.
+ */
+ private final AbstractSPListener containerPaneListener = new
AbstractSPListener() {
+ public void childRemoved(SPChildEvent e) {
+ if (e.getChild() == Relationship.this) {
+ destroy();
+ }
+ }
+ };
/**
* This constructor is only for making a copy of an existing
relationship component.
@@ -134,7 +146,6 @@
this.pkConnectionPoint = new Point(r.getPkConnectionPoint());
this.fkConnectionPoint = new Point(r.getFkConnectionPoint());
this.selected = false;
- this.tpbListener = new TablePaneBehaviourListener();
this.columnHighlightColour = r.columnHighlightColour;
this.foregroundColor = r.getForegroundColor();
@@ -279,6 +290,36 @@
public String toString() {
return "Relationship: "+model; //$NON-NLS-1$
}
+
+ public void connect() {
+ //Disconnect first in case the object is already connected. This
ensures
+ //a listener isn't addd twice.
+ destroy();
+
+ if (pkTable != null) {
+ pkTable.addSPListener(tpbListener);
+ }
+ if (fkTable != null) {
+ fkTable.addSPListener(tpbListener);
+ }
+ getParent().addSPListener(containerPaneListener);
+ }
+
+ /**
+ * You must call this method when you are done with a TablePane
+ * component. It unregisters this instance (and its UI delegate)
+ * on all event listener lists on which it was previously
+ * registered.
+ */
+ private void destroy() {
+ if (pkTable != null) {
+ pkTable.removeSPListener(tpbListener);
+ }
+ if (fkTable != null) {
+ fkTable.removeSPListener(tpbListener);
+ }
+ getParent().removeSPListener(containerPaneListener);
+ }
// -------------------- PlayPenComponent overrides --------------------
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java Thu
May 20 14:57:45 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java Wed
May 26 14:48:19 2010
@@ -226,13 +226,8 @@
* You must call this method when you are adding a TablePane component
after
* the parent is defined. It will register the necessary listeners to
all
* necessary parties.
- * <p>
- * TODO : When there are multiple {...@link PlayPenContentPane}s each
- * {...@link PlayPenComponent} will need to be able to re-connect to its
model
- * when it is added back into its parent content pane. At this point
the
- * interface will need a connect method and this will be implementing
that
- * connect method.
*/
+ @Override
public void connect() {
//Disconnect first in case the object is already connected. This
ensures
//a listener isn't addd twice.
@@ -247,12 +242,8 @@
* component. It unregisters this instance (and its UI delegate)
* on all event listener lists on which it was previously
* registered.
- *
- * <p>FIXME: this should be done automatically when the SQLTable
- * model is removed, because the TablePane shouldn't have to be
- * destroyed separately of the model.
*/
- public void destroy() {
+ private void destroy() {
SQLPowerUtils.unlistenToHierarchy(model, columnListener);
getParent().removeSPListener(containerPaneListener);
}