Added upload alert when droping files in the app and select the uploaded files at...
authorChristos Stathis <chstath@ebs.gr>
Fri, 18 May 2012 16:11:07 +0000 (19:11 +0300)
committerChristos Stathis <chstath@ebs.gr>
Fri, 18 May 2012 16:11:07 +0000 (19:11 +0300)
src/gr/grnet/pithos/resources/close-popup.png [new file with mode: 0644]
src/gr/grnet/pithos/web/client/FileList.java
src/gr/grnet/pithos/web/client/FileUploadDialog.java
src/gr/grnet/pithos/web/client/Pithos.css
src/gr/grnet/pithos/web/client/Pithos.java
src/gr/grnet/pithos/web/client/UploadAlert.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/othersharedtree/OtherSharedTreeView.java
src/gr/grnet/pithos/web/client/othersharedtree/OtherSharedTreeViewModel.java

diff --git a/src/gr/grnet/pithos/resources/close-popup.png b/src/gr/grnet/pithos/resources/close-popup.png
new file mode 100644 (file)
index 0000000..4791b32
Binary files /dev/null and b/src/gr/grnet/pithos/resources/close-popup.png differ
index 0e5e54d..d927970 100644 (file)
@@ -44,6 +44,7 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import com.google.gwt.cell.client.Cell.Context;
 import com.google.gwt.cell.client.ImageResourceCell;
@@ -665,4 +666,19 @@ public class FileList extends Composite {
                else if (callback != null)
                        callback.execute();
        }
+
+       public void selectByUrl(List<String> selectedUrls) {
+               Set<File> previous = selectionModel.getSelectedSet();
+               for (File f : previous)
+                       selectionModel.setSelected(f, false);
+               
+               int i = 0;
+               for (File f : files) {
+                       if (selectedUrls.contains(app.getApiPath() + f.getOwner() + f.getUri())) {
+                               selectionModel.setSelected(f, true);
+                               celltable.getRowElement(i).scrollIntoView();
+                       }
+                       i++;
+               }
+       }
 }
index 1457ef8..ba778d6 100644 (file)
@@ -170,7 +170,7 @@ public class FileUploadDialog extends DialogBox {
                                }
                        }, true);
                else
-                       app.updateOtherSharedFolder(folder, true);
+                       app.updateOtherSharedFolder(folder, true, null);
        }
        
        native void setupUpload(FileUploadDialog dlg, Pithos app, String token) /*-{
@@ -206,10 +206,11 @@ public class FileUploadDialog extends DialogBox {
                                                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].url = path + "/" + files[j].name + "?X-Auth-Token=" + encodeURIComponent(token);
+                                                       files[j].url = path + "/" + files[j].name;
                                                dlg.@gr.grnet.pithos.web.client.FileUploadDialog::setInProgress(Z)(true);
                                                up.start();
                                                app.@gr.grnet.pithos.web.client.Pithos::showUploadIndicator()();
+                                               app.@gr.grnet.pithos.web.client.Pithos::showUploadAlert(I)(files.length);
                                        },
                                        
                                        FilesRemoved: function(up, files) {
@@ -222,7 +223,7 @@ public class FileUploadDialog extends DialogBox {
                                        BeforeUpload: function(up, file) {
                                                if ($wnd.console && $wnd.console.log)
                                                        $wnd.console.log('About to upload ' + file.url);
-                                               up.settings.url = file.url;
+                                               up.settings.url = file.url + + "?X-Auth-Token=" + encodeURIComponent(token);
                                        },
                                        
                                        FileUploaded: function(up, file, response) {
@@ -240,6 +241,11 @@ public class FileUploadDialog extends DialogBox {
                                                        $wnd.console.log('All files finished');
                                                dlg.@gr.grnet.pithos.web.client.FileUploadDialog::setInProgress(Z)(false);
                                                dlg.@gr.grnet.pithos.web.client.FileUploadDialog::hideUploadIndicator()();
+                                               app.@gr.grnet.pithos.web.client.Pithos::hideUploadAlert()();
+                                               var uris = [];
+                                               for (var i = 0; i<files.length; i++)
+                                                       uris.push(files[i].url);
+                                               app.@gr.grnet.pithos.web.client.Pithos::updateUploadFolder(Lcom/google/gwt/core/client/JsArrayString;)(uris);
                                        },
                                        
                                        Error: function(up, error) {
@@ -343,7 +349,6 @@ public class FileUploadDialog extends DialogBox {
                var uploader = $wnd.$("#uploader").pluploadQueue();
                if (uploader.runtime == 'html5') {
                        uploader.settings.drop_element = 'rightPanel';
-                       var dropElm = $wnd.document.getElementById(uploader.settings.drop_element);
                        uploader.trigger('PostInit');
                }
        }-*/;
index 09c8e41..3fb0478 100644 (file)
 .statistics .gwt-HTML {
        font-size: 80%;
 }
+
+.uploadAlert {
+       background-color: #4085a5;
+       border: none;
+       width: 350px;
+}
+
+.uploadAlertLink {
+       text-decoration: underline;
+       position: absolute;
+       left: 200px;
+       top: 2px;
+}
+
+.uploadAlertClose {
+       cursor: pointer;
+       position: absolute;
+       right: 1px;
+       top: 2px;
+}
index f542a11..cf14f1b 100644 (file)
@@ -63,6 +63,9 @@ import java.util.Set;
 
 import com.google.gwt.core.client.EntryPoint;
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+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;
@@ -102,6 +105,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 +130,20 @@ public class Pithos implements EntryPoint, ResizeHandler {
                
                @ClassName("gwt-HTML")
                String html();
+               
+               String uploadAlert();
+
+               String uploadAlertLink();
+
+               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 +186,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() {
@@ -281,7 +294,9 @@ public class Pithos implements EntryPoint, ResizeHandler {
     private Toolbar toolbar;
     
     private FileUploadDialog fileUploadDialog = new FileUploadDialog(this);
-    
+
+       UploadAlert uploadAlert;
+
        @Override
        public void onModuleLoad() {
                if (parseUserCredentials())
@@ -1160,7 +1175,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 {
@@ -1342,6 +1357,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()))
@@ -1350,10 +1369,12 @@ 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);
                }
        }
 
@@ -1365,10 +1386,33 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
        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';
-                       var dropElm = $wnd.document.getElementById(uploader.settings.drop_element);
                        uploader.trigger('PostInit');
                }
        }-*/;
+       
+       public void showUploadAlert(int numOfFiles) {
+               uploadAlert = new UploadAlert(this, numOfFiles);
+               uploadAlert.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
+                       
+                       @Override
+                       public void setPosition(int offsetWidth, int offsetHeight) {
+                               uploadAlert.setPopupPosition((Window.getClientWidth() - offsetWidth)/2, Window.getClientHeight() - offsetHeight);
+                       }
+               });
+       }
+       
+       public void hideUploadAlert() {
+               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);
+       }
 }
diff --git a/src/gr/grnet/pithos/web/client/UploadAlert.java b/src/gr/grnet/pithos/web/client/UploadAlert.java
new file mode 100644 (file)
index 0000000..5cffa45
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+package gr.grnet.pithos.web.client;
+
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.ui.Anchor;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.PopupPanel;
+
+/**
+ * The 'Folder Context' menu implementation.
+ */
+public class UploadAlert extends PopupPanel {
+       
+       /**
+        * The widget's constructor.
+        */
+       public UploadAlert(final Pithos app, int numOfFiles) {
+               // The popup's constructor's argument is a boolean specifying that it
+               // auto-close itself when the user clicks outside of it.
+               super(false);
+               setAnimationEnabled(true);
+               addStyleName(Pithos.resources.pithosCss().uploadAlert());
+               FlowPanel content = new FlowPanel();
+               String label = String.valueOf(numOfFiles) + " " + (numOfFiles > 1 ? "files are" : "file is") + " being uploaded";
+               content.add(new HTML(label));
+               Anchor a = new Anchor("Click for details");
+               a.addStyleName(Pithos.resources.pithosCss().uploadAlertLink());
+               a.addClickHandler(new ClickHandler() {
+                       
+                       @Override
+                       public void onClick(ClickEvent event) {
+                       app.getFileUploadDialog().center();
+                       }
+               });
+               content.add(a);
+               Image close = new Image(Pithos.resources.closePopup());
+               close.addClickHandler(new ClickHandler() {
+                       
+                       @Override
+                       public void onClick(ClickEvent event) {
+                               hide();
+                       }
+               });
+               close.addStyleName(Pithos.resources.pithosCss().uploadAlertClose());
+               content.add(close);
+               add(content);
+       }
+}
index 33491dc..d28b45c 100644 (file)
@@ -49,6 +49,7 @@ import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.user.cellview.client.CellTree;
 import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
 import com.google.gwt.user.cellview.client.TreeNode;
+import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.Tree;
 
@@ -175,7 +176,7 @@ public class OtherSharedTreeView extends Composite implements TreeView {
        return model.getSelection();
     }
 
-    public void updateFolder(Folder folder, boolean showfiles) {
-        model.updateFolder(folder, showfiles);
+    public void updateFolder(Folder folder, boolean showfiles, Command callback) {
+        model.updateFolder(folder, showfiles, callback);
     }
 }
index d7df929..b2ba2aa 100644 (file)
@@ -156,7 +156,7 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
                 dataProviderMap.put(f, new ListDataProvider<Folder>());
             }
             final ListDataProvider<Folder> dataProvider = dataProviderMap.get(f);
-            fetchFolder(f, dataProvider, false);
+            fetchFolder(f, dataProvider, false, null);
             return new DefaultNodeInfo<Folder>(dataProvider, folderCell, selectionModel, null);
         }
     }
@@ -305,15 +305,15 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
         return selectionModel.getSelectedObject();
     }
 
-    public void updateFolder(Folder folder, boolean showfiles) {
+    public void updateFolder(Folder folder, boolean showfiles, Command callback) {
         if (dataProviderMap.get(folder) == null) {
             dataProviderMap.put(folder, new ListDataProvider<Folder>());
         }
         final ListDataProvider<Folder> dataProvider = dataProviderMap.get(folder);
-        fetchFolder(folder, dataProvider, showfiles);
+        fetchFolder(folder, dataProvider, showfiles, callback);
     }
 
-    public void fetchFolder(final Folder f, final ListDataProvider<Folder> dataProvider, final boolean showfiles) {
+    public void fetchFolder(final Folder f, final ListDataProvider<Folder> dataProvider, final boolean showfiles, final Command callback) {
         String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
         GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwner(), path, f) {
             @Override
@@ -327,6 +327,8 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
                         dataProvider.getList().clear();
                         dataProvider.getList().addAll(_result.getSubfolders());
                         app.getOtherSharedTreeView().updateChildren(f);
+                        if (callback != null)
+                               callback.execute();
                     }
                 });
             }