Revision: 3223
Author: [email protected]
Date: Tue Dec 22 12:38:24 2009
Log: The DBTree now calls populate on children that are being expanded. The tree model is not populating when looking up the number of children in an object as it causes an infinite loop on population. It is instead up to the tree using the model or the class displaying the tree to ensure the model is populated when necessary.

Updated the renderer to display imported keys correctly.
http://code.google.com/p/power-architect/source/detail?r=3223

Modified:
 /trunk/src/ca/sqlpower/architect/swingui/DBTree.java
 /trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTreeCellRenderer.java
 /trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java

=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/DBTree.java Mon Dec 21 08:27:43 2009 +++ /trunk/src/ca/sqlpower/architect/swingui/DBTree.java Tue Dec 22 12:38:24 2009
@@ -279,6 +279,9 @@
        public void expandPath(TreePath tp) {
                try {
                        session.getArchitectFrame().setCursor(new 
Cursor(Cursor.WAIT_CURSOR));
+                       if (tp.getLastPathComponent() instanceof SQLObject) {
+                           ((SQLObject) tp.getLastPathComponent()).populate();
+                       }
                        super.expandPath(tp);
                } catch (Exception ex) {
logger.warn("Unexpected exception while expanding path "+tp, ex); //$NON-NLS-1$
@@ -286,6 +289,18 @@
                        session.getArchitectFrame().setCursor(null);
                }
        }
+
+       @Override
+       public void expandRow(int row) {
+           if (getPathForRow(row).getLastPathComponent() instanceof SQLObject) 
{
+               try {
+ ((SQLObject) getPathForRow(row).getLastPathComponent()).populate();
+            } catch (SQLObjectException e) {
+                throw new RuntimeException(e);
+            }
+           }
+           super.expandRow(row);
+       }

        // ---------- methods of DragSourceListener -----------
        public void dragEnter(DragSourceDragEvent dsde) {
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTreeCellRenderer.java Fri May 22 06:08:44 2009 +++ /trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTreeCellRenderer.java Tue Dec 22 12:38:24 2009
@@ -41,6 +41,7 @@
 import ca.sqlpower.sqlobject.SQLSchema;
 import ca.sqlpower.sqlobject.SQLTable;
 import ca.sqlpower.sqlobject.SQLIndex.Column;
+import ca.sqlpower.sqlobject.SQLRelationship.SQLImportedKey;
 import ca.sqlpower.swingui.ComposedIcon;

 /**
@@ -120,13 +121,9 @@
                            setText((table).getName());
                        }
                } else if (value instanceof SQLRelationship) {
- //XXX ARRRRRRGGGGGHHHHHHH!!!! No way of knowing which end of a relationship we're - // looking at because the relationship has two parents. Maybe able to do it with the row number.
-            if (true) {
-                setIcon(EXPORTED_KEY_ICON);
-            } else {
-                setIcon(IMPORTED_KEY_ICON);
-            }
+                   setIcon(EXPORTED_KEY_ICON);
+               } else if (value instanceof SQLImportedKey) {
+                   setIcon(IMPORTED_KEY_ICON);
                } else if (value instanceof SQLIndex) {
             SQLIndex i = (SQLIndex) value;
             if (i.isPrimaryKeyIndex()) {
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java Mon Dec 21 08:27:43 2009 +++ /trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java Tue Dec 22 12:38:24 2009
@@ -48,9 +48,14 @@
 import ca.sqlpower.sqlobject.SQLObjectRoot;
 import ca.sqlpower.sqlobject.SQLRelationship;
 import ca.sqlpower.sqlobject.SQLTable;
+import ca.sqlpower.sqlobject.SQLRelationship.SQLImportedKey;
 import ca.sqlpower.util.SQLPowerUtils;
 import ca.sqlpower.util.TransactionEvent;

+/**
+ * A tree model that displays {...@link SQLObject}s contained in a {...@link SQLObjectRoot}. + * Each object is displayed as is and will not cause the {...@link SQLObject}s to populate.
+ */
 public class DBTreeModel implements TreeModel, java.io.Serializable {

        private static Logger logger = Logger.getLogger(DBTreeModel.class);
@@ -142,6 +147,11 @@
         public void removeDependency(SPObject dependency) {
             //do nothing
         }
+
+        @Override
+        public boolean isPopulated() {
+            return parentTable.isPopulated();
+        }

        }

@@ -570,6 +580,8 @@
             folderList.add(SQLColumnFolder);
FolderNode SQLRelationshipFolder = new FolderNode(table, SQLRelationship.class);
             folderList.add(SQLRelationshipFolder);
+ FolderNode SQLImportedKeys = new FolderNode(table, SQLImportedKey.class);
+            folderList.add(SQLImportedKeys);
FolderNode SQLIndexFolder = new FolderNode(table, SQLIndex.class);
             folderList.add(SQLIndexFolder);
         }

Reply via email to