Revision cd1a56d8

b/web_client/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java
35 35
package gr.grnet.pithos.web.client;
36 36

  
37 37
import com.google.gwt.user.client.ui.TextBox;
38
import gr.grnet.pithos.web.client.foldertree.Group;
38

  
39
import gr.grnet.pithos.web.client.grouptree.Group;
39 40

  
40 41
import java.util.List;
41 42

  
b/web_client/src/gr/grnet/pithos/web/client/Pithos.java
41 41
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
42 42
import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel;
43 43
import gr.grnet.pithos.web.client.foldertree.Resource;
44
import gr.grnet.pithos.web.client.grouptree.Group;
44 45
import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
45 46
import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel;
46 47
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView;
......
131 132
        folderTreeView.updateFolder(f, showfiles, callback);
132 133
    }
133 134

  
135
    public void updateGroupNode(Group group) {
136
        groupTreeView.updateGroupNode(group);
137
    }
138

  
134 139
    public void updateSharedFolder(Folder f, boolean showfiles) {
135 140
    	mysharedTreeView.updateFolder(f, showfiles);
136 141
    }
......
250 255
    private TagTreeViewModel tagTreeViewModel;
251 256
    private TagTreeView tagTreeView;
252 257

  
253
    protected SingleSelectionModel<String> groupTreeSelectionModel;
254 258
    private GroupTreeViewModel groupTreeViewModel;
255 259
    private GroupTreeView groupTreeView;
256 260

  
......
368 372
        tagTreeViewModel = new TagTreeViewModel(this, tagTreeSelectionModel);
369 373
        tagTreeView = new TagTreeView(tagTreeViewModel);
370 374

  
371
        groupTreeSelectionModel = new SingleSelectionModel<String>();
372
        groupTreeSelectionModel.addSelectionChangeHandler(new Handler() {
373
            @Override
374
            public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
375
                if (groupTreeSelectionModel.getSelectedObject() != null) {
376
                    deselectOthers(groupTreeSelectionModel);
377
                }
378
            }
379
        });
380
        selectionModels.add(groupTreeSelectionModel);
381
        groupTreeViewModel = new GroupTreeViewModel(this, groupTreeSelectionModel);
375
        groupTreeViewModel = new GroupTreeViewModel(this);
382 376
        groupTreeView = new GroupTreeView(groupTreeViewModel);
383 377

  
384 378
        VerticalPanel trees = new VerticalPanel();
......
538 532
                			break;
539 533
                		}
540 534
                    folderTreeViewModel.initialize(account);
535
                    groupTreeViewModel.initialize();
541 536
                }
542 537
            }
543 538

  
......
928 923
	public void updateTrash(boolean showFiles, Command callback) {
929 924
		updateFolder(trash, showFiles, callback);
930 925
	}
926

  
927
	public void updateGroupsNode() {
928
		groupTreeView.updateGroupNode(null);
929
	}
930

  
931
	public void addGroup(String groupname) {
932
		Group newGroup = new Group(groupname);
933
		account.addGroup(newGroup);
934
		groupTreeView.updateGroupNode(null);
935
	}
931 936
}
b/web_client/src/gr/grnet/pithos/web/client/commands/AddUserCommand.java
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client.commands;
36

  
37
import gr.grnet.pithos.web.client.Pithos;
38
import gr.grnet.pithos.web.client.foldertree.Resource;
39
import gr.grnet.pithos.web.client.grouptree.Group;
40
import gr.grnet.pithos.web.client.rest.PostRequest;
41
import gr.grnet.pithos.web.client.rest.RestException;
42

  
43
import com.google.gwt.core.client.GWT;
44
import com.google.gwt.core.client.Scheduler;
45
import com.google.gwt.user.client.Command;
46
import com.google.gwt.user.client.Window;
47
import com.google.gwt.user.client.ui.PopupPanel;
48

  
49
/**
50
 * Display the 'new folder' dialog for creating a new folder.
51
 *
52
 */
53
public class AddUserCommand implements Command {
54
	private PopupPanel containerPanel;
55

  
56
    Group group;
57

  
58
    Pithos app;
59

  
60
	/**
61
	 * @param aContainerPanel
62
	 */
63
	public AddUserCommand(Pithos _app, PopupPanel aContainerPanel, Group _group){
64
        app = _app;
65
		containerPanel = aContainerPanel;
66
	    group = _group;
67
	}
68

  
69
	@Override
70
	public void execute() {
71
        if (containerPanel != null)
72
		    containerPanel.hide();
73
        String username = Window.prompt("Enter username:", "");
74
        if (username != null && username.length() > 0) {
75
        	group.addMember(username);
76
        	String path = "?update=";
77
        	PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
78
				
79
				@Override
80
				public void onSuccess(Resource result) {
81
					app.updateGroupNode(group);
82
				}
83
				
84
				@Override
85
				public void onError(Throwable t) {
86
					GWT.log("", t);
87
					if (t instanceof RestException) {
88
						app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText());
89
					}
90
					else
91
						app.displayError("System error updating group:" + t.getMessage());
92
				}
93
			};
94
			updateGroup.setHeader("X-Auth-Token", app.getToken());
95
			String groupMembers = "";
96
			for (String u : group.getMembers())
97
				groupMembers += (u + ",");
98
			updateGroup.setHeader("X-Account-Group-" + group.getName(), groupMembers);
99
			Scheduler.get().scheduleDeferred(updateGroup);
100
        }
101
	}
102
}
b/web_client/src/gr/grnet/pithos/web/client/commands/CreateGroupCommand.java
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client.commands;
36

  
37
import gr.grnet.pithos.web.client.Pithos;
38
import gr.grnet.pithos.web.client.foldertree.Resource;
39
import gr.grnet.pithos.web.client.grouptree.Group;
40
import gr.grnet.pithos.web.client.rest.PostRequest;
41
import gr.grnet.pithos.web.client.rest.RestException;
42

  
43
import com.google.gwt.core.client.GWT;
44
import com.google.gwt.core.client.Scheduler;
45
import com.google.gwt.user.client.Command;
46
import com.google.gwt.user.client.Window;
47
import com.google.gwt.user.client.ui.PopupPanel;
48

  
49
/**
50
 * Display the 'new folder' dialog for creating a new folder.
51
 *
52
 */
53
public class CreateGroupCommand implements Command {
54
	private PopupPanel containerPanel;
55

  
56
    Pithos app;
57

  
58
	/**
59
	 * @param aContainerPanel
60
	 */
61
	public CreateGroupCommand(Pithos _app, PopupPanel aContainerPanel){
62
        app = _app;
63
		containerPanel = aContainerPanel;
64
	}
65

  
66
	@Override
67
	public void execute() {
68
        if (containerPanel != null)
69
		    containerPanel.hide();
70
        String groupname = Window.prompt("Enter group name:", "");
71
        if (groupname != null && groupname.length() > 0) {
72
        	app.addGroup(groupname);
73
        }
74
	}
75
}
b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteGroupCommand.java
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client.commands;
36

  
37
import gr.grnet.pithos.web.client.MessagePanel.Images;
38
import gr.grnet.pithos.web.client.Pithos;
39
import gr.grnet.pithos.web.client.foldertree.Resource;
40
import gr.grnet.pithos.web.client.grouptree.Group;
41
import gr.grnet.pithos.web.client.rest.PostRequest;
42
import gr.grnet.pithos.web.client.rest.RestException;
43

  
44
import com.google.gwt.core.client.GWT;
45
import com.google.gwt.core.client.Scheduler;
46
import com.google.gwt.user.client.Command;
47
import com.google.gwt.user.client.Window;
48
import com.google.gwt.user.client.ui.PopupPanel;
49

  
50

  
51
/**
52
 * Delete selected object command
53
 *
54
 */
55
public class DeleteGroupCommand implements Command {
56
	private PopupPanel containerPanel;
57

  
58
    private Group group;
59

  
60
    Pithos app;
61
    
62
	/**
63
	 * @param _containerPanel
64
	 */
65
	public DeleteGroupCommand(Pithos _app, PopupPanel _containerPanel, Group _group){
66
        app = _app;
67
		containerPanel = _containerPanel;
68
        group = _group;
69
	}
70

  
71
	@Override
72
	public void execute() {
73
        if (containerPanel != null)
74
    		containerPanel.hide();
75
        if (Window.confirm("Are you sure you want to delete group " + group.getName())) {
76
        	String path = "?update=";
77
        	PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
78
				
79
				@Override
80
				public void onSuccess(Resource result) {
81
					app.updateGroupsNode();
82
				}
83
				
84
				@Override
85
				public void onError(Throwable t) {
86
					GWT.log("", t);
87
					if (t instanceof RestException) {
88
						app.displayError("Unable to delete group:" + ((RestException) t).getHttpStatusText());
89
					}
90
					else
91
						app.displayError("System error deleting group:" + t.getMessage());
92
				}
93
			};
94
			updateGroup.setHeader("X-Auth-Token", app.getToken());
95
			updateGroup.setHeader("X-Account-Group-" + group.getName(), "~");
96
			Scheduler.get().scheduleDeferred(updateGroup);
97
        }
98
	}
99
}
b/web_client/src/gr/grnet/pithos/web/client/commands/RemoveUserCommand.java
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client.commands;
36

  
37
import gr.grnet.pithos.web.client.Pithos;
38
import gr.grnet.pithos.web.client.foldertree.Resource;
39
import gr.grnet.pithos.web.client.grouptree.Group;
40
import gr.grnet.pithos.web.client.grouptree.User;
41
import gr.grnet.pithos.web.client.rest.PostRequest;
42
import gr.grnet.pithos.web.client.rest.RestException;
43

  
44
import com.google.gwt.core.client.GWT;
45
import com.google.gwt.core.client.Scheduler;
46
import com.google.gwt.user.client.Command;
47
import com.google.gwt.user.client.Window;
48
import com.google.gwt.user.client.ui.PopupPanel;
49

  
50
/**
51
 * Display the 'new folder' dialog for creating a new folder.
52
 *
53
 */
54
public class RemoveUserCommand implements Command {
55
	private PopupPanel containerPanel;
56

  
57
    User user;
58

  
59
    Pithos app;
60

  
61
	/**
62
	 * @param aContainerPanel
63
	 */
64
	public RemoveUserCommand(Pithos _app, PopupPanel aContainerPanel, User _user){
65
        app = _app;
66
		containerPanel = aContainerPanel;
67
	    user = _user;
68
	}
69

  
70
	@Override
71
	public void execute() {
72
        if (containerPanel != null)
73
		    containerPanel.hide();
74
    	final Group group = user.getGroup();
75
    	group.removeMember(user.getName());
76
    	String path = "?update=";
77
    	PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
78
			
79
			@Override
80
			public void onSuccess(Resource result) {
81
				app.updateGroupNode(group);
82
			}
83
			
84
			@Override
85
			public void onError(Throwable t) {
86
				GWT.log("", t);
87
				if (t instanceof RestException) {
88
					app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText());
89
				}
90
				else
91
					app.displayError("System error updating group:" + t.getMessage());
92
			}
93
		};
94
		updateGroup.setHeader("X-Auth-Token", app.getToken());
95
		String groupMembers = "";
96
		for (String u : group.getMembers())
97
			groupMembers += (u + ",");
98
		updateGroup.setHeader("X-Account-Group-" + group.getName(), groupMembers);
99
		Scheduler.get().scheduleDeferred(updateGroup);
100
	}
101
}
b/web_client/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java
36 36
package gr.grnet.pithos.web.client.foldertree;
37 37

  
38 38
import gr.grnet.pithos.web.client.Pithos;
39
import gr.grnet.pithos.web.client.grouptree.Group;
39 40

  
40 41
import java.util.ArrayList;
41 42
import java.util.Date;
......
230 231
    			return true;
231 232
    	return false;
232 233
    }
234

  
235
	public void addGroup(Group newGroup) {
236
		groups.add(newGroup);
237
	}
233 238
}
/dev/null
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35

  
36
package gr.grnet.pithos.web.client.foldertree;
37

  
38
import java.util.ArrayList;
39
import java.util.List;
40

  
41
public class Group {
42
    private String name;
43

  
44
    private List<String> members = new ArrayList<String>();
45

  
46
    public Group(String _name) {
47
        name = _name;
48
    }
49

  
50
    public List<String> getMembers() {
51
        return members;
52
    }
53

  
54
    public String getName() {
55
        return name;
56
    }
57

  
58
    public void addMember(String user) {
59
        members.add(user);
60
    }
61
}
b/web_client/src/gr/grnet/pithos/web/client/grouptree/Group.java
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35

  
36
package gr.grnet.pithos.web.client.grouptree;
37

  
38
import java.util.ArrayList;
39
import java.util.List;
40

  
41
public class Group {
42
    private String name;
43

  
44
    private List<String> members = new ArrayList<String>();
45

  
46
    public Group(String _name) {
47
        name = _name;
48
    }
49

  
50
    public List<String> getMembers() {
51
        return members;
52
    }
53

  
54
    public String getName() {
55
        return name;
56
    }
57

  
58
    public void addMember(String user) {
59
        members.add(user);
60
    }
61

  
62
	public void removeMember(String username) {
63
		members.remove(username);
64
	}
65
}
b/web_client/src/gr/grnet/pithos/web/client/grouptree/GroupContextMenu.java
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client.grouptree;
36

  
37
import gr.grnet.pithos.web.client.Pithos;
38
import gr.grnet.pithos.web.client.commands.AddUserCommand;
39
import gr.grnet.pithos.web.client.commands.CreateGroupCommand;
40
import gr.grnet.pithos.web.client.commands.DeleteGroupCommand;
41
import gr.grnet.pithos.web.client.grouptree.GroupTreeView.Images;
42

  
43
import com.google.gwt.user.client.ui.AbstractImagePrototype;
44
import com.google.gwt.user.client.ui.MenuBar;
45
import com.google.gwt.user.client.ui.MenuItem;
46
import com.google.gwt.user.client.ui.PopupPanel;
47

  
48
/**
49
 * The 'Folder Context' menu implementation.
50
 */
51
public class GroupContextMenu extends PopupPanel {
52

  
53
	/**
54
	 * The widget's images.
55
	 */
56
	private final GroupTreeView.Images images;
57

  
58
	/**
59
	 * The widget's constructor.
60
	 *
61
	 * @param newImages the image bundle passed on by the parent object
62
	 */
63
	public GroupContextMenu(Pithos app, final Images newImages, Group group) {
64
		// The popup's constructor's argument is a boolean specifying that it
65
		// auto-close itself when the user clicks outside of it.
66
		super(true);
67
		setAnimationEnabled(true);
68
		images = newImages;
69
        MenuBar contextMenu = new MenuBar(true);
70
        
71
        if (group != null) {
72
	        MenuItem addUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.user()).getHTML() + "&nbsp;Add User</span>", true, new AddUserCommand(app, this, group));
73
	        contextMenu.addItem(addUser);
74
	
75
	        MenuItem deleteGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete Group</span>", true, new DeleteGroupCommand(app, this, group));
76
	        contextMenu.addItem(deleteGroup);
77
        }
78
        else {
79
	        MenuItem createGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.group()).getHTML() + "&nbsp;Create Group</span>", true, new CreateGroupCommand(app, this));
80
	        contextMenu.addItem(createGroup);
81
        }
82

  
83
        add(contextMenu);
84
	}
85
}
b/web_client/src/gr/grnet/pithos/web/client/grouptree/GroupTreeView.java
51 51

  
52 52
public class GroupTreeView extends Composite {
53 53

  
54
    public void updateChildren(Folder folder) {
54
    public void updateChildren(Group group) {
55 55
        TreeNode root = ((CellTree) getWidget()).getRootTreeNode();
56
        updateChildren(root, folder);
56
        if (group != null)
57
        	updateChildren(root, group);
58
        else {
59
        	root.setChildOpen(0, false, true);
60
        	root.setChildOpen(0, true, true);
61
        }
57 62
    }
58 63

  
59
    private void updateChildren(TreeNode node, Folder folder) {
64
    private void updateChildren(TreeNode node, Group group) {
60 65
        for (int i=0; i<node.getChildCount(); i++) {
61 66
            if (node.isChildOpen(i)) {
62
                if (folder.equals(node.getChildValue(i))) {
67
                if (group.equals(node.getChildValue(i))) {
63 68
                    node.setChildOpen(i, false, true);
64 69
                    node.setChildOpen(i, true, true);
65 70
                }
66 71
                else {
67 72
                    TreeNode n = node.setChildOpen(i, true);
68
                    updateChildren(n, folder);
73
                    updateChildren(n, group);
69 74
                }
70 75
            }
71 76
        }
......
130 135
        initWidget(tree);
131 136
    }
132 137

  
133

  
134
    public Folder getSelection() {
135
//       return model.getSelection();
136
    	return null;
137
    }
138

  
139
    public void updateFolder(Folder folder, boolean showfiles) {
140
//        model.updateFolder(folder, showfiles);
138
    public void updateGroupNode(Group group) {
139
    	updateChildren(group);
141 140
    }
142 141
}
b/web_client/src/gr/grnet/pithos/web/client/grouptree/GroupTreeViewModel.java
36 36
package gr.grnet.pithos.web.client.grouptree;
37 37

  
38 38
import gr.grnet.pithos.web.client.Pithos;
39
import gr.grnet.pithos.web.client.SharingUsers;
40
import gr.grnet.pithos.web.client.foldertree.AccountResource;
41 39
import gr.grnet.pithos.web.client.foldertree.File;
42
import gr.grnet.pithos.web.client.foldertree.Folder;
43
import gr.grnet.pithos.web.client.foldertree.Group;
44 40
import gr.grnet.pithos.web.client.grouptree.GroupTreeView.Templates;
45
import gr.grnet.pithos.web.client.rest.GetRequest;
46
import gr.grnet.pithos.web.client.rest.RestException;
47 41

  
48 42
import java.util.HashMap;
49
import java.util.HashSet;
50
import java.util.Iterator;
51 43
import java.util.Map;
52 44
import java.util.Set;
53 45

  
54 46
import com.google.gwt.cell.client.AbstractCell;
55 47
import com.google.gwt.cell.client.Cell;
56
import com.google.gwt.cell.client.TextCell;
57
import com.google.gwt.core.client.GWT;
58
import com.google.gwt.core.client.Scheduler;
59 48
import com.google.gwt.event.dom.client.ContextMenuEvent;
60
import com.google.gwt.safehtml.shared.SafeHtml;
61 49
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
62
import com.google.gwt.text.shared.SafeHtmlRenderer;
63
import com.google.gwt.user.client.Command;
64 50
import com.google.gwt.user.client.ui.AbstractImagePrototype;
65 51
import com.google.gwt.view.client.ListDataProvider;
66
import com.google.gwt.view.client.SingleSelectionModel;
67 52
import com.google.gwt.view.client.TreeViewModel;
68 53

  
69 54
public class GroupTreeViewModel implements TreeViewModel {
70 55

  
71 56
    protected Pithos app;
72 57

  
73
    private Cell<Group> groupCell = new AbstractCell<Group>(ContextMenuEvent.getType().getName()) {
58
    private ListDataProvider<String> rootDataProvider = new ListDataProvider<String>();
59
    
60
    private Cell<String> rootCell = new AbstractCell<String>(ContextMenuEvent.getType().getName()) {
61

  
62
		@Override
63
		public void render(@SuppressWarnings("unused") Context context,	String value, SafeHtmlBuilder sb) {
64
            String html = AbstractImagePrototype.create(GroupTreeView.images.groups()).getHTML();
65
            sb.appendHtmlConstant(html);
66
            sb.append(Templates.INSTANCE.nameSpan(value));
67
		}
68
		
69
        @Override
70
        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) {
71
            if (event.getType().equals(ContextMenuEvent.getType().getName())) {
72
                GroupContextMenu menu = new GroupContextMenu(app, GroupTreeView.images, null);
73
                menu.setPopupPosition(event.getClientX(), event.getClientY());
74
                menu.show();
75
            }
76
        }
77
	};
78

  
79
	private Cell<Group> groupCell = new AbstractCell<Group>(ContextMenuEvent.getType().getName()) {
74 80

  
75 81
		@Override
76
		public void render(Context context,	Group value, SafeHtmlBuilder sb) {
82
		public void render(@SuppressWarnings("unused") Context context,	Group value, SafeHtmlBuilder sb) {
77 83
            String html = AbstractImagePrototype.create(GroupTreeView.images.group()).getHTML();
78 84
            sb.appendHtmlConstant(html);
79 85
            sb.append(Templates.INSTANCE.nameSpan(value.getName()));
80 86
		}
87
		
88
        @Override
89
        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) {
90
            if (event.getType().equals(ContextMenuEvent.getType().getName())) {
91
                GroupContextMenu menu = new GroupContextMenu(app, GroupTreeView.images, group);
92
                menu.setPopupPosition(event.getClientX(), event.getClientY());
93
                menu.show();
94
            }
95
        }
81 96
	};
82 97

  
83
    private Cell<String> userCell = new AbstractCell<String>(ContextMenuEvent.getType().getName()) {
98
    private Cell<User> userCell = new AbstractCell<User>(ContextMenuEvent.getType().getName()) {
84 99

  
85 100
		@Override
86
		public void render(Context context,	String value, SafeHtmlBuilder sb) {
101
		public void render(@SuppressWarnings("unused") Context context,	User value, SafeHtmlBuilder sb) {
87 102
            String html = AbstractImagePrototype.create(GroupTreeView.images.user()).getHTML();
88 103
            sb.appendHtmlConstant(html);
89
            sb.append(Templates.INSTANCE.nameSpan(value));
104
            sb.append(Templates.INSTANCE.nameSpan(value.getName()));
90 105
		}
91
	};
92 106

  
93
	private ListDataProvider<String> rootDataProvider = new ListDataProvider<String>();
107
        @Override
108
        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) {
109
            if (event.getType().equals(ContextMenuEvent.getType().getName())) {
110
                UserContextMenu menu = new UserContextMenu(app, GroupTreeView.images, user);
111
                menu.setPopupPosition(event.getClientX(), event.getClientY());
112
                menu.show();
113
            }
114
        }
115
    };
116

  
94 117
    protected ListDataProvider<Group> groupsDataProvider = new ListDataProvider<Group>();
95 118

  
96
    protected Map<Group, ListDataProvider<String>> userDataProviderMap = new HashMap<Group, ListDataProvider<String>>();
119
    protected Map<Group, ListDataProvider<User>> userDataProviderMap = new HashMap<Group, ListDataProvider<User>>();
97 120
    
98 121
    protected Map<String, Set<File>> sharedFiles = new HashMap<String, Set<File>>();
99 122

  
100
    private SingleSelectionModel<String> selectionModel;
101

  
102
    public GroupTreeViewModel(Pithos _app, SingleSelectionModel<String> selectionModel) {
123
    public GroupTreeViewModel(Pithos _app) {
103 124
        app = _app;
104
        this.selectionModel = selectionModel;
105 125
    }
106 126

  
107 127
    @Override
108 128
    public <T> NodeInfo<?> getNodeInfo(T value) {
109 129
        if (value == null) {
110
            rootDataProvider.getList().add("Groups");
111
            return new DefaultNodeInfo<String>(rootDataProvider, new TextCell(new SafeHtmlRenderer<String>() {
112
                @Override
113
                public SafeHtml render(String object) {
114
                    SafeHtmlBuilder builder = new SafeHtmlBuilder();
115
                    render(object, builder);
116
                    return builder.toSafeHtml();
117
                }
118

  
119
                @Override
120
                public void render(String object, SafeHtmlBuilder builder) {
121
                    String html = AbstractImagePrototype.create(GroupTreeView.images.groups()).getHTML();
122
                    builder.appendHtmlConstant(html);
123
                    builder.append(GroupTreeView.Templates.INSTANCE.nameSpan(object));
124
                }
125
                
126
            }),  null, null);
130
        	rootDataProvider.getList().add("");
131
            return new DefaultNodeInfo<String>(rootDataProvider, rootCell,  null, null);
127 132
        }
128 133
        else if (value instanceof String) {
129 134
        	groupsDataProvider.getList().addAll(app.getAccount().getGroups());
......
132 137
        else { //Group
133 138
        	Group g = (Group) value;
134 139
			if (userDataProviderMap.get(g) == null) {
135
				userDataProviderMap.put(g, new ListDataProvider<String>());
140
				userDataProviderMap.put(g, new ListDataProvider<User>());
136 141
			}
137
			final ListDataProvider<String> dataProvider = userDataProviderMap.get(g);
138
        	return new DefaultNodeInfo(dataProvider, userCell, null, null);
142
			final ListDataProvider<User> dataProvider = userDataProviderMap.get(g);
143
			dataProvider.getList().clear();
144
			for (String u : g.getMembers())
145
				dataProvider.getList().add(new User(u, g));
146
        	return new DefaultNodeInfo<User>(dataProvider, userCell, null, null);
139 147
        }
140 148
    }
141 149

  
142 150
	@Override
143 151
    public boolean isLeaf(Object o) {
144
        if (o instanceof String && !o.equals("Groups"))
152
        if (o instanceof String) {
153
       		return ((String) o).length() == 0 || app.getAccount().getGroups().isEmpty();
154
        }
155
        else if (o instanceof Group)
156
        	return ((Group) o).getMembers().isEmpty();
157
        else
145 158
        	return true;
146
        return false;
147 159
    }
160
	
161
	public void initialize() {
162
    	rootDataProvider.getList().clear();
163
    	rootDataProvider.getList().add("Groups");
164
	}
148 165
}
b/web_client/src/gr/grnet/pithos/web/client/grouptree/User.java
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35

  
36
package gr.grnet.pithos.web.client.grouptree;
37

  
38

  
39
public class User {
40
    private String name;
41
    
42
    private Group group;
43

  
44
    public User(String _name, Group _group) {
45
        name = _name;
46
        group = _group;
47
    }
48

  
49
    public String getName() {
50
        return name;
51
    }
52

  
53
	public Group getGroup() {
54
		return group;
55
	}
56
}
b/web_client/src/gr/grnet/pithos/web/client/grouptree/UserContextMenu.java
1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client.grouptree;
36

  
37
import gr.grnet.pithos.web.client.Pithos;
38
import gr.grnet.pithos.web.client.commands.AddUserCommand;
39
import gr.grnet.pithos.web.client.commands.CreateGroupCommand;
40
import gr.grnet.pithos.web.client.commands.DeleteGroupCommand;
41
import gr.grnet.pithos.web.client.commands.RemoveUserCommand;
42
import gr.grnet.pithos.web.client.grouptree.GroupTreeView.Images;
43

  
44
import com.google.gwt.user.client.ui.AbstractImagePrototype;
45
import com.google.gwt.user.client.ui.MenuBar;
46
import com.google.gwt.user.client.ui.MenuItem;
47
import com.google.gwt.user.client.ui.PopupPanel;
48

  
49
/**
50
 * The 'Folder Context' menu implementation.
51
 */
52
public class UserContextMenu extends PopupPanel {
53

  
54
	/**
55
	 * The widget's images.
56
	 */
57
	private final GroupTreeView.Images images;
58

  
59
	/**
60
	 * The widget's constructor.
61
	 *
62
	 * @param newImages the image bundle passed on by the parent object
63
	 */
64
	public UserContextMenu(Pithos app, final Images newImages, User user) {
65
		// The popup's constructor's argument is a boolean specifying that it
66
		// auto-close itself when the user clicks outside of it.
67
		super(true);
68
		setAnimationEnabled(true);
69
		images = newImages;
70
        MenuBar contextMenu = new MenuBar(true);
71
        
72
        MenuItem removeUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Remove User</span>", true, new RemoveUserCommand(app, this, user));
73
        contextMenu.addItem(removeUser);
74

  
75
        add(contextMenu);
76
	}
77
}

Also available in: Unified diff