commit eee72ed54eda04a71ab5007f8f6ee78ef099c93f
Author: Christos KK Loverdos <loverdos@gmail.com>
Date:   Tue Feb 5 14:03:24 2013 +0200

    Add UpdateUserCatalogs as a convenience wrapper around GetUserCatalogs

diff --git a/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java b/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java
index 4913fba..ffd3701 100644
--- a/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java
+++ b/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java
@@ -38,6 +38,7 @@ import com.google.gwt.http.client.Request;
 import com.google.gwt.http.client.Response;
 import com.google.gwt.json.client.JSONObject;
 import gr.grnet.pithos.web.client.catalog.GetUserCatalogs;
+import gr.grnet.pithos.web.client.catalog.UpdateUserCatalogs;
 import gr.grnet.pithos.web.client.catalog.UserCatalogs;
 import gr.grnet.pithos.web.client.grouptree.Group;
 
@@ -187,11 +188,10 @@ public class PermissionsAddDialog extends DialogBox {
         }
         else {
             // Must call server to obtain userID
-            new GetUserCatalogs(app, null, Helpers.toList(userDisplayName)) {
+            new UpdateUserCatalogs(app, null, Helpers.toList(userDisplayName)) {
                 @Override
-                public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) {
-                    app.getUserCatalogs().updateFrom(userCatalogs);
-                    final String userID = app.getUserIDForDisplayName(userDisplayName);
+                public void onSuccess(UserCatalogs requestedUserCatalogs, UserCatalogs updatedUserCatalogs) {
+                    final String userID = updatedUserCatalogs.getUserID(userDisplayName);
                     if(userID == null) {
                         app.displayWarning("Unknown user " + userDisplayName);
                     }
diff --git a/src/gr/grnet/pithos/web/client/PermissionsList.java b/src/gr/grnet/pithos/web/client/PermissionsList.java
index f97c958..2c8c40c 100644
--- a/src/gr/grnet/pithos/web/client/PermissionsList.java
+++ b/src/gr/grnet/pithos/web/client/PermissionsList.java
@@ -57,6 +57,7 @@ import com.google.gwt.user.client.ui.PushButton;
 import com.google.gwt.user.client.ui.RadioButton;
 import com.google.gwt.user.client.ui.VerticalPanel;
 import gr.grnet.pithos.web.client.catalog.GetUserCatalogs;
+import gr.grnet.pithos.web.client.catalog.UpdateUserCatalogs;
 import gr.grnet.pithos.web.client.catalog.UserCatalogs;
 
 
@@ -142,11 +143,10 @@ public class PermissionsList extends Composite {
                     );
                 }
                 else {
-                    new GetUserCatalogs(app, userID) {
+                    new UpdateUserCatalogs(app, userID) {
                         @Override
-                        public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) {
-                            app.getUserCatalogs().updateFrom(userCatalogs);
-                            final String displayName = app.getUserDisplayNameForID(userID);
+                        public void onSuccess(UserCatalogs requestedUserCatalogs, UserCatalogs updatedUserCatalogs) {
+                            final String displayName = updatedUserCatalogs.getDisplayName(userID);
                             permTable.setHTML(
                                 ii,
                                 0,
diff --git a/src/gr/grnet/pithos/web/client/Pithos.java b/src/gr/grnet/pithos/web/client/Pithos.java
index bc267f9..7c94e9c 100644
--- a/src/gr/grnet/pithos/web/client/Pithos.java
+++ b/src/gr/grnet/pithos/web/client/Pithos.java
@@ -61,6 +61,7 @@ import com.google.gwt.view.client.SelectionChangeEvent;
 import com.google.gwt.view.client.SelectionChangeEvent.Handler;
 import com.google.gwt.view.client.SingleSelectionModel;
 import gr.grnet.pithos.web.client.catalog.GetUserCatalogs;
+import gr.grnet.pithos.web.client.catalog.UpdateUserCatalogs;
 import gr.grnet.pithos.web.client.catalog.UserCatalogs;
 import gr.grnet.pithos.web.client.commands.UploadFileCommand;
 import gr.grnet.pithos.web.client.foldertree.*;
@@ -722,13 +723,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                     callback.execute();
                 }
                 // Initialize the user catalog
-                new GetUserCatalogs(Pithos.this, Pithos.this.getUserID()) {
-                    @Override
-                    public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs usersCatalog) {
-                        super.onSuccess(request, response, result, usersCatalog);
-                        Pithos.this.userCatalogs.updateFrom(usersCatalog);
-                    }
-                }.scheduleDeferred();
+                new UpdateUserCatalogs(Pithos.this, Pithos.this.getUserID()).scheduleDeferred();
             }
 
             @Override
diff --git a/src/gr/grnet/pithos/web/client/catalog/UpdateUserCatalogs.java b/src/gr/grnet/pithos/web/client/catalog/UpdateUserCatalogs.java
new file mode 100644
index 0000000..bfebfab
--- /dev/null
+++ b/src/gr/grnet/pithos/web/client/catalog/UpdateUserCatalogs.java
@@ -0,0 +1,65 @@
+package gr.grnet.pithos.web.client.catalog;
+
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.http.client.Request;
+import com.google.gwt.http.client.Response;
+import com.google.gwt.json.client.JSONObject;
+import gr.grnet.pithos.web.client.Helpers;
+import gr.grnet.pithos.web.client.Pithos;
+
+import java.util.List;
+
+/**
+ * This is a wrapper around GetUserCatalogs that takes care of updating
+ * the application-wide user catalogs.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+public class UpdateUserCatalogs implements Scheduler.ScheduledCommand {
+    private final GetUserCatalogs getUserCatalogs;
+    private final Pithos app;
+
+    public UpdateUserCatalogs(Pithos app) {
+        this(app, null, null);
+    }
+
+    public UpdateUserCatalogs(Pithos app, String userID) {
+        this(app, Helpers.toList(userID), null);
+    }
+
+    public UpdateUserCatalogs(Pithos app, List<String> ids) {
+        this(app, ids, null);
+    }
+
+    public void onSuccess(UserCatalogs requestedUserCatalogs, UserCatalogs updatedUserCatalogs) {
+    }
+
+    public void onError(Request request, Throwable t) {
+        getUserCatalogs.onError(request, t);
+    }
+
+    public UpdateUserCatalogs(Pithos app, List<String> ids, List<String> names) {
+        this.app = app;
+        this.getUserCatalogs = new GetUserCatalogs(app, ids, names) {
+            @Override
+            public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) {
+                UpdateUserCatalogs.this.app.getUserCatalogs().updateFrom(userCatalogs);
+                UpdateUserCatalogs.this.onSuccess(userCatalogs, UpdateUserCatalogs.this.app.getUserCatalogs());
+            }
+
+            @Override
+            public void onError(Request request, Throwable t) {
+                UpdateUserCatalogs.this.onError(request, t);
+            }
+        };
+    }
+
+    @Override
+    public void execute() {
+        this.getUserCatalogs.execute();
+    }
+
+    public void scheduleDeferred() {
+        Scheduler.get().scheduleDeferred(this);
+    }
+}
diff --git a/src/gr/grnet/pithos/web/client/othersharedtree/OtherSharedTreeViewModel.java b/src/gr/grnet/pithos/web/client/othersharedtree/OtherSharedTreeViewModel.java
index 0758c7d..1879b89 100644
--- a/src/gr/grnet/pithos/web/client/othersharedtree/OtherSharedTreeViewModel.java
+++ b/src/gr/grnet/pithos/web/client/othersharedtree/OtherSharedTreeViewModel.java
@@ -58,6 +58,7 @@ import gr.grnet.pithos.web.client.FolderContextMenu;
 import gr.grnet.pithos.web.client.Pithos;
 import gr.grnet.pithos.web.client.SharingUsers;
 import gr.grnet.pithos.web.client.catalog.GetUserCatalogs;
+import gr.grnet.pithos.web.client.catalog.UpdateUserCatalogs;
 import gr.grnet.pithos.web.client.catalog.UserCatalogs;
 import gr.grnet.pithos.web.client.foldertree.AccountResource;
 import gr.grnet.pithos.web.client.foldertree.Folder;
@@ -201,18 +202,9 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
                     fetchSharedContainers(userLevelDataProviderForIDs.getList().iterator(), callback);
                 } else {
                     // First fetch unknown display names and then proceed
-                    new GetUserCatalogs(app, userIDsWithUnknownDisplayNames) {
+                    new UpdateUserCatalogs(app, userIDsWithUnknownDisplayNames) {
                         @Override
-                        public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) {
-//                            for(Map.Entry<String, String> entry : userCatalogs) {
-//                                final String id = entry.getKey();
-//                                final String name = entry.getValue();
-//                                LOG("mapping: userID("+id+") -> name("+name+")");
-//                            }
-
-                            // Update the cached user catalogs
-                            app.getUserCatalogs().updateFrom(userCatalogs);
-
+                        public void onSuccess(UserCatalogs requestedUserCatalogs, UserCatalogs updatedUserCatalogs) {
                             fetchSharedContainers(userLevelDataProviderForIDs.getList().iterator(), callback);
                         }
 
