+
+ public void scheduleFolderHeadCommand(final Folder folder, final Command callback) {
+ if (folder == null) {
+ if (callback != null)
+ callback.execute();
+ }
+ else {
+ HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getApiPath(), folder.getOwner(), folder.getUri(), folder) {
+
+ @Override
+ public void onSuccess(Folder _result) {
+ if (callback != null)
+ callback.execute();
+ }
+
+ @Override
+ public void onError(Throwable t) {
+ if (t instanceof RestException) {
+ if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) {
+ final String path = folder.getUri();
+ PutRequest newFolder = new PutRequest(getApiPath(), folder.getOwner(), path) {
+ @Override
+ public void onSuccess(Resource _result) {
+ scheduleFolderHeadCommand(folder, callback);
+ }
+
+ @Override
+ public void onError(Throwable _t) {
+ GWT.log("", _t);
+ setError(_t);
+ if(_t instanceof RestException){
+ displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText());
+ }
+ else
+ displayError("System error creating folder: " + _t.getMessage());
+ }
+
+ @Override
+ protected void onUnauthorized(Response response) {
+ sessionExpired();
+ }
+ };
+ newFolder.setHeader("X-Auth-Token", getToken());
+ newFolder.setHeader("Content-Type", "application/folder");
+ newFolder.setHeader("Accept", "*/*");
+ newFolder.setHeader("Content-Length", "0");
+ Scheduler.get().scheduleDeferred(newFolder);
+ }
+ else
+ displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
+ }
+ else
+ displayError("System error heading folder: " + t.getMessage());
+
+ GWT.log("Error heading folder", t);
+ setError(t);
+ }
+
+ @Override
+ protected void onUnauthorized(Response response) {
+ sessionExpired();
+ }
+ };
+ headFolder.setHeader("X-Auth-Token", getToken());
+ Scheduler.get().scheduleDeferred(headFolder);
+ }
+ }
+
+ public void scheduleFileHeadCommand(File f, final Command callback) {
+ HeadRequest<File> headFile = new HeadRequest<File>(File.class, getApiPath(), f.getOwner(), f.getUri(), f) {
+
+ @Override
+ public void onSuccess(File _result) {
+ if (callback != null)
+ callback.execute();
+ }
+
+ @Override
+ public void onError(Throwable t) {
+ GWT.log("Error heading file", t);
+ setError(t);
+ if (t instanceof RestException)
+ displayError("Error heading file: " + ((RestException) t).getHttpStatusText());
+ else
+ displayError("System error heading file: " + t.getMessage());
+ }
+
+ @Override
+ protected void onUnauthorized(Response response) {
+ sessionExpired();
+ }
+ };
+ 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);
+ }