Changed autorefresh to start at the end of initialization and check with if-modified...
[pithos-web-client] / src / gr / grnet / pithos / web / client / Pithos.java
index 362128e..fcf9fb2 100644 (file)
@@ -55,13 +55,17 @@ import gr.grnet.pithos.web.client.rest.PutRequest;
 import gr.grnet.pithos.web.client.rest.RestException;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.http.HttpStatus;
+
 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;
@@ -75,13 +79,19 @@ import com.google.gwt.http.client.RequestCallback;
 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.DateTimeFormat;
+import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
 import com.google.gwt.i18n.client.Dictionary;
-import com.google.gwt.i18n.client.NumberFormat;
+import com.google.gwt.i18n.client.TimeZone;
+import com.google.gwt.i18n.client.TimeZoneInfo;
+import com.google.gwt.i18n.client.constants.TimeZoneConstants;
 import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONParser;
 import com.google.gwt.json.client.JSONString;
 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.ImageResource.ImageOptions;
 import com.google.gwt.user.client.Command;
@@ -92,11 +102,13 @@ import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.AbstractImagePrototype;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.FlowPanel;
 import com.google.gwt.user.client.ui.HTML;
 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;
@@ -114,6 +126,35 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
        public static final Configuration config = GWT.create(Configuration.class);
        
+       public interface Style extends CssResource {
+               String commandAnchor();
+               
+               String statistics();
+               
+               @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);
+       
        /**
         * Instantiate an application-level image bundle. This object will provide
         * programmatic access to all the images needed by widgets.
@@ -144,12 +185,16 @@ public class Pithos implements EntryPoint, ResizeHandler {
        mysharedTreeView.updateRoot();
     }
     
-    public void updateSharedFolder(Folder f, boolean showfiles) {
-       mysharedTreeView.updateFolder(f, showfiles);
+    public void updateSharedFolder(Folder f, boolean showfiles, Command callback) {
+       mysharedTreeView.updateFolder(f, showfiles, callback);
     }
     
-    public void updateOtherSharedFolder(Folder f, boolean showfiles) {
-       otherSharedTreeView.updateFolder(f, showfiles);
+    public void updateSharedFolder(Folder f, boolean showfiles) {
+       updateSharedFolder(f, showfiles, null);
+    }
+
+    public void updateOtherSharedFolder(Folder f, boolean showfiles, Command callback) {
+       otherSharedTreeView.updateFolder(f, showfiles, callback);
     }
 
     public MysharedTreeView getMySharedTreeView() {
@@ -190,7 +235,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.
@@ -238,7 +283,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
     OtherSharedTreeView otherSharedTreeView = null;
 
     GroupTreeViewModel groupTreeViewModel;
-    private GroupTreeView groupTreeView;
+    GroupTreeView groupTreeView;
 
     TreeView selectedTree;
     protected AccountResource account;
@@ -249,20 +294,18 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
     @SuppressWarnings("rawtypes") List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
     
-    Button upload;
-    
-    private HTML usedBytes;
-    
-    private HTML totalBytes;
-    
-    private HTML usedPercent;
+    public Button upload;
     
     private HTML numOfFiles;
     
     private Toolbar toolbar;
     
-    private FileUploadDialog fileUploadDialog;
-    
+    private FileUploadDialog fileUploadDialog = new FileUploadDialog(this);
+
+       UploadAlert uploadAlert;
+       
+       Date lastModified;
+
        @Override
        public void onModuleLoad() {
                if (parseUserCredentials())
@@ -270,6 +313,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
        }
 
     private void initialize() {
+       lastModified = new Date(); //Initialize if-modified-since value with now.
+       resources.pithosCss().ensureInjected();
        boolean bareContent = Window.Location.getParameter("noframe") != null;
        String contentWidth = bareContent ? "100%" : "75%";
 
@@ -327,7 +372,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%");
 
@@ -362,43 +407,19 @@ public class Pithos implements EntryPoint, ResizeHandler {
         folderTreeView = new FolderTreeView(folderTreeViewModel);
         treeViews.add(folderTreeView);
         
-        fileList = new FileList(this, images, folderTreeView);
+        fileList = new FileList(this, images);
         inner.add(fileList);
 
-        groupTreeViewModel = new GroupTreeViewModel(this);
-        groupTreeView = new GroupTreeView(groupTreeViewModel);
-        treeViews.add(groupTreeView);
-        
         trees = new VerticalPanel();
         trees.setWidth("100%");
-
         
-        HorizontalPanel treeHeader = new HorizontalPanel();
-        treeHeader.addStyleName("pithos-treeHeader");
-        treeHeader.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
-        treeHeader.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
-        HorizontalPanel statistics = new HorizontalPanel();
-        statistics.addStyleName("pithos-statistics");
-        statistics.add(new HTML("Used:&nbsp;"));
-        usedBytes = new HTML();
-        statistics.add(usedBytes);
-        statistics.add(new HTML("&nbsp;of&nbsp;"));
-        totalBytes = new HTML();
-        statistics.add(totalBytes);
-        statistics.add(new HTML("&nbsp;("));
-        usedPercent = new HTML();
-        statistics.add(usedPercent);
-        statistics.add(new HTML(")"));
-        treeHeader.add(statistics);
-        treeHeader.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_LEFT);
-        trees.add(treeHeader);
-
-        trees.add(folderTreeView);
-        trees.add(groupTreeView);
         // Add the left and right panels to the split panel.
         splitPanel.setLeftWidget(trees);
-        splitPanel.setRightWidget(inner);
-        splitPanel.setSplitPosition("35%");
+        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");
         splitPanel.setWidth(contentWidth);
@@ -425,14 +446,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() {
@@ -450,6 +474,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                                        trash = f;
                                                        break;
                                                }
+                                   trees.add(folderTreeView);
                                    folderTreeViewModel.initialize(account, new Command() {
                                                                
                                                                @Override
@@ -457,57 +482,120 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                                    createMySharedTree();
                                                                }
                                                        });
-                                   groupTreeViewModel.initialize();
-                                   showStatistics();
+
+                                   HorizontalPanel separator = new HorizontalPanel();
+                                   separator.addStyleName("pithos-statisticsSeparator");
+                                   separator.add(new HTML(""));
+                                   trees.add(separator);
+
+                                   groupTreeViewModel = new GroupTreeViewModel(Pithos.this);
+                                   groupTreeView = new GroupTreeView(groupTreeViewModel);
+                                   treeViews.add(groupTreeView);
+                                   trees.add(groupTreeView);
+                                   folderTreeView.showStatistics(account);
                                }
                                        }
                                });
             }
         });
-        
-        Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
+    }
+    
+    public void scheduleResfresh() {
+               Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
                        
                        @Override
                        public boolean execute() {
-                               Folder f = getSelection();
-                               if (f != null) {
-                                       if (getSelectedTree().equals(folderTreeView))
-                                               updateFolder(f, true, null, false);
-                                       else if (getSelectedTree().equals(mysharedTreeView))
-                                               updateSharedFolder(f, true);
-                               }
-                               return true;
+                               final Folder f = getSelection();
+                               if (f == null)
+                                       return true;
+                               
+                       HeadRequest<Folder> head = new HeadRequest<Folder>(Folder.class, getApiPath(), getUsername(), "/" + f.getContainer()) {
+
+                                       @Override
+                                       public void onSuccess(Folder _result) {
+                                               lastModified = new Date();
+                                               if (getSelectedTree().equals(folderTreeView))
+                                                       updateFolder(f, true, new Command() {
+       
+                                                               @Override
+                                                               public void execute() {
+                                                                       scheduleResfresh();
+                                                               }
+                                                               
+                                                       }, false);
+                                               else if (getSelectedTree().equals(mysharedTreeView))
+                                                       updateSharedFolder(f, true, new Command() {
+       
+                                                               @Override
+                                                               public void execute() {
+                                                                       scheduleResfresh();
+                                                               }
+                                                       });
+                                       }
+
+                                       @Override
+                                       public void onError(Throwable t) {
+                                               if (t instanceof RestException && ((RestException) t).getHttpStatusCode() == HttpStatus.SC_NOT_MODIFIED)
+                                                       scheduleResfresh();
+                                               else if (retries >= MAX_RETRIES) {
+                                       GWT.log("Error heading folder", t);
+                                                       setError(t);
+                                       if (t instanceof RestException)
+                                           displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
+                                       else
+                                           displayError("System error heading folder: " + t.getMessage());
+                               }
+                               else {//retry
+                                       GWT.log("Retry " + retries);
+                                       Scheduler.get().scheduleDeferred(this);
+                               }
+                                       }
+
+                                       @Override
+                                       protected void onUnauthorized(Response response) {
+                                               if (retries >= MAX_RETRIES)
+                                                       sessionExpired();
+                               else //retry
+                                       Scheduler.get().scheduleDeferred(this);
+                                       }
+                               };
+                               head.setHeader("X-Auth-Token", getToken());
+                               head.setHeader("If-Modified-Since", DateTimeFormat.getFormat("EEE, dd MMM yyyy HH:mm:ss").format(lastModified, TimeZone.createTimeZone(0)) + " GMT");
+                               Scheduler.get().scheduleDeferred(head);
+                               
+                               return false;
                        }
                }, 3000);
     }
 
     public void applyPermissions(Folder f) {
        if (f != null) {
-               if (f.isInTrash())
+               if (f.isInTrash()) {
                        upload.setEnabled(false);
+                       disableUploadArea();
+               }
                else {
                        Boolean[] perms = f.getPermissions().get(username);
                        if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) {
                                upload.setEnabled(true);
+                               enableUploadArea();
                        }
-                       else
+                       else {
                                upload.setEnabled(false);
+                               disableUploadArea();
+                       }
                }
        }
-       else
+       else {
                upload.setEnabled(false);
+               disableUploadArea();
+       }
        }
 
        @SuppressWarnings({ "rawtypes", "unchecked" })
        public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) {
        selectedTree = _selectedTree;
        
-       for (Composite c : treeViews)
-               if (c.equals(selectedTree))
-                       c.addStyleName("cellTreeWidget-selectedTree");
-               else
-                       c.removeStyleName("cellTreeWidget-selectedTree");
-       
         for (SingleSelectionModel s : selectionModels)
             if (!s.equals(model) && s.getSelectedObject() != null)
                 s.setSelected(s.getSelectedObject(), false);
@@ -562,7 +650,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) {
@@ -597,7 +685,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
                        @Override
                        public void onSuccess(AccountResource _result) {
-                               showStatistics();
+                               folderTreeView.showStatistics(account);
                        }
 
                        @Override
@@ -619,13 +707,6 @@ public class Pithos implements EntryPoint, ResizeHandler {
                Scheduler.get().scheduleDeferred(headAccount);
        }
 
-       protected void showStatistics() {
-       usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
-       totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
-       NumberFormat nf = NumberFormat.getPercentFormat();
-       usedPercent.setHTML(nf.format(account.getUsedPercentage()));
-       }
-
        protected void createHomeContainer(final AccountResource _account, final Command callback) {
         String path = "/" + Pithos.HOME_CONTAINER;
         PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
@@ -701,13 +782,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();
@@ -721,6 +808,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         */
        public void displayError(String msg) {
                messagePanel.displayError(msg);
+               onWindowResized(Window.getClientHeight());
        }
 
        /**
@@ -730,6 +818,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         */
        public void displayWarning(String msg) {
                messagePanel.displayWarning(msg);
+               onWindowResized(Window.getClientHeight());
        }
 
        /**
@@ -739,6 +828,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         */
        public void displayInformation(String msg) {
                messagePanel.displayInformation(msg);
+               onWindowResized(Window.getClientHeight());
        }
 
        /**
@@ -777,12 +867,14 @@ public class Pithos implements EntryPoint, ResizeHandler {
        }
 
        public static native void preventIESelection() /*-{
-               $doc.body.onselectstart = function () { return false; };
+               $doc.body.onselectstart = function() {
+                       return false;
+               };
        }-*/;
 
        public static native void enableIESelection() /*-{
                if ($doc.body.onselectstart != null)
-               $doc.body.onselectstart = null;
+                       $doc.body.onselectstart = null;
        }-*/;
 
        /**
@@ -853,6 +945,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                         GWT.log("", t);
                                                setError(t);
                         displayError("System error unable to delete folder: " + t.getMessage());
+                        deleteObject(folder, i + 1, array, callback);
                     }
 
                                @Override
@@ -866,7 +959,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
             else if (o != null) {
                 String subdir = o.get("subdir").isString().stringValue();
                 subdir = subdir.substring(0, subdir.length() - 1);
-                String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(subdir) + "&t=" + System.currentTimeMillis();
+                String path = getApiPath() + folder.getOwner() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(subdir) + "&t=" + System.currentTimeMillis();
                 RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
                 builder.setHeader("X-Auth-Token", getToken());
                 try {
@@ -898,6 +991,18 @@ public class Pithos implements EntryPoint, ResizeHandler {
             }
         }
         else {
+               if (folder.isContainer()) {
+                       updateFolder(folder, true, new Command() {
+                                       
+                                       @Override
+                                       public void execute() {
+                                               updateStatistics();
+                                               if (callback != null)
+                                                       callback.execute();
+                                       }
+                               }, false);
+                       return;
+               }
             String path = folder.getUri();
             DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), URL.encode(path)) {
                 @Override
@@ -1074,10 +1179,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
                groupTreeView.updateGroupNode(null);
        }
 
-       public void addGroup(String groupname) {
+       public Group addGroup(String groupname) {
                Group newGroup = new Group(groupname);
                account.addGroup(newGroup);
                groupTreeView.updateGroupNode(null);
+               return newGroup;
        }
 
        public void removeGroup(Group group) {
@@ -1094,7 +1200,9 @@ public class Pithos implements EntryPoint, ResizeHandler {
        }
 
        public Folder getSelection() {
-               return selectedTree.getSelection();
+               if (selectedTree != null)
+                       return selectedTree.getSelection();
+               return null;
        }
 
        public void showFolderStatistics(int folderFileCount) {
@@ -1121,6 +1229,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                        if (mysharedTreeSelectionModel.getSelectedObject() != null) {
                            deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
                            upload.setEnabled(false);
+                           disableUploadArea();
                            updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
                                        showRelevantToolbarButtons();
                        }
@@ -1153,9 +1262,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
                    public void onSelectionChange(SelectionChangeEvent event) {
                        if (otherSharedTreeSelectionModel.getSelectedObject() != null) {
                            deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
-                           otherSharedTreeView.addStyleName("cellTreeWidget-selectedTree");
                            applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
-                           updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
+                           updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true, null);
                                        showRelevantToolbarButtons();
                        }
                                else {
@@ -1173,8 +1281,9 @@ public class Pithos implements EntryPoint, ResizeHandler {
                        @Override
                        public void execute() {
                            otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
-                               trees.insert(otherSharedTreeView, 3);
+                               trees.insert(otherSharedTreeView, 1);
                                treeViews.add(otherSharedTreeView);
+                               scheduleResfresh();
                        }
                });
        }
@@ -1307,4 +1416,106 @@ public class Pithos implements EntryPoint, ResizeHandler {
                headFile.setHeader("X-Auth-Token", getToken());
                Scheduler.get().scheduleDeferred(headFile);
        }
+
+       public boolean isMySharedSelected() {
+               return getSelectedTree().equals(getMySharedTreeView());
+       }
+       
+       private Folder getUploadFolder() {
+               if (folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
+                       return getSelection();
+               }
+               return null;
+       }
+       
+       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()))
+                               updateFolder(f, true, new Command() {
+                               
+                                       @Override
+                                       public void execute() {
+                                               updateStatistics();
+                                               if (urls != null)
+                                                       selectUploadedFiles(urls);
+                                       }
+                               }, false);
+                       else
+                               updateOtherSharedFolder(f, true, null);
+               }
+       }
+
+       public native void disableUploadArea() /*-{
+               var uploader = $wnd.$("#uploader").pluploadQueue();
+               var dropElm = $wnd.document.getElementById('rightPanel');
+               $wnd.plupload.removeAllEvents(dropElm, uploader.id);
+       }-*/;
+
+       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);
+       }
+       
+       public void deleteAndCreateTrash() {
+               DeleteRequest delete = new DeleteRequest(getApiPath(), getUsername(), "/trash") {
+                       
+                       @Override
+                       protected void onUnauthorized(Response response) {
+                               sessionExpired();
+                       }
+                       
+                       @Override
+                       public void onSuccess(Resource result) {
+                               createTrashContainer(null);
+                       }
+                       
+                       @Override
+                       public void onError(Throwable t) {
+                GWT.log("Error deleting trash", t);
+                               setError(t);
+                if (t instanceof RestException)
+                    displayError("Error deleting trash: " + ((RestException) t).getHttpStatusText());
+                else
+                    displayError("System error deleting trash: " + t.getMessage());
+                       }
+               };
+               delete.setHeader("X-Auth-Token", getToken());
+               Scheduler.get().scheduleDeferred(delete);
+       }
 }