Revision: 3187
Author: terryyiu
Date: Tue Dec  1 14:48:38 2009
Log: Fixing the TablePanel, TestTablePane and InsertionPointWatcher classes to compile.
http://code.google.com/p/power-architect/source/detail?r=3187

Modified:
/branches/sqlobject-spobject-model/regress/ca/sqlpower/architect/swingui/TestTablePane.java /branches/sqlobject-spobject-model/src/ca/sqlpower/architect/InsertionPointWatcher.java /branches/sqlobject-spobject-model/src/ca/sqlpower/architect/swingui/TablePane.java

=======================================
--- /branches/sqlobject-spobject-model/regress/ca/sqlpower/architect/swingui/TestTablePane.java Tue Dec 1 14:21:17 2009 +++ /branches/sqlobject-spobject-model/regress/ca/sqlpower/architect/swingui/TestTablePane.java Tue Dec 1 14:48:38 2009
@@ -293,36 +293,13 @@
* any of its folders and those events have to be handled in the right way.
         */
        public void testListenerDoesntCleanUpEarly() throws SQLObjectException {
-               class MySQLTable extends SQLTable {
-                       class MyFolder extends SQLTable.Folder<SQLColumn> {
-                               MyFolder() {
-                                       super(COLUMNS, true);
-                               }
-
-                               public void removeLastChildNoEvent() {
-                                       children.remove(children.size() - 1);
-                               }
-                       }
-                       public MySQLTable(String name) throws 
SQLObjectException {
-                               super(session.getTargetDatabase(), true);
-                               setName(name);
-                               children.set(0, new MyFolder());
-                               columns = (Folder) children.get(0);
-                       }
-                       public void removeLastColumnNoEvent() {
-                               Folder<SQLColumn> columnsFolder2 = 
getColumnsFolder();
-                ((MyFolder) columnsFolder2).removeLastChildNoEvent();
-                       }
-               }
-
-               MySQLTable t = new MySQLTable("table");
                SQLColumn c1 = new SQLColumn(t, "PK1", Types.BIT, 1, 0);
                t.addColumn(c1, 0);

                TablePane tp = new TablePane(t, pp.getContentPane());

                assertEquals(1, t.getColumns().size());
-               t.removeLastColumnNoEvent();
+               
t.removeColumn(t.getChildrenWithoutPopulating(SQLColumn.class).size());
                assertEquals(0, t.getColumns().size());

                // now table has selection list size 1, and model's column list 
is size 0
@@ -332,7 +309,7 @@
tp.columnListener.childRemoved(new SPChildEvent(fakeSource, fakeSource.getClass(), fakeSource, 6, EventType.REMOVED));

// this event notifies the table pane that we removed c1 earlier on. It should not throw an exception - tp.columnListener.childRemoved(new SPChildEvent(t.getColumnsFolder(), c1.getClass(), c1, 0, EventType.REMOVED)); + tp.columnListener.childRemoved(new SPChildEvent(t, c1.getClass(), c1, 0, EventType.REMOVED));
        }

     public void testMultiHighlight() throws SQLObjectException {
=======================================
--- /branches/sqlobject-spobject-model/src/ca/sqlpower/architect/InsertionPointWatcher.java Tue Dec 1 13:40:46 2009 +++ /branches/sqlobject-spobject-model/src/ca/sqlpower/architect/InsertionPointWatcher.java Tue Dec 1 14:48:38 2009
@@ -45,6 +45,8 @@
     private final T objectUnderObservation;

     private int insertionPoint;
+
+    private final Class<? extends SQLObject> childType;

private final SQLObjectEventHandler eventHandler = new SQLObjectEventHandler();

@@ -53,9 +55,14 @@
      * @param insertionPoint
      */
public InsertionPointWatcher(final T objectUnderObservation, int insertionPoint) { + this(objectUnderObservation, insertionPoint, objectUnderObservation.getChildType());
+    }
+
+ public InsertionPointWatcher(final T objectUnderObservation, int insertionPoint, Class<? extends SQLObject> childType) {
         super();
         this.objectUnderObservation = objectUnderObservation;
         this.insertionPoint = insertionPoint;
+        this.childType = childType;
         objectUnderObservation.addSPListener(eventHandler);
     }

@@ -71,14 +78,14 @@

         @Override
         public void childAddedImpl(SPChildEvent e) {
-            if (e.getIndex() <= insertionPoint) {
+ if (e.getChildType() == childType && e.getIndex() <= insertionPoint) {
                 insertionPoint++;
             }
         }

         @Override
         public void childRemovedImpl(SPChildEvent e) {
-            if (e.getIndex() <= insertionPoint) {
+ if (e.getChildType() == childType && e.getIndex() <= insertionPoint) {
                 insertionPoint++;
             }
         }
=======================================
--- /branches/sqlobject-spobject-model/src/ca/sqlpower/architect/swingui/TablePane.java Tue Dec 1 14:21:17 2009 +++ /branches/sqlobject-spobject-model/src/ca/sqlpower/architect/swingui/TablePane.java Tue Dec 1 14:48:38 2009
@@ -234,7 +234,7 @@
          * delegate) with a PropertyChangeEvent.
          */
         public void childAddedImpl(SPChildEvent e) {
-            if (e.getSource() == getModel().getColumnsFolder()) {
+ if (e.getSource() == getModel() && e.getChildType() == SQLColumn.class) {
                 if (logger.isDebugEnabled()) {
logger.debug("Column inserted. Syncing select/highlight lists. New index="+e.getIndex()); //$NON-NLS-1$ //$NON-NLS-2$
                 }
@@ -494,8 +494,8 @@
} else if (col.getParent().getParentDatabase() == getModel().getParentDatabase()) {
                                    // moving column within playpen

- InsertionPointWatcher<SQLTable.Folder<SQLColumn>> ipWatcher = - new InsertionPointWatcher<SQLTable.Folder<SQLColumn>>(getModel().getColumnsFolder(), insertionPoint);
+                                   InsertionPointWatcher<SQLTable> ipWatcher =
+ new InsertionPointWatcher<SQLTable>(getModel(), insertionPoint, SQLColumn.class);
                                    col.getParent().removeColumn(col);
                                    ipWatcher.dispose();

@@ -504,7 +504,7 @@
+"' to table '"+getModel().getName() //$NON-NLS-1$ +"' at position "+ipWatcher.getInsertionPoint()); //$NON-NLS-1$
                                    }
-                                   
getModel().addColumn(ipWatcher.getInsertionPoint(), col);
+                                   getModel().addColumn(col, 
ipWatcher.getInsertionPoint());
// You need to disable the normalization otherwise it goes around // the property change events and causes undo to fail when dragging
                                    // into the primary key of a table

Reply via email to