Revision: 3485
Author: mo.jeff
Date: Mon May 3 06:53:28 2010
Log: Made modifications to allow the Column editor UI to change the
upstream SQL Type in a column
http://code.google.com/p/power-architect/source/detail?r=3485
Modified:
/trunk/regress/ca/sqlpower/architect/ddl/MySqlDDLGeneratorTest.java
/trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/BasicTablePaneUI.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/EditColumnAction.java
=======================================
--- /trunk/regress/ca/sqlpower/architect/ddl/MySqlDDLGeneratorTest.java Tue
Jan 19 14:37:22 2010
+++ /trunk/regress/ca/sqlpower/architect/ddl/MySqlDDLGeneratorTest.java Mon
May 3 06:53:28 2010
@@ -19,8 +19,11 @@
package ca.sqlpower.architect.ddl;
import ca.sqlpower.sqlobject.SQLColumn;
+import ca.sqlpower.sqlobject.UserDefinedSQLType;
import junit.framework.TestCase;
import ca.sqlpower.sqlobject.SQLTable;
+import
ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider.PropertyType;
+
import java.sql.Types;
import java.util.List;
@@ -33,9 +36,17 @@
tbl.setPhysicalName("test_table");
tbl.setRemarks("Test single ' quotes");
SQLColumn id = new SQLColumn(tbl, "id", Types.INTEGER, 0, 0);
+ UserDefinedSQLType idUpstreamType = new UserDefinedSQLType();
+ idUpstreamType.setName("INTEGER");
+ idUpstreamType.setScaleType("GENERIC",
PropertyType.NOT_APPLICABLE);
+ id.getUserDefinedSQLType().setUpstreamType(idUpstreamType);
id.setRemarks("The row's primary key");
tbl.addColumn(id);
SQLColumn name = new SQLColumn(tbl, "name", Types.VARCHAR, 50,
0);
+ UserDefinedSQLType nameUpstreamType = new UserDefinedSQLType();
+ nameUpstreamType.setName("VARCHAR");
+ nameUpstreamType.setScaleType("GENERIC",
PropertyType.NOT_APPLICABLE);
+ name.getUserDefinedSQLType().setUpstreamType(nameUpstreamType);
name.setRemarks("The person's name");
tbl.addColumn(name);
ddl.addTable(tbl);
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
Tue Apr 6 14:44:35 2010
+++ /trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
Mon May 3 06:53:28 2010
@@ -27,7 +27,7 @@
import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLTable;
-import ca.sqlpower.sqlobject.SQLType;
+import ca.sqlpower.sqlobject.UserDefinedSQLType;
public class TestColumnEditPanel extends TestCase {
SQLDatabase db;
@@ -80,22 +80,24 @@
assertFalse("The column we plan to edit should not be in PK",
col3.isPrimaryKey());
+
col3.getUserDefinedSQLType().setUpstreamType(session.getSQLTypes().get(0));
panel = new ColumnEditPanel(col3, session);
assertEquals("Wrong column logical
name",col3.getName(),panel.getColLogicalName().getText());
- assertEquals("Wrong Precision",col3.getPrecision(),((Integer)
(panel.getColPrec().getValue())).intValue());
- assertEquals("Wrong
type",col3.getType(),((SQLType)(panel.getColType().getSelectedItem())).getType());
+ assertEquals("Wrong Precision",col3.getPrecision(),((Integer)
panel.getColPrec().getValue()).intValue());
+ assertEquals("Wrong
type",col3.getType(),((UserDefinedSQLType)panel.getColType().getSelectedItem()).getType().intValue());
assertEquals("Wrong Scale",col3.getScale(),((Integer)
(panel.getColScale().getValue())).intValue());
assertEquals(col3.isAutoIncrement(),
panel.getColAutoInc().getModel().isSelected());
assertEquals(col3.isPrimaryKey(),
panel.getColInPK().getModel().isSelected());
assertEquals(col3.getNullable() == DatabaseMetaData.columnNullable,
panel.getColNullable().getModel().isSelected());
assertEquals("None Specified",panel.getSourceLabel().getText());
+
col2.getUserDefinedSQLType().setUpstreamType(session.getSQLTypes().get(1));
panel = new ColumnEditPanel(col2, session);
assertEquals("Wrong column logical
name",col2.getName(),panel.getColLogicalName().getText());
- assertEquals("Wrong Precision",col2.getPrecision(),((Integer)
(panel.getColPrec().getValue())).intValue());
- assertEquals("Wrong
type",col2.getType(),((SQLType)(panel.getColType().getSelectedItem())).getType());
+ assertEquals("Wrong Precision",col2.getPrecision(),((Integer)
panel.getColPrec().getValue()).intValue());
+ assertEquals("Wrong
type",col2.getType(),((UserDefinedSQLType)panel.getColType().getSelectedItem()).getType().intValue());
assertEquals("Wrong Scale",col2.getScale(),((Integer)
(panel.getColScale().getValue())).intValue());
assertEquals(col2.isAutoIncrement(),
panel.getColAutoInc().getModel().isSelected());
assertEquals(col2.isPrimaryKey(),
panel.getColInPK().getModel().isSelected());
@@ -107,8 +109,8 @@
panel.getColPhysicalName().setText("CHANGED");
panel.getColLogicalName().setText("Easier Use Column Name");
+ panel.getColType().setSelectedIndex(1);
panel.getColPrec().setValue(new Integer(1234));
- panel.getColType().setSelectedIndex(5);
panel.getColScale().setValue(new Integer(5432));
@@ -121,7 +123,7 @@
assertEquals("Wrong column physical
name","CHANGED",col2.getPhysicalName());
assertEquals("Wrong column logical name","Easier Use Column
Name",col2.getName());
assertEquals("Wrong Precision",1234,col2.getPrecision());
- assertEquals("Wrong type",16,col2.getType());
+ assertEquals("Wrong type",2,col2.getType());
assertEquals("Wrong Scale",5432,col2.getScale());
assertTrue(col2.isAutoIncrement());
assertTrue(col2.isPrimaryKey());
@@ -135,7 +137,6 @@
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));
panel.getColAutoInc().getModel().setSelected(true);
panel.getColInPK().getModel().setSelected(true);
@@ -145,7 +146,6 @@
assertEquals("Wrong column physical name","Physical Name
2",col2.getPhysicalName());
assertEquals("Wrong column logical name","Column
2",col2.getName());
assertEquals("Wrong Precision",3,col2.getPrecision());
- assertEquals("Wrong type",2,col2.getType());
assertEquals("Wrong Scale",4,col2.getScale());
assertFalse(col2.isAutoIncrement());
assertFalse(col2.isPrimaryKey());
=======================================
---
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Tue Apr 20 15:12:12 2010
+++
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Mon May 3 06:53:28 2010
@@ -22,7 +22,9 @@
import java.awt.Window;
import java.beans.PropertyChangeListener;
import java.io.IOException;
+import java.sql.DatabaseMetaData;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -51,7 +53,9 @@
import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectRoot;
+import ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider;
import ca.sqlpower.sqlobject.UserDefinedSQLType;
+import
ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider.PropertyType;
import ca.sqlpower.swingui.RecentMenu;
import ca.sqlpower.swingui.SPSwingWorker;
import ca.sqlpower.swingui.event.SessionLifecycleListener;
@@ -89,6 +93,8 @@
private boolean usingLogicalNames = false;
private ColumnVisibility choice = ColumnVisibility.ALL;
+ private UserDefinedSQLType testType1;
+ private UserDefinedSQLType testType2;
public TestingArchitectSwingSession(ArchitectSwingSessionContext
context) throws SQLObjectException {
this.context = context;
@@ -122,6 +128,27 @@
kettleJob = new KettleJob(this);
printSettings = new PrintSettings();
+
+ testType1 = new UserDefinedSQLType();
+ String platform =
SQLTypePhysicalPropertiesProvider.GENERIC_PLATFORM;
+ testType1.setName("Test Type 1");
+ testType1.setPrecision(platform, 1);
+ testType1.setScale(platform, 1);
+ testType1.setType(1);
+ testType1.setNullability(DatabaseMetaData.columnNoNulls);
+ testType1.setAutoIncrement(false);
+ testType1.setPrecisionType(platform, PropertyType.VARIABLE);
+ testType1.setScaleType(platform, PropertyType.VARIABLE);
+
+ testType2 = new UserDefinedSQLType();
+ testType2.setName("Test Type 2");
+ testType2.setPrecision(platform, 1);
+ testType2.setScale(platform, 1);
+ testType2.setType(2);
+ testType2.setNullability(DatabaseMetaData.columnNoNulls);
+ testType2.setAutoIncrement(false);
+ testType2.setPrecisionType(platform, PropertyType.VARIABLE);
+ testType2.setScaleType(platform, PropertyType.VARIABLE);
}
public TestingArchitectSwingSession(ArchitectSwingSessionContext
context, SwingUIProjectLoader project) throws SQLObjectException {
@@ -440,7 +467,9 @@
}
public List<UserDefinedSQLType> getSQLTypes() {
- // TODO Auto-generated method stub
- return null;
+ List<UserDefinedSQLType> list = new
ArrayList<UserDefinedSQLType>();
+ list.add(testType1);
+ list.add(testType2);
+ return list;
}
}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/BasicTablePaneUI.java
Mon Apr 5 16:15:43 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/BasicTablePaneUI.java
Mon May 3 06:53:28 2010
@@ -294,7 +294,7 @@
} else {
displayName.append(col.getPhysicalName()).append(": ");
}
- displayName.append(ddlg.getColumnDataTypeName(col));
+ displayName.append(col.getTypeName());
displayName.append(getColumnTag(col));
return displayName.toString();
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
Thu Apr 22 12:03:52 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
Mon May 3 06:53:28 2010
@@ -27,6 +27,8 @@
import java.awt.event.ComponentEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.sql.DatabaseMetaData;
import java.util.ArrayList;
@@ -68,7 +70,9 @@
import ca.sqlpower.sqlobject.SQLObject;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectUtils;
-import ca.sqlpower.sqlobject.SQLType;
+import ca.sqlpower.sqlobject.SQLTypePhysicalProperties;
+import ca.sqlpower.sqlobject.UserDefinedSQLType;
+import
ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider.PropertyType;
import ca.sqlpower.swingui.ChangeListeningDataEntryPanel;
import ca.sqlpower.swingui.DataEntryPanelChangeUtil;
import ca.sqlpower.swingui.SPSUtils;
@@ -257,7 +261,7 @@
if (cols.size() > 1) {
panel.add(cb, cc.xy(1, row));
}
- panel.add(colType = new JComboBox(SQLType.getTypes()), cc.xyw(2,
row++, 4));
+ panel.add(colType = new
JComboBox(session.getSQLTypes().toArray()), cc.xyw(2, row++, 4));
componentEnabledMap.put(colType, cb);
colType.setSelectedItem(null);
colType.addActionListener(this);
@@ -436,6 +440,14 @@
SQLPowerUtils.listenToHierarchy(session.getRootObject(),
obsolesenceListener);
SQLPowerUtils.listenToHierarchy(session.getRootObject(), this);
panel.addAncestorListener(cleanupListener);
+ colType.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getItem() instanceof UserDefinedSQLType) {
+ UserDefinedSQLType sqlType = (UserDefinedSQLType)
e.getItem();
+ updateSQLTypeComponents(sqlType);
+ }
+ }
+ });
}
private Component makeTitle(String string) {
@@ -481,10 +493,10 @@
updateComponent(colLogicalName, col.getName());
updateComponent(colPhysicalName, col.getPhysicalName());
- updateComponent(colType, SQLType.getType(col.getType()));
-
- updateComponent(colScale, Integer.valueOf(col.getScale()));
- updateComponent(colPrec, Integer.valueOf(col.getPrecision()));
+ updateComponent(colType,
col.getUserDefinedSQLType().getUpstreamType());
+
+ updateComponent(colScale, col.getScale(), col.getScaleType());
+ updateComponent(colPrec, col.getPrecision(),
col.getPrecisionType());
updateComponent(colNullable, col.getNullable() ==
DatabaseMetaData.columnNullable);
@@ -538,15 +550,16 @@
}
/** Subroutine of {...@link #updateComponents(SQLColumn)}. */
- private void updateComponent(JSpinner comp, Integer expectedValue) {
+ private void updateComponent(JSpinner comp, int expectedValue,
PropertyType propertyType) {
boolean unvisited = comp.getValue().equals(Integer.valueOf(0));
if (componentEnabledMap.get(comp).isSelected() &&
- (unvisited || comp.getValue().equals(expectedValue))) {
+ (unvisited || comp.getValue().equals(expectedValue)) &&
+ propertyType != PropertyType.NOT_APPLICABLE) {
comp.setValue(expectedValue);
} else {
- comp.setValue(Integer.valueOf(0));
componentEnabledMap.get(comp).setSelected(false);
}
+ comp.setEnabled(propertyType == PropertyType.VARIABLE);
}
/** Subroutine of {...@link #updateComponents(SQLColumn)}. */
@@ -667,7 +680,7 @@
column.setPhysicalName(colPhysicalName.getText());
}
if (componentEnabledMap.get(colType).isSelected()) {
- column.setType(((SQLType)
colType.getSelectedItem()).getType());
+
column.getUserDefinedSQLType().setUpstreamType((UserDefinedSQLType)
colType.getSelectedItem());
}
if (componentEnabledMap.get(colScale).isSelected()) {
@@ -961,6 +974,22 @@
//no-op
}
-
-
-}
+ /**
+ * If a user chooses a new Type to base the column on, then the UI
+ * components for other properties like precision, scale, default
value,
+ * nullability, and autoincrement need to change to match that of the
new
+ * type. But the SQLColumn object itself must not change at that
point, so
+ * that it is simple to cancel any changes if the user chooses to
click the
+ * 'Cancel' button.
+ *
+ * @param sqlType
+ */
+ private void updateSQLTypeComponents(UserDefinedSQLType sqlType) {
+ SQLTypePhysicalProperties properties =
sqlType.getDefaultPhysicalProperties();
+ updateComponent(colScale, properties.getScale(),
properties.getScaleType());
+ updateComponent(colPrec, properties.getPrecision(),
properties.getPrecisionType());
+ updateComponent(colNullable, sqlType.getNullability() ==
DatabaseMetaData.columnNullable);
+ updateComponent(colDefaultValue, properties.getDefaultValue());
+ updateComponent(colAutoInc, sqlType.getAutoIncrement());
+ }
+}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/EditColumnAction.java
Thu Mar 4 08:08:10 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/EditColumnAction.java
Mon May 3 06:53:28 2010
@@ -108,7 +108,11 @@
if (!addToTable) {
column = st.getColumn(colIdx);
} else {
- column = new SQLColumn();
+ if (session.getSQLTypes().size() > 0) {
+ column = new
SQLColumn(session.getSQLTypes().get(0));
+ } else {
+ column = new SQLColumn();
+ }
// 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.