Author: daceywang
Date: Fri Apr 17 15:34:03 2009
New Revision: 2982

Modified:
   trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java
   trunk/src/ca/sqlpower/architect/swingui/action/EditColumnAction.java

Log:
Fixed the bug that happened in the architect user group meeting which the sequence name of the column becomes very long after forward engineering. Now the sequence name takes the physical name of the table instead of the logical name. (For reverse engineer reason, now the physical name of the table sets to be the same as the logical name in the constructor of the SQLTable.)

Modified: trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java        
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java Fri Apr 17 15:34:03 2009
@@ -332,8 +332,7 @@
         componentEnabledMap.put(colAutoIncSequenceName, cb);
colAutoIncSequenceName.getDocument().addDocumentListener(new DocumentCheckboxEnabler(cb));

- // Listener to update the sequence name when the column name changes - colPhysicalName.getDocument().addDocumentListener(new DocumentListener() {
+        DocumentListener listener = new DocumentListener() {
             public void changedUpdate(DocumentEvent e) {
                 syncSequenceName();
             }
@@ -345,7 +344,10 @@
             public void removeUpdate(DocumentEvent e) {
                 syncSequenceName();
             }
-        });
+        };
+ // Listener to update the sequence name when the column name changes
+        colPhysicalName.getDocument().addDocumentListener(listener);
+        colLogicalName.getDocument().addDocumentListener(listener);

// Listener to rediscover the sequence naming convention, and reset the // sequence name to its original (according to the column's own sequence
@@ -358,10 +360,18 @@
                     // because sequence names have to be unique
                     SQLColumn column = columns.iterator().next();
colAutoIncSequenceName.setText(column.getAutoIncrementSequenceName());
-                    discoverSequenceNamePattern(column.getName());
+ if (column.getPhysicalName() != null && !column.getPhysicalName().trim().equals("")) { + discoverSequenceNamePattern(column.getPhysicalName());
+                    } else {
+                        discoverSequenceNamePattern(column.getName());
+                    }
                     syncSequenceName();
                 } else {
-                    discoverSequenceNamePattern(colPhysicalName.getText());
+ if (colPhysicalName.getText() != null && !colPhysicalName.getText().trim().equals("")) { + discoverSequenceNamePattern(colPhysicalName.getText());
+                    } else {
+ discoverSequenceNamePattern(colLogicalName.getText());
+                    }
                 }
             }
         });
@@ -479,10 +489,17 @@
         logger.debug("Selected" + colInPK.isSelected());

         colAutoInc.setSelected(col.isAutoIncrement());
-
+ logger.info("col seq name set? " + col.isAutoIncrementSequenceNameSet()); updateComponent(colAutoIncSequenceName, col.getAutoIncrementSequenceName()); + logger.info("col seq name set? " + col.isAutoIncrementSequenceNameSet());
+
+ logger.info("The seq name is: " + col.getAutoIncrementSequenceName());
         updateComponents();
-        discoverSequenceNamePattern(col.getName());
+ if (col.getPhysicalName() != null && !col.getPhysicalName().trim().equals("")) {
+            discoverSequenceNamePattern(col.getPhysicalName());
+        } else {
+            discoverSequenceNamePattern(col.getName());
+        }
     }

     /** Subroutine of {...@link #updateComponents(SQLColumn)}. */
@@ -543,7 +560,10 @@
      */
     private void syncSequenceName() {
         if (seqNamePrefix != null && seqNameSuffix != null) {
- String newName = seqNamePrefix + colPhysicalName.getText() + seqNameSuffix;
+            String newName = seqNamePrefix;
+ newName += (colPhysicalName.getText() == null || colPhysicalName.getText().trim().equals("")) ?
+                    colLogicalName.getText() : colPhysicalName.getText();
+            newName += seqNameSuffix;
             colAutoIncSequenceName.setText(newName);
         }
     }

Modified: trunk/src/ca/sqlpower/architect/swingui/action/EditColumnAction.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/action/EditColumnAction.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/action/EditColumnAction.java Fri Apr 17 15:34:03 2009
@@ -112,7 +112,11 @@

// XXX it sucks to do this here, but the column can't determine its correct // sequence name until it has a parent. By then, it will be too late. - column.setAutoIncrementSequenceName(st.getName() + "_" + column.getName() + "_seq"); //$NON-NLS-1$ //$NON-NLS-2$ + if (st.getPhysicalName() != null && !st.getPhysicalName().trim().equals("")) { + column.setAutoIncrementSequenceName(st.getPhysicalName() + "_" + column.getName() + "_seq"); //$NON-NLS-1$ //$NON-NLS-2$
+                } else {
+ column.setAutoIncrementSequenceName(st.getName() + "_" + column.getName() + "_seq"); //$NON-NLS-1$ //$NON-NLS-2$
+                }
                        }
                        
final ColumnEditPanel columnEditPanel = new ColumnEditPanel(column, session);

Reply via email to