Author: daceywang
Date: Thu Apr  2 15:47:50 2009
New Revision: 2972

Modified:
   trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
   trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java
   trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java
   trunk/src/ca/sqlpower/architect/swingui/action/EditColumnAction.java
   trunk/src/ca/sqlpower/architect/swingui/messages.properties

Log:
Add text field for logical name in ColumnEditPanel and add variable to store the value. Also made some test cases for this new property.

Modified: trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
==============================================================================
--- trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java (original) +++ trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java Thu Apr 2 15:47:50 2009
@@ -81,7 +81,7 @@

            panel = new ColumnEditPanel(col3, session);

- assertEquals("Wrong column name",col3.getName(),panel.getColName().getText()); + assertEquals("Wrong column technical name",col3.getName(),panel.getColPhysicalName().getText()); assertEquals("Wrong Precision",col3.getPrecision(),((Integer) (panel.getColPrec().getValue())).intValue()); assertEquals("Wrong type",col3.getType(),((SQLType)(panel.getColType().getSelectedItem())).getType()); assertEquals("Wrong Scale",col3.getScale(),((Integer) (panel.getColScale().getValue())).intValue());
@@ -92,7 +92,7 @@

         panel = new ColumnEditPanel(col2, session);

- assertEquals("Wrong column name",col2.getName(),panel.getColName().getText()); + assertEquals("Wrong column technical name",col2.getName(),panel.getColPhysicalName().getText()); assertEquals("Wrong Precision",col2.getPrecision(),((Integer) (panel.getColPrec().getValue())).intValue()); assertEquals("Wrong type",col2.getType(),((SQLType)(panel.getColType().getSelectedItem())).getType()); assertEquals("Wrong Scale",col2.getScale(),((Integer) (panel.getColScale().getValue())).intValue());
@@ -104,7 +104,8 @@

        public void testApplyChanges() {

-               panel.getColName().setText("CHANGED");
+               panel.getColPhysicalName().setText("CHANGED");
+               panel.getColLogicalName().setText("Easier Use Column Name");
                panel.getColPrec().setValue(new Integer(1234));
                panel.getColType().setSelectedIndex(5);
                panel.getColScale().setValue(new Integer(5432));
@@ -116,7 +117,8 @@
                
                panel.applyChanges();
assertEquals("Panel check boxes borked",true,panel.getColAutoInc().getModel().isSelected());
-               assertEquals("Wrong column name","CHANGED",col2.getName());
+               assertEquals("Wrong column technical 
name","CHANGED",col2.getName());
+ assertEquals("Wrong column alias name","Easier Use Column Name",col2.getLogicalName());
                assertEquals("Wrong Precision",1234,col2.getPrecision());
                assertEquals("Wrong type",16,col2.getType());
                assertEquals("Wrong Scale",5432,col2.getScale());
@@ -126,7 +128,8 @@
        }

        public void testDiscardChanges() {
-               panel.getColName().setText("CHANGED");
+               panel.getColPhysicalName().setText("CHANGED");
+               panel.getColLogicalName().setText("Easier Use Column Name");
                panel.getColPrec().setValue(new Integer(1234));
                panel.getColType().setSelectedIndex(5);
                panel.getColScale().setValue(new Integer(5432));
@@ -135,7 +138,8 @@
                panel.getColNullable().getModel().setSelected(true);
                panel.discardChanges();
                
-               assertEquals("Wrong column name","Column 2",col2.getName());
+               assertEquals("Wrong column technical name","Column 
2",col2.getName());
+               assertEquals("Wrong column alias 
name","",col2.getLogicalName());
                assertEquals("Wrong Precision",3,col2.getPrecision());
                assertEquals("Wrong type",2,col2.getType());
                assertEquals("Wrong Scale",4,col2.getScale());

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 Thu Apr 2 15:47:50 2009
@@ -61,12 +61,12 @@

 import ca.sqlpower.architect.ArchitectSession;
 import ca.sqlpower.architect.ddl.DDLUtils;
-import ca.sqlpower.sqlobject.SQLObjectException;
-import ca.sqlpower.sqlobject.SQLObjectRuntimeException;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLObject;
 import ca.sqlpower.sqlobject.SQLObjectEvent;
+import ca.sqlpower.sqlobject.SQLObjectException;
 import ca.sqlpower.sqlobject.SQLObjectListener;
+import ca.sqlpower.sqlobject.SQLObjectRuntimeException;
 import ca.sqlpower.sqlobject.SQLObjectUtils;
 import ca.sqlpower.sqlobject.SQLType;
 import ca.sqlpower.swingui.DataEntryPanel;
@@ -106,7 +106,9 @@
      */
     private final JLabel sourceLabel;

-    private final JTextField colName;
+    private final JTextField colPhysicalName;
+
+    private final JTextField colLogicalName;

     private final JComboBox colType;

@@ -184,33 +186,55 @@
         row++;

         layout.appendRow(RowSpec.decode("p"));
- panel.add(makeTitle(Messages.getString("ColumnEditPanel.name")), cc.xyw(2, row++, 4)); //$NON-NLS-1$ + panel.add(makeTitle(Messages.getString("ColumnEditPanel.physicalName")), cc.xyw(2, row++, 4)); //$NON-NLS-1$
         layout.appendRow(RowSpec.decode("p"));
         cb = new JCheckBox();
         if (cols.size() > 1) {
             panel.add(cb, cc.xy(1, row));
         }
-        panel.add(colName = new JTextField(), cc.xyw(2, row++, 4));
-        componentEnabledMap.put(colName, cb);
- colName.getDocument().addDocumentListener(new DocumentCheckboxEnabler(cb));
-        colName.addComponentListener(new ComponentAdapter() {
+        panel.add(colPhysicalName = new JTextField(), cc.xyw(2, row++, 4));
+        componentEnabledMap.put(colPhysicalName, cb);
+ colPhysicalName.getDocument().addDocumentListener(new DocumentCheckboxEnabler(cb));
+        colPhysicalName.addComponentListener(new ComponentAdapter() {
             @Override
             public void componentShown(ComponentEvent e) {
-                colName.requestFocusInWindow();
+                colPhysicalName.requestFocusInWindow();
             }
         });
-        colName.addFocusListener(new FocusAdapter() {
+        colPhysicalName.addFocusListener(new FocusAdapter() {
             public void focusGained(FocusEvent e) {
                 if(logger.isDebugEnabled()) {
                     logger.debug("focus Gained : " + e);
                 }
-                colName.selectAll();
+                colPhysicalName.selectAll();
             }
-
-            public void focusLost(FocusEvent e) {
+        });
+
+        layout.appendRow(RowSpec.decode("5dlu"));
+        row++;
+
+        layout.appendRow(RowSpec.decode("p"));
+ panel.add(makeTitle(Messages.getString("ColumnEditPanel.logicalName")), cc.xyw(2, row++, 4)); //$NON-NLS-1$
+        layout.appendRow(RowSpec.decode("p"));
+        cb = new JCheckBox();
+        if (cols.size() > 1) {
+            panel.add(cb, cc.xy(1, row));
+        }
+        panel.add(colLogicalName = new JTextField(), cc.xyw(2, row++, 4));
+        componentEnabledMap.put(colLogicalName, cb);
+ colLogicalName.getDocument().addDocumentListener(new DocumentCheckboxEnabler(cb));
+        colLogicalName.addComponentListener(new ComponentAdapter() {
+            @Override
+            public void componentShown(ComponentEvent e) {
+                colLogicalName.requestFocusInWindow();
+            }
+        });
+        colLogicalName.addFocusListener(new FocusAdapter() {
+            public void focusGained(FocusEvent e) {
                 if(logger.isDebugEnabled()) {
-                    logger.debug("focus lost : " + e);
+                    logger.debug("focus Gained : " + e);
                 }
+                colLogicalName.selectAll();
             }
         });

@@ -309,7 +333,7 @@
colAutoIncSequenceName.getDocument().addDocumentListener(new DocumentCheckboxEnabler(cb));

// Listener to update the sequence name when the column name changes
-        colName.getDocument().addDocumentListener(new DocumentListener() {
+ colPhysicalName.getDocument().addDocumentListener(new DocumentListener() {
             public void changedUpdate(DocumentEvent e) {
                 syncSequenceName();
             }
@@ -337,7 +361,7 @@
                     discoverSequenceNamePattern(column.getName());
                     syncSequenceName();
                 } else {
-                    discoverSequenceNamePattern(colName.getText());
+                    discoverSequenceNamePattern(colPhysicalName.getText());
                 }
             }
         });
@@ -387,8 +411,8 @@
         }

 //         TODO only give focus to column name if it's enabled?
-        colName.requestFocus();
-        colName.selectAll();
+        colPhysicalName.requestFocus();
+        colPhysicalName.selectAll();

SQLObjectUtils.listenToHierarchy(obsolesenceListener, session.getRootObject());
         panel.addAncestorListener(cleanupListener);
@@ -431,7 +455,8 @@
sourceColumn.getParentTable()) + "." + sourceColumn.getName());
         }

-        updateComponent(colName, col.getName());
+        updateComponent(colPhysicalName, col.getName());
+        updateComponent(colLogicalName, col.getLogicalName());
         updateComponent(colType, SQLType.getType(col.getType()));

         updateComponent(colScale, Integer.valueOf(col.getScale()));
@@ -518,7 +543,7 @@
      */
     private void syncSequenceName() {
         if (seqNamePrefix != null && seqNameSuffix != null) {
- String newName = seqNamePrefix + colName.getText() + seqNameSuffix; + String newName = seqNamePrefix + colPhysicalName.getText() + seqNameSuffix;
             colAutoIncSequenceName.setText(newName);
         }
     }
@@ -581,14 +606,16 @@
compoundEditRoot.startCompoundEdit(Messages.getString("ColumnEditPanel.compoundEditName")); //$NON-NLS-1$

             for (SQLColumn column : columns) {
-                if (componentEnabledMap.get(colName).isSelected()) {
-                    if (colName.getText().trim().length() == 0) {
+ if (componentEnabledMap.get(colPhysicalName).isSelected()) {
+                    if (colPhysicalName.getText().trim().length() == 0) {
errors.add(Messages.getString("ColumnEditPanel.columnNameRequired")); //$NON-NLS-1$
                     } else {
-                        column.setName(colName.getText());
+                        column.setName(colPhysicalName.getText());
                     }
                 }
-
+                if (componentEnabledMap.get(colLogicalName).isSelected()) {
+                    column.setLogicalName(colLogicalName.getText());
+                }
                 if (componentEnabledMap.get(colType).isSelected()) {
column.setType(((SQLType) colType.getSelectedItem()).getType());
                 }
@@ -683,10 +710,14 @@
     public JCheckBox getColInPK() {
         return colInPK;
     }
-
/** Only for testing. Normal client code should not need to call this. */
-    public JTextField getColName() {
-        return colName;
+    public JTextField getColLogicalName() {
+        return colLogicalName;
+    }
+
+ /** Only for testing. Normal client code should not need to call this. */
+    public JTextField getColPhysicalName() {
+        return colPhysicalName;
     }

/** Only for testing. Normal client code should not need to call this. */

Modified: trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java Thu Apr 2 15:47:50 2009
@@ -1222,6 +1222,7 @@
             if (sourceCol != null) {
propNames.put("source-column-ref", sqlObjectSaveIdMap.get(sourceCol)); //$NON-NLS-1$
             }
+ propNames.put("logicalName", ((SQLColumn) o).getLogicalName()); //$NON-NLS-1$ propNames.put("type", new Integer(((SQLColumn) o).getType())); //$NON-NLS-1$ propNames.put("sourceDataTypeName", ((SQLColumn) o).getSourceDataTypeName()); //$NON-NLS-1$ propNames.put("scale", new Integer(((SQLColumn) o).getScale())); //$NON-NLS-1$

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 Thu Apr 2 15:47:50 2009
@@ -125,7 +125,7 @@
                                         new Callable<Boolean>(){
                                                public Boolean call() {
                                                    if (addToTable) {
- tp.getModel().startCompoundEdit("adding a new column '" + columnEditPanel.getColName().getText() + "'"); //$NON-NLS-1$ //$NON-NLS-2$ + tp.getModel().startCompoundEdit("adding a new column '" + columnEditPanel.getColPhysicalName().getText() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
                                                            try {
                                                                
tp.getModel().addColumn(colIdx, column);
                                                            } catch 
(SQLObjectException e) {
@@ -134,7 +134,7 @@
                                                        }
Boolean ret = Boolean.valueOf(columnEditPanel.applyChanges());
                                if (addToTable) {
- tp.getModel().endCompoundEdit("adding a new column '" + columnEditPanel.getColName().getText() + "'"); //$NON-NLS-1$ //$NON-NLS-2$ + tp.getModel().endCompoundEdit("adding a new column '" + columnEditPanel.getColPhysicalName().getText() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
                                                    }
                                                        return ret;
                                                }

Modified: trunk/src/ca/sqlpower/architect/swingui/messages.properties
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/messages.properties (original)
+++ trunk/src/ca/sqlpower/architect/swingui/messages.properties Thu Apr 2 15:47:50 2009
@@ -71,7 +71,8 @@
 ColumnEditPanel.compoundEditName=Modify Column Properties
 ColumnEditPanel.defaultValue=Default Value
 ColumnEditPanel.inPrimaryKey=In Primary Key
-ColumnEditPanel.name=Name
+ColumnEditPanel.physicalName=Physical Name
+ColumnEditPanel.logicalName=Logical Name
 ColumnEditPanel.noneSpecified=None Specified
 ColumnEditPanel.precision=Precision
 ColumnEditPanel.remarks=Remarks

Reply via email to