Author: thomasobrien95
Date: Fri Dec 5 15:36:03 2008
New Revision: 2867
Modified:
trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java
trunk/src/ca/sqlpower/architect/swingui/TablePane.java
Log:
Fix for bug 1628. When a column was dropped from one play pen table
to another the column folder was not firing a change event. The
relationships on the tables are monitoring the column folders and
need an event fired to know when to update themselves.
Modified: trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java
==============================================================================
--- trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java
(original)
+++ trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java Fri Dec
5 15:36:03 2008
@@ -27,6 +27,7 @@
import java.util.List;
import ca.sqlpower.architect.ArchitectException;
+import ca.sqlpower.architect.CountingSQLObjectListener;
import ca.sqlpower.architect.SQLColumn;
import ca.sqlpower.architect.SQLObject;
import ca.sqlpower.architect.SQLObjectEvent;
@@ -313,6 +314,30 @@
assertEquals(Collections.singletonList(t.getColumn(2)),
tp.getSelectedItems());
t.removeChild(2);
assertEquals(Collections.singletonList(t.getColumn(2)),
tp.getSelectedItems());
+ }
+
+ /**
+ * This is regression testing for bug 1628. Previously dragging a
column from one table to
+ * another would not fire a change event on the columns folder the
child column was added to.
+ * This broke the relationships as they update based on inserts and
removes on the column
+ * folder.
+ */
+ public void testDropColumnBetweenTablesFiresFolderEvent() throws
Exception {
+ CountingSQLObjectListener listener = new
CountingSQLObjectListener();
+ tp.getModel().getColumnsFolder().addSQLObjectListener(listener);
+
+ SQLTable table = new SQLTable(tp.getModel().getParentDatabase(),
true);
+ SQLColumn col = new SQLColumn();
+ col.setName("Test Col");
+ table.addColumn(col);
+
+ System.out.println(tp.getModel().getParentDatabase() + ", "+
table.getParentDatabase());
+ tp.insertObjects(Collections.singletonList(col),
TablePane.COLUMN_INDEX_END_OF_PK);
+
+ assertEquals(tp.getModel(), col.getParentTable());
+ assertTrue(col.isPrimaryKey());
+ assertEquals(1, listener.getStructureChangedCount());
+
}
@Override
Modified: trunk/src/ca/sqlpower/architect/swingui/TablePane.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/TablePane.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/TablePane.java Fri Dec 5
15:36:03 2008
@@ -541,6 +541,7 @@
} finally {
getModel().setMagicEnabled(true);
}
+
getModel().getColumnsFolder().fireDbStructureChanged();
} else {
// importing column from a source
database
getModel().inherit(insertionPoint, col,
newColumnsInPk);