Revision: 3726
Author: [email protected]
Date: Tue Jul 13 13:48:22 2010
Log: Newly added tables now have a number appended to them to distinguish between tables
http://code.google.com/p/power-architect/source/detail?r=3726

Modified:
 /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java Tue Jul 13 10:58:50 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java Tue Jul 13 13:48:22 2010
@@ -1328,24 +1328,26 @@
// unless you like being attacked by screaming monkeys, that is. ArchitectSwingSessionContext context = ASUtils.getContext();

-                    final File openFile;
+ final List<ArchitectSwingSession> sessions = new ArrayList<ArchitectSwingSession>();
                     if (args.length > 0) {
-                        openFile = new File(args[0]);
+                        for (int i = 0; i < args.length; i++) {
+                            File openFile = new File(args[i]);
+ InputStream in = new BufferedInputStream(new FileInputStream(openFile)); + ArchitectSwingSession session = context.createSession(in); + session.getRecentMenu().putRecentFileName(openFile.getAbsolutePath());
+                            session.getProjectLoader().setFile(openFile);
+                            sessions.add(session);
+                        }
                     } else {
-                        openFile = null;
-                    }
-
-                    final ArchitectSwingSession session;
-                    if (openFile != null) {
- InputStream in = new BufferedInputStream(new FileInputStream(openFile));
-                        session = context.createSession(in);
- session.getRecentMenu().putRecentFileName(openFile.getAbsolutePath());
-                        session.getProjectLoader().setFile(openFile);
-                    } else {
-                        session = context.createSession();
+                        sessions.add(context.createSession());
                     }
ArchitectFrame frame = new ArchitectFrame(context, null);
-                    frame.init(session);
+                    frame.init(sessions.get(0));
+                    for (int i = 1; i < sessions.size(); i++) {
+                        frame.addSession(sessions.get(i));
+                        frame.setCurrentSession(sessions.get(i));
+                    }
+                    frame.setCurrentSession(sessions.get(0));
                 } catch (Exception e) {
                     e.printStackTrace();
//We wish we had a parent component to direct the dialog to
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Mon Jul 12 09:30:04 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Tue Jul 13 13:48:22 2010
@@ -1273,21 +1273,15 @@
                }
SQLColumn.assignTypes(newTable.getColumns(), newTable.getParentDatabase().getDataSource().getParentCollection(), platform, getSession());
            }
-
-               String key = source.getName().toLowerCase();
-               boolean isAlreadyOnPlaypen = false;
-               int newSuffix = 0;
-
+           boolean isAlreadyOnPlaypen = false;
+
                // ensure tablename is unique
if (logger.isDebugEnabled()) logger.debug("before add: " + tableNames); //$NON-NLS-1$
-               if (!tableNames.add(key)) {
-                       boolean done = false;
-                       while (!done) {
-                               newSuffix++;
-                               done = tableNames.add(key+"_"+newSuffix); 
//$NON-NLS-1$
-                       }
-                       newTable.setName(source.getName()+"_"+newSuffix); 
//$NON-NLS-1$
-                       isAlreadyOnPlaypen = true;
+               int suffix = uniqueTableSuffix(source.getName());
+               if (suffix != 0) {
+                   String newName = source.getName() + "_" + suffix;
+                   newTable.setName(newName);
+                   isAlreadyOnPlaypen = true;
                }
if (logger.isDebugEnabled()) logger.debug("after add: " + tableNames); //$NON-NLS-1$

@@ -1297,11 +1291,23 @@
                tp.revalidate();

if (duplicateProperties.getDefaultTransferStyle() == TransferStyles.REVERSE_ENGINEER) { - createRelationshipsFromPP(source, newTable, true, isAlreadyOnPlaypen, newSuffix); - createRelationshipsFromPP(source, newTable, false, isAlreadyOnPlaypen, newSuffix); + createRelationshipsFromPP(source, newTable, true, isAlreadyOnPlaypen, suffix); + createRelationshipsFromPP(source, newTable, false, isAlreadyOnPlaypen, suffix);
                }
                return tp;
        }
+
+       public int uniqueTableSuffix(String base) {
+           int suffix = 0;
+           if (!tableNames.add(base.toLowerCase())) {
+            boolean done = false;
+            while (!done) {
+                suffix++;
+ done = tableNames.add(base.toLowerCase() + "_" + suffix); //$NON-NLS-1$
+            }
+        }
+           return suffix;
+       }

        /**
      * Creates exported relationships if the importing tables exist in the

Reply via email to