Revision: 3837
Author: [email protected]
Date: Wed Aug  4 13:00:45 2010
Log: Fixed bug 2925. Once a domain was selected no other domains in that category could be selected. The cause was the session was returning either the snapshot domain category or if it did not exist the system domain category. If only one domain in the category was in the snapshot but there were multiples in the system category some of the system category domains would be missing. The solution was to have the session return the domains themselves in a list and have the UI group them into reasonable categories.

This also fixes an issue where the core session interface was dependent on the DomainCategory class which is in the enterprise package.
http://code.google.com/p/power-architect/source/detail?r=3837

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/ArchitectSession.java
 /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionImpl.java
/trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java /trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/SQLTypeTreeModel.java

=======================================
--- /trunk/regress/ca/sqlpower/architect/StubArchitectSession.java Tue Aug 3 08:39:01 2010 +++ /trunk/regress/ca/sqlpower/architect/StubArchitectSession.java Wed Aug 4 13:00:45 2010
@@ -22,7 +22,6 @@
 import java.util.List;

 import ca.sqlpower.architect.ddl.DDLGenerator;
-import ca.sqlpower.architect.enterprise.DomainCategory;
 import ca.sqlpower.architect.profile.ProfileManager;
 import ca.sqlpower.architect.swingui.LiquibaseSettings;
 import ca.sqlpower.object.SPObjectSnapshot;
@@ -177,7 +176,7 @@
         return null;
     }

-    public List<DomainCategory> getDomainCategories() {
+    public List<UserDefinedSQLType> getDomains() {
         // TODO Auto-generated method stub
         return null;
     }
=======================================
--- /trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java Tue Aug 3 08:39:01 2010 +++ /trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java Wed Aug 4 13:00:45 2010
@@ -35,7 +35,6 @@
 import java.util.List;

 import ca.sqlpower.architect.ddl.DDLGenerator;
-import ca.sqlpower.architect.enterprise.DomainCategory;
 import ca.sqlpower.architect.olap.OLAPRootObject;
 import ca.sqlpower.architect.profile.ProfileManager;
 import ca.sqlpower.architect.swingui.LiquibaseSettings;
@@ -212,7 +211,7 @@
return defaultUPF.createListUserPrompter(question, responses, defaultResponse);
     }

-    public List<DomainCategory> getDomainCategories() {
+    public List<UserDefinedSQLType> getDomains() {
         // TODO Auto-generated method stub
         return null;
     }
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java Tue Aug 3 08:39:01 2010 +++ /trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java Wed Aug 4 13:00:45 2010
@@ -42,7 +42,6 @@
 import ca.sqlpower.architect.ddl.DDLGenerator;
 import ca.sqlpower.architect.ddl.GenericDDLGenerator;
 import ca.sqlpower.architect.enterprise.ArchitectClientSideSession;
-import ca.sqlpower.architect.enterprise.DomainCategory;
 import ca.sqlpower.architect.etl.kettle.KettleJob;
 import ca.sqlpower.architect.olap.OLAPRootObject;
 import ca.sqlpower.architect.olap.OLAPSession;
@@ -497,7 +496,7 @@
return new DefaultUserPrompterFactory().createListUserPrompter(question, responses, defaultResponse);
     }

-    public List<DomainCategory> getDomainCategories() {
+    public List<UserDefinedSQLType> getDomains() {
         return Collections.emptyList();
     }

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectSession.java Tue Aug 3 08:39:01 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectSession.java Wed Aug 4 13:00:45 2010
@@ -22,7 +22,6 @@
 import java.util.List;

 import ca.sqlpower.architect.ddl.DDLGenerator;
-import ca.sqlpower.architect.enterprise.DomainCategory;
 import ca.sqlpower.architect.profile.ProfileManager;
 import ca.sqlpower.architect.swingui.CompareDMSettings;
 import ca.sqlpower.architect.swingui.LiquibaseSettings;
@@ -141,10 +140,10 @@
     public List<UserDefinedSQLType> getSQLTypes();

     /**
- * Returns a list of {...@link DomainCategory}s defined in this session. Only + * Returns a list of {...@link UserDefinedSQLType}s defined in this session. Only
      * enterprise sessions should contain domains.
      */
-    public List<DomainCategory> getDomainCategories();
+    public List<UserDefinedSQLType> getDomains();

     /**
      * Searches the session for a {...@link UserDefinedSQLType} with the given
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionImpl.java Tue Aug 3 08:39:01 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionImpl.java Wed Aug 4 13:00:45 2010
@@ -26,7 +26,6 @@

 import ca.sqlpower.architect.ddl.DDLGenerator;
 import ca.sqlpower.architect.ddl.GenericDDLGenerator;
-import ca.sqlpower.architect.enterprise.DomainCategory;
 import ca.sqlpower.architect.enterprise.UpstreamTypeUpdaterListener;
 import ca.sqlpower.architect.profile.ProfileManager;
 import ca.sqlpower.architect.profile.ProfileManagerImpl;
@@ -283,7 +282,7 @@
return userPrompterFactory.createListUserPrompter(question, responses, defaultResponse);
     }

-    public List<DomainCategory> getDomainCategories() {
+    public List<UserDefinedSQLType> getDomains() {
         return Collections.emptyList();
     }

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java Wed Aug 4 09:59:25 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java Wed Aug 4 13:00:45 2010
@@ -246,6 +246,7 @@
upstreamSnapshot = new UserDefinedSQLTypeSnapshot(upUpStreamType, systemRevision, isUpstreamDomainSnapshot);
                     session.getWorkspace().addChild(upstreamSnapshot, 0);
session.getWorkspace().addChild(upstreamSnapshot.getSPObject(), 0);
+                    upstreamSnapshot.setSnapshotUseCount(1);
                     addUpdateListener(upstreamSnapshot.getSPObject());
                 }
snapshot = new UserDefinedSQLTypeSnapshot(upstreamType, systemRevision, isDomainSnapshot, upstreamSnapshot);
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java Wed Aug 4 09:24:41 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java Wed Aug 4 13:00:45 2010
@@ -323,9 +323,7 @@
                                            public List<UserDefinedSQLType> 
getSQLTypes() {
List<UserDefinedSQLType> types = new ArrayList<UserDefinedSQLType>();
                                                
types.addAll(ArchitectClientSideSession.this.getSQLTypes());
- for (DomainCategory dc : ArchitectClientSideSession.this.getDomainCategories()) {
-                                                   
types.addAll(dc.getChildren(UserDefinedSQLType.class));
-                                               }
+                                               
types.addAll(ArchitectClientSideSession.this.getDomains());
                                                return types;
                                            }

@@ -1155,45 +1153,58 @@
     }

     /**
- * Returns the {...@link List} of {...@link DomainCategory}s in this session's
-     * system workspace.
+ * Returns the {...@link List} of {...@link UserDefinedSQLType}s in this session + * that are children of a {...@link DomainCategory}. Each domain in the system
+     * will be in the list once as either the domain that is in the system
+ * workspace or a snapshot of the domain that is in the current project. UDTs + * that are children of a category are defined as domains instead of types.
      */
     @Override
-    public List<DomainCategory> getDomainCategories() {
+    public List<UserDefinedSQLType> getDomains() {
// The following was my attempt to merge the snapshot and system category lists together // without making it O(nm), but the code is a bit lengthier than I'd like, so perhaps
         // the added complexity may not be worth it?
-        List<DomainCategorySnapshot> categorySnapshots =
- new ArrayList<DomainCategorySnapshot>(getWorkspace().getChildren(DomainCategorySnapshot.class));
+        List<UserDefinedSQLTypeSnapshot> typeSnapshots =
+ new ArrayList<UserDefinedSQLTypeSnapshot>(getWorkspace().getChildren(UserDefinedSQLTypeSnapshot.class));
         List<DomainCategory> systemCategories =
new ArrayList<DomainCategory>(getSystemWorkspace().getChildren(DomainCategory.class)); + List<UserDefinedSQLTypeSnapshot> domainSnapshots = new ArrayList<UserDefinedSQLTypeSnapshot>();
+        for (UserDefinedSQLTypeSnapshot udtSnapshot : typeSnapshots) {
+            if (udtSnapshot.isDomainSnapshot()) {
+                domainSnapshots.add(udtSnapshot);
+            }
+        }
+ List<UserDefinedSQLType> systemDomains = new ArrayList<UserDefinedSQLType>();
+        for (DomainCategory category : systemCategories) {
+ systemDomains.addAll(category.getChildren(UserDefinedSQLType.class));
+        }

         // If there are no snapshots, just return the system categories.
- if (categorySnapshots.size() == 0) return Collections.unmodifiableList(systemCategories); + if (domainSnapshots.size() == 0) return Collections.unmodifiableList(systemDomains);

         // Sort both lists by the UUIDs of the system categories
- Collections.sort(categorySnapshots, new Comparator<DomainCategorySnapshot>() { - public int compare(DomainCategorySnapshot o1, DomainCategorySnapshot o2) { + Collections.sort(domainSnapshots, new Comparator<UserDefinedSQLTypeSnapshot>() { + public int compare(UserDefinedSQLTypeSnapshot o1, UserDefinedSQLTypeSnapshot o2) { return o1.getOriginalUUID().compareTo(o2.getOriginalUUID());
             }
         });
- Collections.sort(systemCategories, new SPObjectUUIDComparator<DomainCategory>()); + Collections.sort(systemDomains, new SPObjectUUIDComparator<UserDefinedSQLType>());

// Now go through the list of system categories. If a snapshot category's // original UUID matches, then replace the system category with the snapshot. - Iterator<DomainCategorySnapshot> snapshotIterator = categorySnapshots.iterator();
-        DomainCategorySnapshot currentSnapshot = snapshotIterator.next();
-
-        for (int i = 0; i < systemCategories.size() ; i++) {
-            DomainCategory type = systemCategories.get(i);
+ Iterator<UserDefinedSQLTypeSnapshot> snapshotIterator = domainSnapshots.iterator(); + UserDefinedSQLTypeSnapshot currentSnapshot = snapshotIterator.next();
+
+        for (int i = 0; i < systemDomains.size() ; i++) {
+            UserDefinedSQLType type = systemDomains.get(i);
int compareTo = currentSnapshot.getOriginalUUID().compareTo(type.getUUID());
             if (compareTo <= 0) {
                 if (compareTo == 0) {
-                    systemCategories.set(i, currentSnapshot.getSPObject());
+                    systemDomains.set(i, currentSnapshot.getSPObject());
                 } else {
-                    systemCategories.add(i, currentSnapshot.getSPObject());
-                }
- if (snapshotIterator.hasNext() && i != systemCategories.size() - 1) {
+                    systemDomains.add(i, currentSnapshot.getSPObject());
+                }
+ if (snapshotIterator.hasNext() && i != systemDomains.size() - 1) {
                     currentSnapshot = snapshotIterator.next();
                 } else {
                     break;
@@ -1204,10 +1215,10 @@
// If we've gone through all the system types, then append the remaining snapshot categories
         while (snapshotIterator.hasNext()) {
             currentSnapshot = snapshotIterator.next();
-            systemCategories.add(currentSnapshot.getSPObject());
+            systemDomains.add(currentSnapshot.getSPObject());
         }

-        return Collections.unmodifiableList(systemCategories);
+        return Collections.unmodifiableList(systemDomains);
     }

     @Override
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Tue Aug 3 08:39:01 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Wed Aug 4 13:00:45 2010
@@ -64,7 +64,6 @@
 import ca.sqlpower.architect.ProjectSettings.ColumnVisibility;
 import ca.sqlpower.architect.ddl.DDLGenerator;
 import ca.sqlpower.architect.enterprise.ArchitectClientSideSession;
-import ca.sqlpower.architect.enterprise.DomainCategory;
 import ca.sqlpower.architect.enterprise.NetworkConflictResolver;
 import ca.sqlpower.architect.etl.kettle.KettleJob;
 import ca.sqlpower.architect.olap.OLAPRootObject;
@@ -1266,8 +1265,8 @@
return swinguiUserPrompterFactory.createListUserPrompter(question, responses, defaultResponse);
     }

-    public List<DomainCategory> getDomainCategories() {
-        return delegateSession.getDomainCategories();
+    public List<UserDefinedSQLType> getDomains() {
+        return delegateSession.getDomains();
     }

     public JScrollPane getPlayPenScrollPane() {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/SQLTypeTreeModel.java Tue Jul 27 09:04:00 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/SQLTypeTreeModel.java Wed Aug 4 13:00:45 2010
@@ -36,6 +36,9 @@
 import ca.sqlpower.object.SPObject;
 import ca.sqlpower.sqlobject.UserDefinedSQLType;

+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
 /**
* This {...@link TreeModel} defines the hierarchy of {...@link UserDefinedSQLType}s
  * and {...@link DomainCategory}s under an {...@link ArchitectProject}.
@@ -81,13 +84,24 @@
     private final List<UserDefinedSQLType> sqlTypes;

     /**
- * The {...@link List} of {...@link DomainCategory}s reflective of the categories - * in the {...@link ArchitectProject} when the constructor of this tree model
-     * is called. Categories are not directly retrieved from the
- * {...@link ArchitectProject} as it may have changed after creation of this
-     * model.
+     * The {...@link List} of {...@link DomainCategory} names reflective of the
+     * categories and domains in the {...@link ArchitectProject} when the
+ * constructor of this tree model is called. The category names are mapped
+     * to a collection of the domains that are under them as the domains
+ * returned by the session could be a combination of actual system domains + * and snapshot domains in the project. In this case the domains are under
+     * different parents but should represent being under the same parent.
+     * <p>
+ * Domains are not directly retrieved from the {...@link ArchitectProject} as
+     * it may have changed after creation of this model.
      */
-    private final List<DomainCategory> domainCategories;
+ private final Multimap<String, UserDefinedSQLType> domainCategoryMap = ArrayListMultimap.create();
+
+    /**
+ * The list of names of domain categories sorted to be in alphabetical order.
+     * All domain categories known to this tree model will be in this list.
+     */
+    private final ArrayList<String> domainCategoryNameList;

     /**
      * Creates a new SQLTypeTreeModel.
@@ -100,20 +114,31 @@
     public SQLTypeTreeModel(ArchitectSession session) {
         root = session.getWorkspace();
sqlTypes = new ArrayList<UserDefinedSQLType>(session.getSQLTypes()); - domainCategories = new ArrayList<DomainCategory>(session.getDomainCategories());
+        Collections.sort(sqlTypes, typeComparator);
+        List<UserDefinedSQLType> domains = session.getDomains();
+        for (UserDefinedSQLType domain : domains) {
+            domainCategoryMap.put(domain.getParent().getName(), domain);
+        }
+ domainCategoryNameList = new ArrayList<String>(domainCategoryMap.keySet());
+        Collections.sort(domainCategoryNameList);
     }

-    public SPObject getChild(Object parent, int index) {
+    public Object getChild(Object parent, int index) {
         // If the parent is the delegate ArchitectProject, get the child at
         // the specified index which should be of type UserDefinedSQLType
         // or DomainCategory.
         if (root == parent) {
-            return getChildren().get(index);
+            if (index < domainCategoryNameList.size()) {
+ //Making a temporary domain category so the icon on the tree renderer is correct. + return new DomainCategory(domainCategoryNameList.get(index)); + } else if (index < domainCategoryNameList.size() + sqlTypes.size()) {
+                return sqlTypes.get(index - domainCategoryNameList.size());
+            }

         // If the parent is DomainCategory, get the child at the specified
         // index which should be of type UserDefinedSQLType.
         } else if (parent instanceof DomainCategory &&
-                domainCategories.contains(parent)) {
+ domainCategoryMap.keySet().contains(((DomainCategory) parent).getName())) {
             return getDomainTypes((DomainCategory) parent).get(index);
         }

@@ -122,25 +147,13 @@

     public int getChildCount(Object parent) {
         if (root == parent) {
-            return getChildren().size();
+            return domainCategoryNameList.size() + sqlTypes.size();
         } else if (parent instanceof DomainCategory &&
-                domainCategories.contains(parent)) {
+ domainCategoryMap.keySet().contains(((DomainCategory) parent).getName())) {
             return getDomainTypes((DomainCategory) parent).size();
         }
         return 0;
     }
-
-    /**
-     * Returns the sorted {...@link List} of {...@link UserDefinedSQLType}s and
-     * {...@link DomainCategory}s that are children of a given project.
-     */
-    private List<? extends SPObject> getChildren() {
-        List<SPObject> children = new ArrayList<SPObject>();
-        children.addAll(domainCategories);
-        children.addAll(sqlTypes);
-        Collections.sort(children, typeComparator);
-        return Collections.unmodifiableList(children);
-    }

     /**
* Creates the sorted {...@link List} of {...@link UserDefinedSQLType}s under a
@@ -153,7 +166,7 @@
      */
private List<UserDefinedSQLType> getDomainTypes(DomainCategory category) { List<UserDefinedSQLType> children = new ArrayList<UserDefinedSQLType>(
-                category.getChildren(UserDefinedSQLType.class));
+                domainCategoryMap.get(category.getName()));
         Collections.sort(children, typeComparator);
         return Collections.unmodifiableList(children);
     }
@@ -162,9 +175,13 @@
         if (parent == null || child == null) {
             return -1;
         } else if (root == parent) {
-            return getChildren().indexOf(child);
+            if (domainCategoryNameList.contains(child)) {
+                return domainCategoryNameList.indexOf(child);
+            } else if (sqlTypes.contains(child)) {
+ return domainCategoryNameList.size() + sqlTypes.indexOf(child);
+            }
         } else if (parent instanceof DomainCategory &&
-                domainCategories.contains(parent)) {
+ domainCategoryMap.keySet().contains(((DomainCategory) parent))) {
             if (child instanceof UserDefinedSQLType) {
return getDomainTypes((DomainCategory) parent).indexOf(child);
             }

Reply via email to