Revision: 3514
Author: [email protected]
Date: Mon May 10 11:20:07 2010
Log: Added calls to SQLColumn.assignTypes() where columns are added to the
PlayPen, and added support for the ListUserPrompter.
http://code.google.com/p/power-architect/source/detail?r=3514
Modified:
/trunk/regress/ca/sqlpower/architect/StubArchitectSession.java
/trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
/trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionImpl.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java
=======================================
--- /trunk/regress/ca/sqlpower/architect/StubArchitectSession.java Mon May
3 16:11:03 2010
+++ /trunk/regress/ca/sqlpower/architect/StubArchitectSession.java Mon May
10 11:20:07 2010
@@ -179,4 +179,9 @@
// TODO Auto-generated method stub
return null;
}
-}
+
+ public <T> UserPrompter createListUserPrompter(String question,
List<T> responses, T defaultResponse) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
=======================================
--- /trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java Mon
May 3 16:11:03 2010
+++ /trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java Mon
May 10 11:20:07 2010
@@ -215,4 +215,8 @@
// TODO Auto-generated method stub
return null;
}
-}
+
+ public <T> UserPrompter createListUserPrompter(String question,
List<T> responses, T defaultResponse) {
+ return defaultUPF.createListUserPrompter(question, responses,
defaultResponse);
+ }
+}
=======================================
---
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Mon May 3 16:11:03 2010
+++
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Mon May 10 11:20:07 2010
@@ -492,4 +492,8 @@
return null;
}
}
-}
+
+ public <T> UserPrompter createListUserPrompter(String question,
List<T> responses, T defaultResponse) {
+ return new
DefaultUserPrompterFactory().createListUserPrompter(question, responses,
defaultResponse);
+ }
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionImpl.java
Mon May 3 16:11:03 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionImpl.java
Mon May 10 11:20:07 2010
@@ -275,5 +275,9 @@
}
return null;
}
+
+ public <T> UserPrompter createListUserPrompter(String question,
List<T> responses, T defaultResponse) {
+ return userPrompterFactory.createListUserPrompter(question,
responses, defaultResponse);
+ }
}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Thu May 6 12:56:55 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Mon May 10 11:20:07 2010
@@ -1225,4 +1225,8 @@
public UserDefinedSQLType findSQLTypeByJDBCType(int type) {
return delegateSession.findSQLTypeByJDBCType(type);
}
-}
+
+ public <T> UserPrompter createListUserPrompter(String question,
List<T> responses, T defaultResponse) {
+ return swinguiUserPrompterFactory.createListUserPrompter(question,
responses, defaultResponse);
+ }
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Fri
May 7 11:49:29 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Mon May
10 11:20:07 2010
@@ -134,6 +134,7 @@
import ca.sqlpower.sqlobject.SQLRelationship;
import ca.sqlpower.sqlobject.SQLSchema;
import ca.sqlpower.sqlobject.SQLTable;
+import ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider;
import ca.sqlpower.sqlobject.SQLRelationship.SQLImportedKey;
import ca.sqlpower.sqlobject.SQLTable.TransferStyles;
import ca.sqlpower.sqlobject.undo.CompoundEventListener;
@@ -144,6 +145,9 @@
import ca.sqlpower.util.SQLPowerUtils;
import ca.sqlpower.util.TransactionEvent;
import ca.sqlpower.util.TransactionEvent.TransactionState;
+
+import com.google.common.collect.ArrayListMultimap;
+
import edu.umd.cs.findbugs.annotations.SuppressWarnings;
@@ -1238,15 +1242,28 @@
}
/**
+ * Adds or reverse engineers a copy of the given source table to this
playpen, using
+ * preferredLocation as the layout constraint. Tries to avoid
+ * adding two tables with identical names.
+ *
+ * @return A reference to the newly-created TablePane.
+ * @see SQLTable#inherit
+ * @see PlayPenLayout#addLayoutComponent(Component,Object)
+ */
+ public synchronized TablePane importTableCopy(SQLTable source, Point
preferredLocation, DuplicateProperties duplicateProperties) throws
SQLObjectException {
+ return importTableCopy(source, preferredLocation,
duplicateProperties, true);
+ }
+
+ /**
* Adds or reverse engineers a copy of the given source table to this
playpen, using
* preferredLocation as the layout constraint. Tries to avoid
* adding two tables with identical names.
- *
+ *
* @return A reference to the newly-created TablePane.
* @see SQLTable#inherit
* @see PlayPenLayout#addLayoutComponent(Component,Object)
*/
- public synchronized TablePane importTableCopy(SQLTable source, Point
preferredLocation, DuplicateProperties duplicateProperties) throws
SQLObjectException {
+ public synchronized TablePane importTableCopy(SQLTable source, Point
preferredLocation, DuplicateProperties duplicateProperties, boolean
assignTypes) throws SQLObjectException {
SQLTable newTable;
switch (duplicateProperties.getDefaultTransferStyle()) {
case REVERSE_ENGINEER:
@@ -1267,7 +1284,18 @@
ASUtils.correctSourceColumn(sourceColumn, duplicateProperties,
column, getSession().getSourceDatabases());
}
- SQLColumn.assignTypes(newTable.getColumns(),
newTable.getParentDatabase().getDataSource().getParentCollection(),
newTable.getParentDatabase().getDataSource().getName());
+ // Although this method is called in AddObjectsTask.cleanup(), it
+ // remains here so that tests will use it as well. Columns that
have
+ // upstream types are ignored, so this is safe.
+ if (assignTypes) {
+ String platform;
+ if (source.getParentDatabase() != null &&
source.getParentDatabase().getDataSource() != null) {
+ platform =
source.getParentDatabase().getDataSource().getParentType().getName();
+ } else {
+ platform =
SQLTypePhysicalPropertiesProvider.GENERIC_PLATFORM;
+ }
+ SQLColumn.assignTypes(newTable.getColumns(),
newTable.getParentDatabase().getDataSource().getParentCollection(),
platform, getSession());
+ }
String key = source.getName().toLowerCase();
boolean isAlreadyOnPlaypen = false;
@@ -1581,6 +1609,9 @@
// reset iterator
Iterator<SQLObject> soIt =
sqlObjects.iterator();
+ // Track all columns added so we can assign
types
+ ArrayListMultimap<String, SQLColumn> addedColumns =
ArrayListMultimap.create();
+
resetTableNames();
while (soIt.hasNext() && !isCancelled()) {
SQLObject someData = soIt.next();
@@ -1592,9 +1623,13 @@
}
if (someData instanceof SQLTable) {
- TablePane tp = importTableCopy((SQLTable) someData,
preferredLocation, duplicateProperties);
+ TablePane tp = importTableCopy((SQLTable) someData,
preferredLocation, duplicateProperties, false);
setMessage(ArchitectUtils.truncateString(((SQLTable)someData).getName()));
preferredLocation.x += tp.getPreferredSize().width
+ 5;
+
+ String platform = ((SQLTable)
someData).getParentDatabase().getDataSource().getParentType().getName();
+ addedColumns.putAll(platform,
tp.getModel().getChildren(SQLColumn.class));
+
increaseProgress();
} else if (someData instanceof
SQLSchema) {
SQLSchema sourceSchema =
(SQLSchema) someData;
@@ -1603,7 +1638,7 @@
Object nextTable = it.next();
SQLTable sourceTable =
(SQLTable) nextTable;
setMessage(ArchitectUtils.truncateString(sourceTable.getName()));
- TablePane tp = importTableCopy(sourceTable, preferredLocation,
duplicateProperties);
+ TablePane tp = importTableCopy(sourceTable, preferredLocation,
duplicateProperties, true);
preferredLocation.x +=
tp.getPreferredSize().width + 5;
increaseProgress();
}
@@ -1618,7 +1653,7 @@
Object
nextTable = it.next();
SQLTable sourceTable = (SQLTable)
nextTable;
setMessage(ArchitectUtils.truncateString(sourceTable.getName()));
- TablePane tp = importTableCopy(sourceTable, preferredLocation,
duplicateProperties);
+ TablePane tp = importTableCopy(sourceTable, preferredLocation,
duplicateProperties, true);
preferredLocation.x += tp.getPreferredSize().width + 5;
increaseProgress();
}
@@ -1628,7 +1663,7 @@
Object nextTable = cit.next();
SQLTable
sourceTable = (SQLTable) nextTable;
setMessage(ArchitectUtils.truncateString(sourceTable.getName()));
- TablePane tp = importTableCopy(sourceTable, preferredLocation,
duplicateProperties);
+ TablePane tp = importTableCopy(sourceTable, preferredLocation,
duplicateProperties, true);
preferredLocation.x += tp.getPreferredSize().width + 5;
increaseProgress();
}
@@ -1637,6 +1672,11 @@
logger.error("Unknown object dropped in PlayPen: "+someData);
//$NON-NLS-1$
}
}
+
+ for (String platform : addedColumns.keySet()) {
+ SQLColumn.assignTypes(addedColumns.get(platform),
session.getDataSources(), platform, session);
+ }
+
session.getPlayPen().getContentPane().commit();
} catch (SQLObjectException e) {
session.getPlayPen().getContentPane().rollback(e.getMessage());
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java Fri
May 7 11:49:29 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java Mon
May 10 11:20:07 2010
@@ -42,6 +42,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import javax.swing.Icon;
import javax.swing.JCheckBoxMenuItem;
@@ -70,7 +71,7 @@
import ca.sqlpower.object.annotation.Mutator;
import ca.sqlpower.object.annotation.NonBound;
import ca.sqlpower.object.annotation.Transient;
-import ca.sqlpower.sql.JDBCDataSource;
+import ca.sqlpower.sql.DataSourceCollection;
import ca.sqlpower.sqlobject.LockedColumnException;
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLIndex;
@@ -87,6 +88,8 @@
import ca.sqlpower.util.SQLPowerUtils;
import ca.sqlpower.util.TransactionEvent;
+import com.google.common.collect.ArrayListMultimap;
+
public class TablePane extends ContainerPane<SQLTable, SQLColumn> {
private static final Logger logger = Logger.getLogger(TablePane.class);
@@ -835,30 +838,33 @@
}
try {
- List<SQLColumn> droppedColumns = new
ArrayList<SQLColumn>();
+ ArrayListMultimap<String, SQLColumn> droppedColumns =
ArrayListMultimap.create();
for (SQLObject o : droppedItems) {
if (o instanceof SQLColumn) {
- droppedColumns.add((SQLColumn) o);
+ droppedColumns.put(((SQLColumn)
o).getParent().getParentDatabase().getDataSource().getParentType().getName(),
(SQLColumn) o);
} else if (o instanceof SQLTable) {
- droppedColumns.addAll(((SQLTable)
o).getChildren(SQLColumn.class));
+ droppedColumns.putAll(((SQLTable)
o).getParentDatabase().getDataSource().getParentType().getName(),
((SQLTable) o).getChildren(SQLColumn.class));
}
}
for (int i = 0; i < importedKeys.size(); i++) {
// Not dealing with self-referencing tables right now.
if
(importedKeys.get(i).getPkTable().equals(importedKeys.get(i).getFkTable()))
continue;
- for (int j = 0; j < droppedColumns.size(); j++) {
- if
(importedKeys.get(i).containsFkColumn(droppedColumns.get(j))) {
+ for (Entry<String, SQLColumn> entry :
droppedColumns.entries()) {
+ if
(importedKeys.get(i).containsFkColumn(entry.getValue())) {
importedKeys.get(i).setIdentifying(newColumnsInPk);
break;
}
}
}
+
+ DataSourceCollection dsCollection =
getModel().getParentDatabase().getDataSource().getParentCollection();
// Note that it is safe to assign types to previously
assigned
// columns, they will be ignored.
- JDBCDataSource ds =
getModel().getParentDatabase().getDataSource();
- SQLColumn.assignTypes(droppedColumns,
ds.getParentCollection(), ds.getName());
+ for (String platform : droppedColumns.keySet()) {
+ SQLColumn.assignTypes(droppedColumns.get(platform),
dsCollection, platform, getPlayPen().getSession());
+ }
ArchitectProject project = this.getParent().getParent();
success = false;