Fixed various bugs in other shared tree
authorChristos Stathis <chstath@ebs.gr>
Wed, 14 Sep 2011 17:57:54 +0000 (20:57 +0300)
committerChristos Stathis <chstath@ebs.gr>
Wed, 14 Sep 2011 17:57:54 +0000 (20:57 +0300)
src/gr/grnet/pithos/web/client/FileContextMenu.java
src/gr/grnet/pithos/web/client/FileUploadDialog.java
src/gr/grnet/pithos/web/client/FolderContextMenu.java
src/gr/grnet/pithos/web/client/PermissionsList.java
src/gr/grnet/pithos/web/client/Pithos.java
src/gr/grnet/pithos/web/client/mysharedtree/MysharedTreeViewModel.java
src/gr/grnet/pithos/web/client/othersharedtree/OtherSharedTreeViewModel.java

index 675410b..6c52a1c 100644 (file)
@@ -187,38 +187,47 @@ public class FileContextMenu extends PopupPanel {
                images = newImages;
         MenuBar contextMenu = new MenuBar(true);
 
+        Boolean[] permissions = selectedFolder.getPermissions().get(app.getUsername());
+       boolean canWrite = selectedFolder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
+
         if (!selectedFolder.isInTrash()) {
-               if (app.getClipboard().hasFiles()) {
+               if (canWrite && app.getClipboard().hasFiles()) {
                    pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, selectedFolder));
                    contextMenu.addItem(pasteItem);
                }
 
-               MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
-               contextMenu.addItem(upload);
-
-                       cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, selectedFiles));
-            contextMenu.addItem(cutItem);
+               if (canWrite) {
+                       MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
+                       contextMenu.addItem(upload);
+       
+                               cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, selectedFiles));
+                   contextMenu.addItem(cutItem);
+               }
 
                        copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, selectedFiles));
             contextMenu.addItem(copyItem);
 
-                       trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
-            contextMenu.addItem(trashItem);
+            if (canWrite) {
+                               trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
+                   contextMenu.addItem(trashItem);
+            }
         }
         else {
                        MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles));
                        contextMenu.addItem(restore);
         }
 
-               deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
-        contextMenu.addItem(deleteItem);
+        if (canWrite) {
+                       deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
+               contextMenu.addItem(deleteItem);
+        }
 
 //      MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
 //      contextMenu.addItem(refresh);
 //                     sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
 //            contextMenu.addItem(sharingItem);
         if (!selectedFolder.isInTrash()) {
-               if (selectedFiles.size() == 1)
+               if (canWrite && selectedFiles.size() == 1)
                        contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0)));
 
             if (!selectedFiles.isEmpty())
index 3026d4c..e6f8a2f 100644 (file)
@@ -171,7 +171,10 @@ public class FileUploadDialog extends DialogBox {
                                        GWT.log(results, null);
                                        app.displayError(results);
                                }
-                app.updateFolder(folder, true, null);
+                               if (app.getSelectedTree().equals(app.getFolderTreeView()))
+                                       app.updateFolder(folder, true, null);
+                               else
+                                       app.updateOtherSharedFolder(folder, true);
                                hide();
                        }
                });
@@ -206,7 +209,7 @@ public class FileUploadDialog extends DialogBox {
             return;
         }
         final String fname = getFilename(upload.getFilename());
-        String apath = app.getApiPath() + app.getUsername() + folder.getUri() + "/" + fname;
+        String apath = app.getApiPath() + folder.getOwner() + folder.getUri() + "/" + fname;
         form.setAction(apath);
         submit.setEnabled(false);
         upload.setVisible(false);
index e5c5f8e..4743787 100644 (file)
@@ -82,33 +82,40 @@ public class FolderContextMenu extends PopupPanel {
                images = newImages;
         MenuBar contextMenu = new MenuBar(true);
 
-        if (!folder.isInTrash()) {
-               MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(app, this, folder, images));
-               contextMenu.addItem(newFolder);
+        Boolean[] permissions = folder.getPermissions().get(app.getUsername());
+       boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
 
-               if (!folder.isContainer()) {
-                   MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, folder));
-                   contextMenu.addItem(cut);
-               }
+        if (!folder.isInTrash()) {
+               if (canWrite) {
+                       MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(app, this, folder, images));
+                       contextMenu.addItem(newFolder);
+
+                       if (!folder.isContainer()) {
+                           MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, folder));
+                           contextMenu.addItem(cut);
+                       }
+               }
 
                MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, folder));
                contextMenu.addItem(copy);
        
-               if (!app.getClipboard().isEmpty()) {
-                   pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, folder));
-                   contextMenu.addItem(pasteItem);
-               }
-
-                   if (!folder.isContainer()) {
-                       MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, folder));
-                       contextMenu.addItem(moveToTrash);
-               
-                       MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
-                       contextMenu.addItem(delete);
-               
-                       MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, folder, newImages, 0));
-                       contextMenu.addItem(properties);
-                   }
+               if (canWrite) {
+                       if (!app.getClipboard().isEmpty()) {
+                           pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, folder));
+                           contextMenu.addItem(pasteItem);
+                       }
+
+                           if (!folder.isContainer()) {
+                               MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, folder));
+                               contextMenu.addItem(moveToTrash);
+                       
+                               MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
+                               contextMenu.addItem(delete);
+                       
+                               MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, folder, newImages, 0));
+                               contextMenu.addItem(properties);
+                           }
+               }
         }
         else {
                if (!folder.isTrash()) {
index 39aaad2..45ab6c7 100644 (file)
@@ -141,6 +141,7 @@ public class PermissionsList extends Composite {
                     public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
                         Boolean[] ps = permissions.get(user);
                         ps[0] = booleanValueChangeEvent.getValue();
+                        hasChanges = true;
                     }
                 });
                 write.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@@ -148,6 +149,7 @@ public class PermissionsList extends Composite {
                     public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
                         Boolean[] ps = permissions.get(user);
                         ps[1] = booleanValueChangeEvent.getValue();
+                        hasChanges = true;
                     }
                 });
                 PushButton removeButton = new PushButton(AbstractImagePrototype.create(images.delete()).createImage(), new ClickHandler() {
index 779f34b..efeb5a3 100644 (file)
@@ -266,6 +266,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
     @SuppressWarnings("rawtypes")
        private List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
+    
+    Button upload;
 
        @Override
        public void onModuleLoad() {
@@ -295,15 +297,6 @@ public class Pithos implements EntryPoint, ResizeHandler {
         rightside.addStyleName("pithos-rightSide");
         rightside.setSpacing(5);
 
-        PushButton parentButton = new PushButton(new Image(images.asc()), new ClickHandler() {
-            @Override
-            public void onClick(@SuppressWarnings("unused") ClickEvent event) {
-
-            }
-        });
-        parentButton.addStyleName("pithos-parentButton");
-        rightside.add(parentButton);
-
         HTML folderStatistics = new HTML("5 Files (size: 1.1GB)");
         folderStatistics.addStyleName("pithos-folderStatistics");
         rightside.add(folderStatistics);
@@ -318,6 +311,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
             public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
                 if (folderTreeSelectionModel.getSelectedObject() != null) {
                     deselectOthers(folderTreeView, folderTreeSelectionModel);
+                    applyPermissions(folderTreeSelectionModel.getSelectedObject());
                     Folder f = folderTreeSelectionModel.getSelectedObject();
                     updateFolder(f, true, null);
                 }
@@ -337,6 +331,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
             public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
                 if (mysharedTreeSelectionModel.getSelectedObject() != null) {
                     deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
+                    upload.setEnabled(false);
                     updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
                 }
             }
@@ -351,6 +346,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
             public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
                 if (otherSharedTreeSelectionModel.getSelectedObject() != null) {
                     deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
+                    applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
                     updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
                 }
             }
@@ -364,10 +360,10 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
         VerticalPanel trees = new VerticalPanel();
 
-        Button upload = new Button("Upload File", new ClickHandler() {
+        upload = new Button("Upload File", new ClickHandler() {
             @Override
             public void onClick(@SuppressWarnings("unused") ClickEvent event) {
-                new UploadFileCommand(Pithos.this, null, folderTreeView.getSelection()).execute();
+                new UploadFileCommand(Pithos.this, null, getSelection()).execute();
             }
         });
         upload.addStyleName("pithos-uploadButton");
@@ -422,7 +418,24 @@ public class Pithos implements EntryPoint, ResizeHandler {
         });
     }
 
-    @SuppressWarnings({ "rawtypes", "unchecked" })
+    public void applyPermissions(Folder f) {
+       if (f != null) {
+               if (f.isInTrash())
+                       upload.setEnabled(false);
+               else {
+                       Boolean[] perms = f.getPermissions().get(username);
+                       if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) {
+                               upload.setEnabled(true);
+                       }
+                       else
+                               upload.setEnabled(false);
+               }
+       }
+       else
+               upload.setEnabled(false);
+       }
+
+       @SuppressWarnings({ "rawtypes", "unchecked" })
        public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) {
        selectedTree = _selectedTree;
         for (SingleSelectionModel s : selectionModels)
index 679e462..1c0eba1 100644 (file)
@@ -117,6 +117,7 @@ public class MysharedTreeViewModel implements TreeViewModel {
                 public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
                     if (selectionModel2.getSelectedObject() != null) {
                        app.deselectOthers(app.getMySharedTreeView(), selectionModel2);
+                       app.applyPermissions(null);
                        fetchSharedFiles();
                     }
                 }
index 2403696..e97dac8 100644 (file)
@@ -119,6 +119,7 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
                 public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
                     if (selectionModel2.getSelectedObject() != null) {
                        app.deselectOthers(app.getOtherSharedTreeView(), selectionModel2);
+                       app.applyPermissions(null);
                        app.showFiles(new HashSet<File>());
                     }
                 }
@@ -150,6 +151,7 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
                        public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
                            if (selectionModel3.getSelectedObject() != null) {
                                app.deselectOthers(app.getOtherSharedTreeView(), selectionModel3);
+                               app.applyPermissions(null);
                                String username = selectionModel3.getSelectedObject();
                                fetchSharedFiles(username, userDataProviderMap.get(username));
                            }