Merge branch 'master' into packaging
[pithos-web-client] / src / gr / grnet / pithos / web / client / Pithos.java
index cfd53a1..992916f 100644 (file)
@@ -34,7 +34,6 @@
  */
 package gr.grnet.pithos.web.client;
 
-import gr.grnet.pithos.web.client.PithosDisclosurePanel.Style;
 import gr.grnet.pithos.web.client.commands.UploadFileCommand;
 import gr.grnet.pithos.web.client.foldertree.AccountResource;
 import gr.grnet.pithos.web.client.foldertree.File;
@@ -63,6 +62,7 @@ import java.util.Set;
 
 import com.google.gwt.core.client.EntryPoint;
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.JsArrayString;
 import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.core.client.Scheduler.RepeatingCommand;
 import com.google.gwt.core.client.Scheduler.ScheduledCommand;
@@ -77,7 +77,6 @@ import com.google.gwt.http.client.RequestException;
 import com.google.gwt.http.client.Response;
 import com.google.gwt.http.client.URL;
 import com.google.gwt.i18n.client.Dictionary;
-import com.google.gwt.i18n.client.NumberFormat;
 import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONParser;
@@ -86,7 +85,6 @@ import com.google.gwt.json.client.JSONValue;
 import com.google.gwt.resources.client.ClientBundle;
 import com.google.gwt.resources.client.CssResource;
 import com.google.gwt.resources.client.ImageResource;
-import com.google.gwt.resources.client.ClientBundle.Source;
 import com.google.gwt.resources.client.ImageResource.ImageOptions;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.Cookies;
@@ -102,6 +100,7 @@ import com.google.gwt.user.client.ui.HasHorizontalAlignment;
 import com.google.gwt.user.client.ui.HasVerticalAlignment;
 import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.HorizontalSplitPanel;
+import com.google.gwt.user.client.ui.PopupPanel;
 import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.view.client.SelectionChangeEvent;
@@ -126,11 +125,24 @@ public class Pithos implements EntryPoint, ResizeHandler {
                
                @ClassName("gwt-HTML")
                String html();
+               
+               String uploadAlert();
+
+               String uploadAlertLink();
+
+               String uploadAlertProgress();
+               
+               String uploadAlertPercent();
+               
+               String uploadAlertClose();
        }
        
        public interface Resources extends ClientBundle {
                @Source("Pithos.css")
                Style pithosCss();
+               
+               @Source("gr/grnet/pithos/resources/close-popup.png")
+               ImageResource closePopup();
        }
 
        public static Resources resources = GWT.create(Resources.class);
@@ -173,8 +185,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
        updateSharedFolder(f, showfiles, null);
     }
 
-    public void updateOtherSharedFolder(Folder f, boolean showfiles) {
-       otherSharedTreeView.updateFolder(f, showfiles);
+    public void updateOtherSharedFolder(Folder f, boolean showfiles, Command callback) {
+       otherSharedTreeView.updateFolder(f, showfiles, callback);
     }
 
     public MysharedTreeView getMySharedTreeView() {
@@ -215,7 +227,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
        /**
         * The bottom panel that contains the status bar.
         */
-       private StatusPanel statusPanel = null;
+       StatusPanel statusPanel = null;
 
        /**
         * The file list widget.
@@ -280,8 +292,10 @@ public class Pithos implements EntryPoint, ResizeHandler {
     
     private Toolbar toolbar;
     
-    private FileUploadDialog fileUploadDialog;
-    
+    private FileUploadDialog fileUploadDialog = new FileUploadDialog(this);
+
+       UploadAlert uploadAlert;
+
        @Override
        public void onModuleLoad() {
                if (parseUserCredentials())
@@ -347,7 +361,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         header.setCellWidth(folderStatistics, "40px");
         outer.add(header);
         outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER);
-        // Inner contains the various lists.nner
+        // Inner contains the various lists
         inner.sinkEvents(Event.ONCONTEXTMENU);
         inner.setWidth("100%");
 
@@ -385,14 +399,15 @@ public class Pithos implements EntryPoint, ResizeHandler {
         fileList = new FileList(this, images);
         inner.add(fileList);
 
-        inner.add(createUploadArea());
-        
         trees = new VerticalPanel();
         trees.setWidth("100%");
         
         // Add the left and right panels to the split panel.
         splitPanel.setLeftWidget(trees);
-        splitPanel.setRightWidget(inner);
+        FlowPanel right = new FlowPanel();
+        right.getElement().setId("rightPanel");
+        right.add(inner);
+        splitPanel.setRightWidget(right);
         splitPanel.setSplitPosition("219px");
         splitPanel.setSize("100%", "100%");
         splitPanel.addStyleName("pithos-splitPanel");
@@ -420,14 +435,17 @@ public class Pithos implements EntryPoint, ResizeHandler {
         // Call the window resized handler to get the initial sizes setup. Doing
         // this in a deferred command causes it to occur after all widgets'
         // sizes have been computed by the browser.
-        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
-
-            @Override
-            public void execute() {
+        Scheduler.get().scheduleIncremental(new RepeatingCommand() {
+                       
+                       @Override
+                       public boolean execute() {
+                               if (!isCloudbarReady())
+                                       return true;
                 onWindowResized(Window.getClientHeight());
-            }
-        });
-
+                               return false;
+                       }
+               });
+        
         Scheduler.get().scheduleDeferred(new ScheduledCommand() {
             @Override
             public void execute() {
@@ -490,23 +508,23 @@ public class Pithos implements EntryPoint, ResizeHandler {
        if (f != null) {
                if (f.isInTrash()) {
                        upload.setEnabled(false);
-                       hideUploadArea();
+                       disableUploadArea();
                }
                else {
                        Boolean[] perms = f.getPermissions().get(username);
                        if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) {
                                upload.setEnabled(true);
-                               showUploadArea();
+                               enableUploadArea();
                        }
                        else {
                                upload.setEnabled(false);
-                               hideUploadArea();
+                               disableUploadArea();
                        }
                }
        }
        else {
                upload.setEnabled(false);
-               hideUploadArea();
+               disableUploadArea();
        }
        }
 
@@ -568,7 +586,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         Window.Location.assign(otherProperties.get("loginUrl") + Window.Location.getHref());
        }
 
-       protected void fetchAccount(final Command callback) {
+       public void fetchAccount(final Command callback) {
         String path = "?format=json";
 
         GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
@@ -700,13 +718,19 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
        protected void onWindowResized(int height) {
                // Adjust the split panel to take up the available room in the window.
-               int newHeight = height - splitPanel.getAbsoluteTop();
+               int newHeight = height - splitPanel.getAbsoluteTop() - 153;
                if (newHeight < 1)
                        newHeight = 1;
                splitPanel.setHeight("" + newHeight);
                inner.setHeight("" + newHeight);
        }
-
+       
+       native boolean isCloudbarReady()/*-{
+               if ($wnd.$("div.servicesbar") && $wnd.$("div.servicesbar").height() > 0)
+                       return true;
+               return false;
+       }-*/;
+       
        @Override
        public void onResize(ResizeEvent event) {
                int height = event.getHeight();
@@ -720,6 +744,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         */
        public void displayError(String msg) {
                messagePanel.displayError(msg);
+               onWindowResized(Window.getClientHeight());
        }
 
        /**
@@ -729,6 +754,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         */
        public void displayWarning(String msg) {
                messagePanel.displayWarning(msg);
+               onWindowResized(Window.getClientHeight());
        }
 
        /**
@@ -738,6 +764,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         */
        public void displayInformation(String msg) {
                messagePanel.displayInformation(msg);
+               onWindowResized(Window.getClientHeight());
        }
 
        /**
@@ -1123,7 +1150,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                        if (mysharedTreeSelectionModel.getSelectedObject() != null) {
                            deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
                            upload.setEnabled(false);
-                           hideUploadArea();
+                           disableUploadArea();
                            updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
                                        showRelevantToolbarButtons();
                        }
@@ -1157,7 +1184,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                        if (otherSharedTreeSelectionModel.getSelectedObject() != null) {
                            deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
                            applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
-                           updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
+                           updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true, null);
                                        showRelevantToolbarButtons();
                        }
                                else {
@@ -1314,103 +1341,6 @@ public class Pithos implements EntryPoint, ResizeHandler {
                return getSelectedTree().equals(getMySharedTreeView());
        }
        
-       private FlowPanel createUploadArea() {
-               FlowPanel area = new FlowPanel();
-               area.getElement().setId("container");
-               HTML list = new HTML();
-               list.getElement().setId("filelist");
-               area.add(list);
-               Scheduler.get().scheduleDeferred(new ScheduledCommand() {
-                       
-                       @Override
-                       public void execute() {
-                               setupUploadArea(Pithos.this, getToken());
-                       }
-               });
-               
-               return area;
-       }
-       
-       native void setupUploadArea(Pithos app, String token) /*-{
-               $wnd.$("#container").pluploadQueue({
-                       // General settings
-                       runtimes : 'html5',
-                       unique_names : true,
-                       multiple_queues: true,
-                       drop_element: 'filelist',
-                       
-                       preinit: {
-                               Init: function(up, info) {
-                                       if ($wnd.console && $wnd.console.log)
-                                               $wnd.console.log("Init fired");
-                                       up.settings.file_data_name = "X-Object-Data";                           
-                               }
-                       },
-                       
-                       init: {
-                               FilesAdded: function(up, files) {
-                                       $wnd.$('#container').css('border', '');
-                                       var api = app.@gr.grnet.pithos.web.client.Pithos::getApiPath()();
-                                       var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
-                                       var owner = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getOwner()();
-                                       var uri = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getUri()();
-                                       var path = api + owner + uri;
-                                       for (var j=0; j<files.length; j++) {
-                                               files[j].folder = folder;
-                                               files[j].url = path + "/" + files[j].name + "?X-Auth-Token=" + encodeURIComponent(token);
-                                       }
-                                       up.start();
-                               },
-                               
-                               BeforeUpload: function(up, file) {
-                                       if ($wnd.console && $wnd.console.log)
-                                               $wnd.console.log('About to upload ' + file.url);
-                                       up.settings.url = file.url;
-                               },
-                               
-                               FileUploaded: function(up, file, response) {
-                                       if ($wnd.console && $wnd.console.log) {
-                                               $wnd.console.log('File ' + file.name + ' uploaded');
-                                               $wnd.console.log('Response: ' + response);
-                                       }
-                                       up.removeFile(file);
-                                       var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
-                                       if (folder == file.folder)
-                                               app.@gr.grnet.pithos.web.client.Pithos::updateUploadFolder()();
-                               },
-                               
-                               UploadComplete: function(up, files) {
-                                       if ($wnd.console && $wnd.console.log)
-                                               $wnd.console.log('All files finished');
-                               },
-                               
-                               Error: function(up, error) {
-                                       if ($wnd.console && $wnd.console.log)
-                                               $wnd.console.log("Error occured:" + error);
-                               }
-                       }
-               });
-               var uploader = $wnd.$("#container").pluploadQueue();
-               if (uploader.runtime != 'html5')
-                       $wnd.$("#container").hide();
-               else {
-                       if ($wnd.console && $wnd.console.log) {
-                               $wnd.console.log(uploader);
-                               $wnd.console.log($wnd.plupload);
-                       }
-                       $wnd.$('.plupload_header').hide();
-                       $wnd.$('.plupload_filelist_header').hide();
-                       $wnd.$('#container_filelist').css('overflow-y', 'auto');
-                       $wnd.$('.plupload_filelist_footer').hide();
-                       $wnd.document.getElementById('container').addEventListener('dragenter', function(event) {
-                               $wnd.$('#container').css('border', '3px inset');
-                       }, false);
-                       $wnd.document.getElementById('container').addEventListener('dragleave', function(event) {
-                               $wnd.$('#container').css('border', '');
-                       }, false);
-               }
-       }-*/;
-       
        private Folder getUploadFolder() {
                if (folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
                        return getSelection();
@@ -1419,6 +1349,10 @@ public class Pithos implements EntryPoint, ResizeHandler {
        }
        
        private void updateUploadFolder() {
+               updateUploadFolder(null);
+       }
+       
+       private void updateUploadFolder(final JsArrayString urls) {
                if (folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
                        Folder f = getSelection();
                        if (getSelectedTree().equals(getFolderTreeView()))
@@ -1427,18 +1361,54 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                        @Override
                                        public void execute() {
                                                updateStatistics();
+                                               if (urls != null)
+                                                       selectUploadedFiles(urls);
                                        }
                                }, false);
                        else
-                               updateOtherSharedFolder(f, true);
+                               updateOtherSharedFolder(f, true, null);
                }
        }
 
-       public native void hideUploadArea() /*-{
-               $wnd.$("#container").hide();
+       public native void disableUploadArea() /*-{
+               var uploader = $wnd.$("#uploader").pluploadQueue();
+               var dropElm = $wnd.document.getElementById('rightPanel');
+               $wnd.plupload.removeAllEvents(dropElm, uploader.id);
        }-*/;
 
-       public native void showUploadArea() /*-{
-               $wnd.$("#container").show();
+       public native void enableUploadArea() /*-{
+               var uploader = $wnd.$("#uploader").pluploadQueue();
+               var dropElm = $wnd.document.getElementById('rightPanel');
+               $wnd.plupload.removeAllEvents(dropElm, uploader.id);
+               if (uploader.runtime == 'html5') {
+                       uploader.settings.drop_element = 'rightPanel';
+                       uploader.trigger('PostInit');
+               }
        }-*/;
+       
+       public void showUploadAlert(int nOfFiles) {
+               if (uploadAlert == null)
+                       uploadAlert = new UploadAlert(this, nOfFiles);
+               if (!uploadAlert.isShowing())
+                       uploadAlert.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
+                               
+                               @Override
+                               public void setPosition(int offsetWidth, int offsetHeight) {
+                                       uploadAlert.setPopupPosition((Window.getClientWidth() - offsetWidth)/2, statusPanel.getAbsoluteTop() - offsetHeight);
+                               }
+                       });
+               uploadAlert.setNumOfFiles(nOfFiles);
+       }
+       
+       public void hideUploadAlert() {
+               if (uploadAlert != null && uploadAlert.isShowing())
+                       uploadAlert.hide();
+       }
+       
+       public void selectUploadedFiles(JsArrayString urls) {
+               List<String> selectedUrls = new ArrayList<String>();
+               for (int i=0; i<urls.length(); i++)
+                       selectedUrls.add(urls.get(i));
+               fileList.selectByUrl(selectedUrls);
+       }
 }