Groups tree, unfinished
authorChristos Stathis <chstath@ebs.gr>
Tue, 13 Sep 2011 16:06:27 +0000 (19:06 +0300)
committerChristos Stathis <chstath@ebs.gr>
Tue, 13 Sep 2011 16:06:27 +0000 (19:06 +0300)
13 files changed:
src/gr/grnet/pithos/web/client/PermissionsAddDialog.java
src/gr/grnet/pithos/web/client/Pithos.java
src/gr/grnet/pithos/web/client/commands/AddUserCommand.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/commands/CreateGroupCommand.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/commands/DeleteGroupCommand.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/commands/RemoveUserCommand.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/foldertree/AccountResource.java
src/gr/grnet/pithos/web/client/grouptree/Group.java [moved from src/gr/grnet/pithos/web/client/foldertree/Group.java with 94% similarity]
src/gr/grnet/pithos/web/client/grouptree/GroupContextMenu.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/grouptree/GroupTreeView.java
src/gr/grnet/pithos/web/client/grouptree/GroupTreeViewModel.java
src/gr/grnet/pithos/web/client/grouptree/User.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/grouptree/UserContextMenu.java [new file with mode: 0644]

index c503199..84c2d01 100644 (file)
@@ -35,7 +35,8 @@
 package gr.grnet.pithos.web.client;
 
 import com.google.gwt.user.client.ui.TextBox;
-import gr.grnet.pithos.web.client.foldertree.Group;
+
+import gr.grnet.pithos.web.client.grouptree.Group;
 
 import java.util.List;
 
index c0dc23f..60643d7 100644 (file)
@@ -41,6 +41,7 @@ import gr.grnet.pithos.web.client.foldertree.Folder;
 import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
 import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel;
 import gr.grnet.pithos.web.client.foldertree.Resource;
+import gr.grnet.pithos.web.client.grouptree.Group;
 import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
 import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel;
 import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView;
@@ -131,6 +132,10 @@ public class Pithos implements EntryPoint, ResizeHandler {
         folderTreeView.updateFolder(f, showfiles, callback);
     }
 
+    public void updateGroupNode(Group group) {
+        groupTreeView.updateGroupNode(group);
+    }
+
     public void updateSharedFolder(Folder f, boolean showfiles) {
        mysharedTreeView.updateFolder(f, showfiles);
     }
@@ -250,7 +255,6 @@ public class Pithos implements EntryPoint, ResizeHandler {
     private TagTreeViewModel tagTreeViewModel;
     private TagTreeView tagTreeView;
 
-    protected SingleSelectionModel<String> groupTreeSelectionModel;
     private GroupTreeViewModel groupTreeViewModel;
     private GroupTreeView groupTreeView;
 
@@ -368,17 +372,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         tagTreeViewModel = new TagTreeViewModel(this, tagTreeSelectionModel);
         tagTreeView = new TagTreeView(tagTreeViewModel);
 
-        groupTreeSelectionModel = new SingleSelectionModel<String>();
-        groupTreeSelectionModel.addSelectionChangeHandler(new Handler() {
-            @Override
-            public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
-                if (groupTreeSelectionModel.getSelectedObject() != null) {
-                    deselectOthers(groupTreeSelectionModel);
-                }
-            }
-        });
-        selectionModels.add(groupTreeSelectionModel);
-        groupTreeViewModel = new GroupTreeViewModel(this, groupTreeSelectionModel);
+        groupTreeViewModel = new GroupTreeViewModel(this);
         groupTreeView = new GroupTreeView(groupTreeViewModel);
 
         VerticalPanel trees = new VerticalPanel();
@@ -538,6 +532,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                        break;
                                }
                     folderTreeViewModel.initialize(account);
+                    groupTreeViewModel.initialize();
                 }
             }
 
@@ -928,4 +923,14 @@ public class Pithos implements EntryPoint, ResizeHandler {
        public void updateTrash(boolean showFiles, Command callback) {
                updateFolder(trash, showFiles, callback);
        }
+
+       public void updateGroupsNode() {
+               groupTreeView.updateGroupNode(null);
+       }
+
+       public void addGroup(String groupname) {
+               Group newGroup = new Group(groupname);
+               account.addGroup(newGroup);
+               groupTreeView.updateGroupNode(null);
+       }
 }
diff --git a/src/gr/grnet/pithos/web/client/commands/AddUserCommand.java b/src/gr/grnet/pithos/web/client/commands/AddUserCommand.java
new file mode 100644 (file)
index 0000000..b1be216
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2011 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.commands;
+
+import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.foldertree.Resource;
+import gr.grnet.pithos.web.client.grouptree.Group;
+import gr.grnet.pithos.web.client.rest.PostRequest;
+import gr.grnet.pithos.web.client.rest.RestException;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.PopupPanel;
+
+/**
+ * Display the 'new folder' dialog for creating a new folder.
+ *
+ */
+public class AddUserCommand implements Command {
+       private PopupPanel containerPanel;
+
+    Group group;
+
+    Pithos app;
+
+       /**
+        * @param aContainerPanel
+        */
+       public AddUserCommand(Pithos _app, PopupPanel aContainerPanel, Group _group){
+        app = _app;
+               containerPanel = aContainerPanel;
+           group = _group;
+       }
+
+       @Override
+       public void execute() {
+        if (containerPanel != null)
+                   containerPanel.hide();
+        String username = Window.prompt("Enter username:", "");
+        if (username != null && username.length() > 0) {
+               group.addMember(username);
+               String path = "?update=";
+               PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
+                               
+                               @Override
+                               public void onSuccess(Resource result) {
+                                       app.updateGroupNode(group);
+                               }
+                               
+                               @Override
+                               public void onError(Throwable t) {
+                                       GWT.log("", t);
+                                       if (t instanceof RestException) {
+                                               app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText());
+                                       }
+                                       else
+                                               app.displayError("System error updating group:" + t.getMessage());
+                               }
+                       };
+                       updateGroup.setHeader("X-Auth-Token", app.getToken());
+                       String groupMembers = "";
+                       for (String u : group.getMembers())
+                               groupMembers += (u + ",");
+                       updateGroup.setHeader("X-Account-Group-" + group.getName(), groupMembers);
+                       Scheduler.get().scheduleDeferred(updateGroup);
+        }
+       }
+}
diff --git a/src/gr/grnet/pithos/web/client/commands/CreateGroupCommand.java b/src/gr/grnet/pithos/web/client/commands/CreateGroupCommand.java
new file mode 100644 (file)
index 0000000..e7eec5b
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2011 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.commands;
+
+import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.foldertree.Resource;
+import gr.grnet.pithos.web.client.grouptree.Group;
+import gr.grnet.pithos.web.client.rest.PostRequest;
+import gr.grnet.pithos.web.client.rest.RestException;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.PopupPanel;
+
+/**
+ * Display the 'new folder' dialog for creating a new folder.
+ *
+ */
+public class CreateGroupCommand implements Command {
+       private PopupPanel containerPanel;
+
+    Pithos app;
+
+       /**
+        * @param aContainerPanel
+        */
+       public CreateGroupCommand(Pithos _app, PopupPanel aContainerPanel){
+        app = _app;
+               containerPanel = aContainerPanel;
+       }
+
+       @Override
+       public void execute() {
+        if (containerPanel != null)
+                   containerPanel.hide();
+        String groupname = Window.prompt("Enter group name:", "");
+        if (groupname != null && groupname.length() > 0) {
+               app.addGroup(groupname);
+        }
+       }
+}
diff --git a/src/gr/grnet/pithos/web/client/commands/DeleteGroupCommand.java b/src/gr/grnet/pithos/web/client/commands/DeleteGroupCommand.java
new file mode 100644 (file)
index 0000000..eaa4d3e
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2011 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.commands;
+
+import gr.grnet.pithos.web.client.MessagePanel.Images;
+import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.foldertree.Resource;
+import gr.grnet.pithos.web.client.grouptree.Group;
+import gr.grnet.pithos.web.client.rest.PostRequest;
+import gr.grnet.pithos.web.client.rest.RestException;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.PopupPanel;
+
+
+/**
+ * Delete selected object command
+ *
+ */
+public class DeleteGroupCommand implements Command {
+       private PopupPanel containerPanel;
+
+    private Group group;
+
+    Pithos app;
+    
+       /**
+        * @param _containerPanel
+        */
+       public DeleteGroupCommand(Pithos _app, PopupPanel _containerPanel, Group _group){
+        app = _app;
+               containerPanel = _containerPanel;
+        group = _group;
+       }
+
+       @Override
+       public void execute() {
+        if (containerPanel != null)
+               containerPanel.hide();
+        if (Window.confirm("Are you sure you want to delete group " + group.getName())) {
+               String path = "?update=";
+               PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
+                               
+                               @Override
+                               public void onSuccess(Resource result) {
+                                       app.updateGroupsNode();
+                               }
+                               
+                               @Override
+                               public void onError(Throwable t) {
+                                       GWT.log("", t);
+                                       if (t instanceof RestException) {
+                                               app.displayError("Unable to delete group:" + ((RestException) t).getHttpStatusText());
+                                       }
+                                       else
+                                               app.displayError("System error deleting group:" + t.getMessage());
+                               }
+                       };
+                       updateGroup.setHeader("X-Auth-Token", app.getToken());
+                       updateGroup.setHeader("X-Account-Group-" + group.getName(), "~");
+                       Scheduler.get().scheduleDeferred(updateGroup);
+        }
+       }
+}
diff --git a/src/gr/grnet/pithos/web/client/commands/RemoveUserCommand.java b/src/gr/grnet/pithos/web/client/commands/RemoveUserCommand.java
new file mode 100644 (file)
index 0000000..4c925dd
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2011 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.commands;
+
+import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.foldertree.Resource;
+import gr.grnet.pithos.web.client.grouptree.Group;
+import gr.grnet.pithos.web.client.grouptree.User;
+import gr.grnet.pithos.web.client.rest.PostRequest;
+import gr.grnet.pithos.web.client.rest.RestException;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.PopupPanel;
+
+/**
+ * Display the 'new folder' dialog for creating a new folder.
+ *
+ */
+public class RemoveUserCommand implements Command {
+       private PopupPanel containerPanel;
+
+    User user;
+
+    Pithos app;
+
+       /**
+        * @param aContainerPanel
+        */
+       public RemoveUserCommand(Pithos _app, PopupPanel aContainerPanel, User _user){
+        app = _app;
+               containerPanel = aContainerPanel;
+           user = _user;
+       }
+
+       @Override
+       public void execute() {
+        if (containerPanel != null)
+                   containerPanel.hide();
+       final Group group = user.getGroup();
+       group.removeMember(user.getName());
+       String path = "?update=";
+       PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
+                       
+                       @Override
+                       public void onSuccess(Resource result) {
+                               app.updateGroupNode(group);
+                       }
+                       
+                       @Override
+                       public void onError(Throwable t) {
+                               GWT.log("", t);
+                               if (t instanceof RestException) {
+                                       app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText());
+                               }
+                               else
+                                       app.displayError("System error updating group:" + t.getMessage());
+                       }
+               };
+               updateGroup.setHeader("X-Auth-Token", app.getToken());
+               String groupMembers = "";
+               for (String u : group.getMembers())
+                       groupMembers += (u + ",");
+               updateGroup.setHeader("X-Account-Group-" + group.getName(), groupMembers);
+               Scheduler.get().scheduleDeferred(updateGroup);
+       }
+}
index 6a83fd8..3b33d21 100644 (file)
@@ -36,6 +36,7 @@
 package gr.grnet.pithos.web.client.foldertree;
 
 import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.grouptree.Group;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -230,4 +231,8 @@ public class AccountResource extends Resource {
                        return true;
        return false;
     }
+
+       public void addGroup(Group newGroup) {
+               groups.add(newGroup);
+       }
 }
@@ -33,7 +33,7 @@
  * or implied, of GRNET S.A.
  */
 
-package gr.grnet.pithos.web.client.foldertree;
+package gr.grnet.pithos.web.client.grouptree;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -58,4 +58,8 @@ public class Group {
     public void addMember(String user) {
         members.add(user);
     }
+
+       public void removeMember(String username) {
+               members.remove(username);
+       }
 }
diff --git a/src/gr/grnet/pithos/web/client/grouptree/GroupContextMenu.java b/src/gr/grnet/pithos/web/client/grouptree/GroupContextMenu.java
new file mode 100644 (file)
index 0000000..188770f
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2011 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.grouptree;
+
+import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.commands.AddUserCommand;
+import gr.grnet.pithos.web.client.commands.CreateGroupCommand;
+import gr.grnet.pithos.web.client.commands.DeleteGroupCommand;
+import gr.grnet.pithos.web.client.grouptree.GroupTreeView.Images;
+
+import com.google.gwt.user.client.ui.AbstractImagePrototype;
+import com.google.gwt.user.client.ui.MenuBar;
+import com.google.gwt.user.client.ui.MenuItem;
+import com.google.gwt.user.client.ui.PopupPanel;
+
+/**
+ * The 'Folder Context' menu implementation.
+ */
+public class GroupContextMenu extends PopupPanel {
+
+       /**
+        * The widget's images.
+        */
+       private final GroupTreeView.Images images;
+
+       /**
+        * The widget's constructor.
+        *
+        * @param newImages the image bundle passed on by the parent object
+        */
+       public GroupContextMenu(Pithos app, final Images newImages, Group group) {
+               // The popup's constructor's argument is a boolean specifying that it
+               // auto-close itself when the user clicks outside of it.
+               super(true);
+               setAnimationEnabled(true);
+               images = newImages;
+        MenuBar contextMenu = new MenuBar(true);
+        
+        if (group != null) {
+               MenuItem addUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.user()).getHTML() + "&nbsp;Add User</span>", true, new AddUserCommand(app, this, group));
+               contextMenu.addItem(addUser);
+       
+               MenuItem deleteGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete Group</span>", true, new DeleteGroupCommand(app, this, group));
+               contextMenu.addItem(deleteGroup);
+        }
+        else {
+               MenuItem createGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.group()).getHTML() + "&nbsp;Create Group</span>", true, new CreateGroupCommand(app, this));
+               contextMenu.addItem(createGroup);
+        }
+
+        add(contextMenu);
+       }
+}
index 87c69ed..5a066ab 100644 (file)
@@ -51,21 +51,26 @@ import com.google.gwt.user.client.ui.Tree;
 
 public class GroupTreeView extends Composite {
 
-    public void updateChildren(Folder folder) {
+    public void updateChildren(Group group) {
         TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
-        updateChildren(root, folder);
+        if (group != null)
+               updateChildren(root, group);
+        else {
+               root.setChildOpen(0, false, true);
+               root.setChildOpen(0, true, true);
+        }
     }
 
-    private void updateChildren(TreeNode node, Folder folder) {
+    private void updateChildren(TreeNode node, Group group) {
         for (int i=0; i<node.getChildCount(); i++) {
             if (node.isChildOpen(i)) {
-                if (folder.equals(node.getChildValue(i))) {
+                if (group.equals(node.getChildValue(i))) {
                     node.setChildOpen(i, false, true);
                     node.setChildOpen(i, true, true);
                 }
                 else {
                     TreeNode n = node.setChildOpen(i, true);
-                    updateChildren(n, folder);
+                    updateChildren(n, group);
                 }
             }
         }
@@ -130,13 +135,7 @@ public class GroupTreeView extends Composite {
         initWidget(tree);
     }
 
-
-    public Folder getSelection() {
-//       return model.getSelection();
-       return null;
-    }
-
-    public void updateFolder(Folder folder, boolean showfiles) {
-//        model.updateFolder(folder, showfiles);
+    public void updateGroupNode(Group group) {
+       updateChildren(group);
     }
 }
index 4e2b8f1..9f6163d 100644 (file)
 package gr.grnet.pithos.web.client.grouptree;
 
 import gr.grnet.pithos.web.client.Pithos;
-import gr.grnet.pithos.web.client.SharingUsers;
-import gr.grnet.pithos.web.client.foldertree.AccountResource;
 import gr.grnet.pithos.web.client.foldertree.File;
-import gr.grnet.pithos.web.client.foldertree.Folder;
-import gr.grnet.pithos.web.client.foldertree.Group;
 import gr.grnet.pithos.web.client.grouptree.GroupTreeView.Templates;
-import gr.grnet.pithos.web.client.rest.GetRequest;
-import gr.grnet.pithos.web.client.rest.RestException;
 
 import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
 import com.google.gwt.cell.client.AbstractCell;
 import com.google.gwt.cell.client.Cell;
-import com.google.gwt.cell.client.TextCell;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.event.dom.client.ContextMenuEvent;
-import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
-import com.google.gwt.text.shared.SafeHtmlRenderer;
-import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.ui.AbstractImagePrototype;
 import com.google.gwt.view.client.ListDataProvider;
-import com.google.gwt.view.client.SingleSelectionModel;
 import com.google.gwt.view.client.TreeViewModel;
 
 public class GroupTreeViewModel implements TreeViewModel {
 
     protected Pithos app;
 
-    private Cell<Group> groupCell = new AbstractCell<Group>(ContextMenuEvent.getType().getName()) {
+    private ListDataProvider<String> rootDataProvider = new ListDataProvider<String>();
+    
+    private Cell<String> rootCell = new AbstractCell<String>(ContextMenuEvent.getType().getName()) {
+
+               @Override
+               public void render(@SuppressWarnings("unused") Context context, String value, SafeHtmlBuilder sb) {
+            String html = AbstractImagePrototype.create(GroupTreeView.images.groups()).getHTML();
+            sb.appendHtmlConstant(html);
+            sb.append(Templates.INSTANCE.nameSpan(value));
+               }
+               
+        @Override
+        public void onBrowserEvent(@SuppressWarnings("unused") Cell.Context context, @SuppressWarnings("unused") com.google.gwt.dom.client.Element parent, String s, com.google.gwt.dom.client.NativeEvent event, @SuppressWarnings("unused") com.google.gwt.cell.client.ValueUpdater<String> valueUpdater) {
+            if (event.getType().equals(ContextMenuEvent.getType().getName())) {
+                GroupContextMenu menu = new GroupContextMenu(app, GroupTreeView.images, null);
+                menu.setPopupPosition(event.getClientX(), event.getClientY());
+                menu.show();
+            }
+        }
+       };
+
+       private Cell<Group> groupCell = new AbstractCell<Group>(ContextMenuEvent.getType().getName()) {
 
                @Override
-               public void render(Context context,     Group value, SafeHtmlBuilder sb) {
+               public void render(@SuppressWarnings("unused") Context context, Group value, SafeHtmlBuilder sb) {
             String html = AbstractImagePrototype.create(GroupTreeView.images.group()).getHTML();
             sb.appendHtmlConstant(html);
             sb.append(Templates.INSTANCE.nameSpan(value.getName()));
                }
+               
+        @Override
+        public void onBrowserEvent(@SuppressWarnings("unused") Cell.Context context, @SuppressWarnings("unused") com.google.gwt.dom.client.Element parent, Group group, com.google.gwt.dom.client.NativeEvent event, @SuppressWarnings("unused") com.google.gwt.cell.client.ValueUpdater<Group> valueUpdater) {
+            if (event.getType().equals(ContextMenuEvent.getType().getName())) {
+                GroupContextMenu menu = new GroupContextMenu(app, GroupTreeView.images, group);
+                menu.setPopupPosition(event.getClientX(), event.getClientY());
+                menu.show();
+            }
+        }
        };
 
-    private Cell<String> userCell = new AbstractCell<String>(ContextMenuEvent.getType().getName()) {
+    private Cell<User> userCell = new AbstractCell<User>(ContextMenuEvent.getType().getName()) {
 
                @Override
-               public void render(Context context,     String value, SafeHtmlBuilder sb) {
+               public void render(@SuppressWarnings("unused") Context context, User value, SafeHtmlBuilder sb) {
             String html = AbstractImagePrototype.create(GroupTreeView.images.user()).getHTML();
             sb.appendHtmlConstant(html);
-            sb.append(Templates.INSTANCE.nameSpan(value));
+            sb.append(Templates.INSTANCE.nameSpan(value.getName()));
                }
-       };
 
-       private ListDataProvider<String> rootDataProvider = new ListDataProvider<String>();
+        @Override
+        public void onBrowserEvent(@SuppressWarnings("unused") Cell.Context context, @SuppressWarnings("unused") com.google.gwt.dom.client.Element parent, User user, com.google.gwt.dom.client.NativeEvent event, @SuppressWarnings("unused") com.google.gwt.cell.client.ValueUpdater<User> valueUpdater) {
+            if (event.getType().equals(ContextMenuEvent.getType().getName())) {
+                UserContextMenu menu = new UserContextMenu(app, GroupTreeView.images, user);
+                menu.setPopupPosition(event.getClientX(), event.getClientY());
+                menu.show();
+            }
+        }
+    };
+
     protected ListDataProvider<Group> groupsDataProvider = new ListDataProvider<Group>();
 
-    protected Map<Group, ListDataProvider<String>> userDataProviderMap = new HashMap<Group, ListDataProvider<String>>();
+    protected Map<Group, ListDataProvider<User>> userDataProviderMap = new HashMap<Group, ListDataProvider<User>>();
     
     protected Map<String, Set<File>> sharedFiles = new HashMap<String, Set<File>>();
 
-    private SingleSelectionModel<String> selectionModel;
-
-    public GroupTreeViewModel(Pithos _app, SingleSelectionModel<String> selectionModel) {
+    public GroupTreeViewModel(Pithos _app) {
         app = _app;
-        this.selectionModel = selectionModel;
     }
 
     @Override
     public <T> NodeInfo<?> getNodeInfo(T value) {
         if (value == null) {
-            rootDataProvider.getList().add("Groups");
-            return new DefaultNodeInfo<String>(rootDataProvider, new TextCell(new SafeHtmlRenderer<String>() {
-                @Override
-                public SafeHtml render(String object) {
-                    SafeHtmlBuilder builder = new SafeHtmlBuilder();
-                    render(object, builder);
-                    return builder.toSafeHtml();
-                }
-
-                @Override
-                public void render(String object, SafeHtmlBuilder builder) {
-                    String html = AbstractImagePrototype.create(GroupTreeView.images.groups()).getHTML();
-                    builder.appendHtmlConstant(html);
-                    builder.append(GroupTreeView.Templates.INSTANCE.nameSpan(object));
-                }
-                
-            }),  null, null);
+               rootDataProvider.getList().add("");
+            return new DefaultNodeInfo<String>(rootDataProvider, rootCell,  null, null);
         }
         else if (value instanceof String) {
                groupsDataProvider.getList().addAll(app.getAccount().getGroups());
@@ -132,17 +137,29 @@ public class GroupTreeViewModel implements TreeViewModel {
         else { //Group
                Group g = (Group) value;
                        if (userDataProviderMap.get(g) == null) {
-                               userDataProviderMap.put(g, new ListDataProvider<String>());
+                               userDataProviderMap.put(g, new ListDataProvider<User>());
                        }
-                       final ListDataProvider<String> dataProvider = userDataProviderMap.get(g);
-               return new DefaultNodeInfo(dataProvider, userCell, null, null);
+                       final ListDataProvider<User> dataProvider = userDataProviderMap.get(g);
+                       dataProvider.getList().clear();
+                       for (String u : g.getMembers())
+                               dataProvider.getList().add(new User(u, g));
+               return new DefaultNodeInfo<User>(dataProvider, userCell, null, null);
         }
     }
 
        @Override
     public boolean isLeaf(Object o) {
-        if (o instanceof String && !o.equals("Groups"))
+        if (o instanceof String) {
+                       return ((String) o).length() == 0 || app.getAccount().getGroups().isEmpty();
+        }
+        else if (o instanceof Group)
+               return ((Group) o).getMembers().isEmpty();
+        else
                return true;
-        return false;
     }
+       
+       public void initialize() {
+       rootDataProvider.getList().clear();
+       rootDataProvider.getList().add("Groups");
+       }
 }
diff --git a/src/gr/grnet/pithos/web/client/grouptree/User.java b/src/gr/grnet/pithos/web/client/grouptree/User.java
new file mode 100644 (file)
index 0000000..5d3e853
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2011 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.grouptree;
+
+
+public class User {
+    private String name;
+    
+    private Group group;
+
+    public User(String _name, Group _group) {
+        name = _name;
+        group = _group;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+       public Group getGroup() {
+               return group;
+       }
+}
diff --git a/src/gr/grnet/pithos/web/client/grouptree/UserContextMenu.java b/src/gr/grnet/pithos/web/client/grouptree/UserContextMenu.java
new file mode 100644 (file)
index 0000000..0aa8def
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2011 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.grouptree;
+
+import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.commands.AddUserCommand;
+import gr.grnet.pithos.web.client.commands.CreateGroupCommand;
+import gr.grnet.pithos.web.client.commands.DeleteGroupCommand;
+import gr.grnet.pithos.web.client.commands.RemoveUserCommand;
+import gr.grnet.pithos.web.client.grouptree.GroupTreeView.Images;
+
+import com.google.gwt.user.client.ui.AbstractImagePrototype;
+import com.google.gwt.user.client.ui.MenuBar;
+import com.google.gwt.user.client.ui.MenuItem;
+import com.google.gwt.user.client.ui.PopupPanel;
+
+/**
+ * The 'Folder Context' menu implementation.
+ */
+public class UserContextMenu extends PopupPanel {
+
+       /**
+        * The widget's images.
+        */
+       private final GroupTreeView.Images images;
+
+       /**
+        * The widget's constructor.
+        *
+        * @param newImages the image bundle passed on by the parent object
+        */
+       public UserContextMenu(Pithos app, final Images newImages, User user) {
+               // The popup's constructor's argument is a boolean specifying that it
+               // auto-close itself when the user clicks outside of it.
+               super(true);
+               setAnimationEnabled(true);
+               images = newImages;
+        MenuBar contextMenu = new MenuBar(true);
+        
+        MenuItem removeUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Remove User</span>", true, new RemoveUserCommand(app, this, user));
+        contextMenu.addItem(removeUser);
+
+        add(contextMenu);
+       }
+}