Author: daceywang
Date: Thu Apr 2 12:24:43 2009
New Revision: 2970
Modified:
trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
trunk/src/ca/sqlpower/architect/swingui/BasicTablePaneUI.java
Log:
This is the interim solution to bug 1613. Now column types will be
displayed differently based on the different requirements from the database
platforms. The full solution lie in the implementation of the Domains
feature.
Notice that getShortDisplayName() in SQLColumn is not actually used except
in the toString() method and some test cases.The reason not to remove them
is that it's a method defined in the interface of SQLObject.
Modified: trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
(original)
+++ trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Thu Apr 2
12:24:43 2009
@@ -152,15 +152,21 @@
protected Map<String, ProfileFunctionDescriptor> profileFunctionMap;
-
+ public GenericDDLGenerator(boolean allowConnection) throws
SQLException {
+ this.allowConnection = allowConnection;
+ warnings = new ArrayList();
+ ddlStatements = new ArrayList();
+ ddl = new StringBuffer(500);
+ println("");
+ topLevelNames = new CaseInsensitiveHashMap(); // for tracking dup
table/relationship names
+ createTypeMap();
+ }
+
+ /**
+ * Creates a new generic DDL generator that's allowed to connect to
the target database.
+ */
public GenericDDLGenerator() throws SQLException {
- allowConnection = true;
- warnings = new ArrayList();
- ddlStatements = new ArrayList();
- ddl = new StringBuffer(500);
- println("");
- topLevelNames = new CaseInsensitiveHashMap(); // for tracking dup
table/relationship names
- createTypeMap();
+ this(true);
}
public String generateDDLScript(Collection<SQLTable> tables) throws
SQLException, SQLObjectException {
Modified: trunk/src/ca/sqlpower/architect/swingui/BasicTablePaneUI.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/BasicTablePaneUI.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/BasicTablePaneUI.java Thu Apr
2 12:24:43 2009
@@ -32,19 +32,30 @@
import java.awt.font.FontRenderContext;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
-import ca.sqlpower.sqlobject.SQLObjectException;
+import ca.sqlpower.architect.ddl.GenericDDLGenerator;
import ca.sqlpower.sqlobject.SQLColumn;
+import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLTable;
public class BasicTablePaneUI extends TablePaneUI implements
PropertyChangeListener, java.io.Serializable {
private static Logger logger = Logger.getLogger(BasicTablePaneUI.class);
+ private static final GenericDDLGenerator ddlg;
+ static {
+ try {
+ ddlg = new GenericDDLGenerator(false);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* The TablePane component that this UI delegate works for.
*/
@@ -218,7 +229,7 @@
// draws the column
currentColor = tp.getColumnHighlight(i);
g2.setColor(currentColor == null ? Color.BLACK :
currentColor);
- g2.drawString(col.getShortDisplayName() +
getColumnTag(col, tp),
+ g2.drawString(columnText(col),
BOX_LINE_THICKNESS+tp.getMargin().left,
y += fontHeight);
i++;
@@ -275,7 +286,22 @@
}
}
- public Dimension getPreferredSize() {
+ /**
+ * Generates the string to be displayed for the given column. Includes
the column's name,
+ * data type, and any "tags" (such as PK and FK) are enabled in the
user prefs.
+ *
+ * @param col The column to create the text for
+ * @return The text that should be displayed for the given column
+ */
+ private String columnText(SQLColumn col) {
+ StringBuilder displayName = new StringBuilder(50);
+ displayName.append(col.getName()).append(": ");
+ displayName.append(ddlg.getColumnDataTypeName(col));
+ displayName.append(getColumnTag(col));
+ return displayName.toString();
+ }
+
+ public Dimension getPreferredSize() {
return getPreferredSize(tablePane);
}
@@ -307,7 +333,7 @@
logger.error("Found null column in table '"+table.getName()+"'");
//$NON-NLS-1$ //$NON-NLS-2$
throw new NullPointerException("Found null column in
table '"+table.getName()+"'"); //$NON-NLS-1$ //$NON-NLS-2$
}
- itemsToCheck.add(col.toString() +
getColumnTag(col, c));
+ itemsToCheck.add(columnText(col));
}
itemsToCheck.add(getTitleString(c)); // this works as long as the
title uses the same font as the columns
for(String item : itemsToCheck) {
@@ -467,22 +493,22 @@
/**
* Determines what tag to append to the given column
*/
- private String getColumnTag(SQLColumn col, TablePane tp) {
+ private String getColumnTag(SQLColumn col) {
StringBuffer tag = new StringBuffer();
StringBuffer fullTag = new StringBuffer();
boolean isPK = col.isPrimaryKey();
boolean isFK = col.isForeignKey();
boolean isAK = col.isUniqueIndexed() && !isPK;
boolean emptyTag = true;
- if (tp.isShowPkTag() && isPK) {
+ if (tablePane.isShowPkTag() && isPK) {
tag.append("P"); //$NON-NLS-1$
emptyTag = false;
}
- if (tp.isShowFkTag() && isFK) {
+ if (tablePane.isShowFkTag() && isFK) {
tag.append("F"); //$NON-NLS-1$
emptyTag = false;
}
- if (tp.isShowAkTag() && isAK) {
+ if (tablePane.isShowAkTag() && isAK) {
tag.append("A"); //$NON-NLS-1$
emptyTag = false;
}