Revision fbff60ff

b/web_client/src/gr/grnet/pithos/web/client/CellTreeViewModel.java
322 322
        	  
323 323
        	  DnDFolderPopupMenu popup ;
324 324
        	  if(context.getDraggableData() instanceof FileResource){
325
        		  if(context.getDroppableData() instanceof RestResourceWrapper)
326
        			  popup = new DnDFolderPopupMenu(images, ((RestResourceWrapper) context.getDroppableData()).getResource(), Arrays.asList(context.getDraggableData()));
327
        		  else
328
        			  popup = new DnDFolderPopupMenu(images, null, Arrays.asList(context.getDraggableData()));
325
//        		  if(context.getDroppableData() instanceof RestResourceWrapper)
326
//        			  popup = new DnDFolderPopupMenu(images, ((RestResourceWrapper) context.getDroppableData()).getResource(), Arrays.asList(context.getDraggableData()));
327
 //       		  else
328
 //       			  popup = new DnDFolderPopupMenu(images, null, Arrays.asList(context.getDraggableData()));
329 329
        	  }
330 330
        	  
331 331
        	  else{
332
        		  if(context.getDroppableData() instanceof RestResourceWrapper)
333
        			  popup = new DnDFolderPopupMenu(images, ((RestResourceWrapper) context.getDroppableData()).getResource(), context.getDraggableData());
334
        		  else
335
        			  popup = new DnDFolderPopupMenu(images, null, context.getDraggableData());
332
//        		  if(context.getDroppableData() instanceof RestResourceWrapper)
333
//        			  popup = new DnDFolderPopupMenu(images, ((RestResourceWrapper) context.getDroppableData()).getResource(), context.getDraggableData());
334
//        		  else
335
//        			  popup = new DnDFolderPopupMenu(images, null, context.getDraggableData());
336 336
        	  }
337 337
        	  
338 338
        	  int left = context.getDroppable().getAbsoluteLeft() + 40;
339 339
              int top = context.getDroppable().getAbsoluteTop() + 20;
340
              popup.setPopupPosition(left, top);
340
//              popup.setPopupPosition(left, top);
341 341
        	 
342
        	  popup.show();
342
 //       	  popup.show();
343 343
          }
344 344
        });
345 345
	}
b/web_client/src/gr/grnet/pithos/web/client/DnDFolderPopupMenu.java
3 3
 */
4 4
package gr.grnet.pithos.web.client;
5 5

  
6
import gr.grnet.pithos.web.client.foldertree.File;
7
import gr.grnet.pithos.web.client.foldertree.Folder;
6 8
import gr.grnet.pithos.web.client.rest.MultiplePostCommand;
7 9
import gr.grnet.pithos.web.client.rest.PostCommand;
8 10
import gr.grnet.pithos.web.client.rest.RestException;
......
23 25

  
24 26
public class DnDFolderPopupMenu extends PopupPanel {
25 27

  
26
        public DnDFolderPopupMenu(final CellTreeView.Images newImages, final FolderResource target, final Object toCopy) {
27
                // The popup's constructor's argument is a boolean specifying that it
28
                // auto-close itself when the user clicks outside of it.
29
                super(true);
30
                setAnimationEnabled(true);
31
                // A dummy command that we will execute from unimplemented leaves.
32
                final Command cancelCmd = new Command() {
33

  
34
                        @Override
35
                        public void execute() {
36
                                hide();
37
                        }
38
                };
39

  
40
                final MenuBar contextMenu = new MenuBar(true);
41
                final CellTreeView folders = GSS.get().getTreeView();
42

  
43
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Move</span>", true, new Command() {
44

  
45
                                @Override
46
                                public void execute() {
47
                                        if (toCopy instanceof RestResourceWrapper){
48
                                                moveFolder(target, ((RestResourceWrapper) toCopy).getResource());
49
                                        }
50
                                        else if(toCopy instanceof List){
51
                                        	List<FileResource> files = GSS.get().getFileList().getSelectedFiles();
52
                                                moveFiles(target, files);
53
                                        }
54
                                        hide();
55
                                }
56

  
57
                        }).setVisible(target != null);
58

  
59
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new Command() {
60

  
61
                        @Override
62
                        public void execute() {
63
                                if (toCopy instanceof RestResourceWrapper)
64
                                        copyFolder(target, ((RestResourceWrapper) toCopy).getResource());
65
                                else if(toCopy instanceof List){
66
                                	List<FileResource> files = GSS.get().getFileList().getSelectedFiles();
67
                                    copyFiles(target, files);
68
                                }
69
                                hide();
70
                        }
71

  
72
                }).setVisible(target != null);
73

  
74
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.trash()).getHTML() + "&nbsp;Delete (Trash)</span>", true, new Command() {
75

  
76
                        @Override
77
                        public void execute() {
78
                        	GWT.log("EXECUTE TRASH:"+toCopy.getClass().getName());
79
                                if (toCopy instanceof RestResourceWrapper){
80
                                        trashFolder(((RestResourceWrapper) toCopy).getResource());
81
                                }
82
                                else if(toCopy instanceof List){
83
                                	List<FileResource> files = GSS.get().getFileList().getSelectedFiles();
84
                                    trashFiles(files);
85
                                }
86
                                hide();
87
                        }
88

  
89
                }).setVisible(target == null);
90
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Cancel</span>", true, cancelCmd);
91

  
92
                add(contextMenu);
93

  
94
        }
95

  
96
        private void copyFolder(final FolderResource target, FolderResource toCopy) {
97
                String atarget = target.getUri();
98
                atarget = atarget.endsWith("/") ? atarget : atarget + '/';
99
                atarget = atarget + toCopy.getName();
100
                PostCommand cf = new PostCommand(toCopy.getUri() + "?copy=" + atarget, "", 200) {
101

  
102
                        @Override
103
                        public void onComplete() {
104
                        		GSS.get().getTreeView().updateNodeChildren(new RestResourceWrapper(target));
105
								GSS.get().getStatusPanel().updateStats();
106
                        }
107

  
108
                        @Override
109
                        public void onError(Throwable t) {
110
                                GWT.log("", t);
111
                                if (t instanceof RestException) {
112
                                        int statusCode = ((RestException) t).getHttpStatusCode();
113
                                        if (statusCode == 405)
114
                                                GSS.get().displayError("You don't have the necessary permissions");
115

  
116
                                        else if (statusCode == 409)
117
                                                GSS.get().displayError("A folder with the same name already exists");
118
                                        else if (statusCode == 413)
119
                                                GSS.get().displayError("Your quota has been exceeded");
120
                                        else
121
                                                GSS.get().displayError("Unable to copy folder:" + ((RestException)t).getHttpStatusText());
122
                                } else
123
                                        GSS.get().displayError("System error copying folder:" + t.getMessage());
124
                        }
125
                };
126
                DeferredCommand.addCommand(cf);
127
        }
128

  
129
        private void moveFolder(final FolderResource target, final FolderResource toCopy) {
130
                String atarget = target.getUri();
131
                atarget = atarget.endsWith("/") ? atarget : atarget + '/';
132
                atarget = atarget + toCopy.getName();
133

  
134
                PostCommand cf = new PostCommand(toCopy.getUri() + "?move=" + atarget, "", 200) {
135

  
136
                        @Override
137
                        public void onComplete() {
138
                        	GWT.log("[MOVE]"+target.getUri()+"   "+ toCopy.getParentURI());
139
                        	GSS.get().getTreeView().updateNodeChildren(new RestResourceWrapper(target));
140
							GSS.get().getTreeView().updateNodeChildrenForRemove(toCopy.getParentURI());
141
							GSS.get().getStatusPanel().updateStats();
142
                        }
143

  
144
                        @Override
145
                        public void onError(Throwable t) {
146
                                GWT.log("", t);
147
                                if (t instanceof RestException) {
148
                                        int statusCode = ((RestException) t).getHttpStatusCode();
149
                                        if (statusCode == 405)
150
                                                GSS.get().displayError("You don't have the necessary permissions");
151

  
152
                                        else if (statusCode == 409)
153
                                                GSS.get().displayError("A folder with the same name already exists");
154
                                        else if (statusCode == 413)
155
                                                GSS.get().displayError("Your quota has been exceeded");
156
                                        else
157
                                                GSS.get().displayError("Unable to copy folder:" + ((RestException)t).getHttpStatusText());
158
                                } else
159
                                        GSS.get().displayError("System error copying folder:" + t.getMessage());
160
                        }
161
                };
162
                DeferredCommand.addCommand(cf);
163
        }
164

  
165
        private void copyFiles(final FolderResource ftarget, List<FileResource> files) {
166
                List<String> fileIds = new ArrayList<String>();
167
                String target = ftarget.getUri();
168
                target = target.endsWith("/") ? target : target + '/';
169
                for (FileResource fileResource : files) {
170
                        String fileTarget = target + URL.encodeComponent(fileResource.getName());
171
                        fileIds.add(fileResource.getUri() + "?copy=" + fileTarget);
28
    public DnDFolderPopupMenu(final CellTreeView.Images newImages, final Folder target, final Object toCopy) {
29
        // The popup's constructor's argument is a boolean specifying that it
30
        // auto-close itself when the user clicks outside of it.
31
        super(true);
32
        setAnimationEnabled(true);
33
        // A dummy command that we will execute from unimplemented leaves.
34
        final Command cancelCmd = new Command() {
35

  
36
            @Override
37
            public void execute() {
38
                hide();
39
            }
40
        };
41

  
42
        final MenuBar contextMenu = new MenuBar(true);
43
        final CellTreeView folders = GSS.get().getTreeView();
44

  
45
        contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Move</span>", true, new Command() {
46

  
47
            @Override
48
            public void execute() {
49
                if (toCopy instanceof Folder) {
50
                    moveFolder(target, (Folder) toCopy);
172 51
                }
173
                int index = 0;
174
                executeCopyOrMoveFiles(index, fileIds);
175

  
176
        }
177

  
178
        private void moveFiles(final FolderResource ftarget, List<FileResource> files) {
179
                List<String> fileIds = new ArrayList<String>();
180
                String target = ftarget.getUri();
181
                target = target.endsWith("/") ? target : target + '/';
182
                for (FileResource fileResource : files) {
183
                        String fileTarget = target + URL.encodeComponent(fileResource.getName());
184
                        fileIds.add(fileResource.getUri() + "?move=" + fileTarget);
52
                else if (toCopy instanceof List) {
53
                    List<File> files = GSS.get().getFileList().getSelectedFiles();
54
                    moveFiles(target, files);
185 55
                }
186
                int index = 0;
187
                executeCopyOrMoveFiles(index, fileIds);
188

  
189
        }
190

  
191
        private void trashFolder(final FolderResource folder){
192
                PostCommand tot = new PostCommand(folder.getUri()+"?trash=","",200){
193

  
194
                        @Override
195
                        public void onComplete() {
196
                        	GSS.get().getTreeView().updateNodeChildrenForRemove(folder.getParentURI());
197
                        	GSS.get().getTreeView().updateTrashNode();
198
                                /*for(TreeItem item : items)
199
                                        GSS.get().getFolders().updateFolder((DnDTreeItem) item);
200
                                GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
201
                               
202
                                GSS.get().showFileList(true);
203
                                */
204
                        }
205

  
206
                        @Override
207
                        public void onError(Throwable t) {
208
                                GWT.log("", t);
209
                                if(t instanceof RestException){
210
                                        int statusCode = ((RestException)t).getHttpStatusCode();
211
                                        if(statusCode == 405)
212
                                                GSS.get().displayError("You don't have the necessary permissions");
213
                                        else if(statusCode == 404)
214
                                                GSS.get().displayError("Folder does not exist");
215
                                        else
216
                                                GSS.get().displayError("Unable to trash folder:"+((RestException)t).getHttpStatusText());
217
                                }
218
                                else
219
                                        GSS.get().displayError("System error trashing folder:"+t.getMessage());
220
                        }
221
                };
222
                DeferredCommand.addCommand(tot);
223
        }
224

  
225
        private void trashFiles(List<FileResource> files){
226
                final List<String> fileIds = new ArrayList<String>();
227
                for(FileResource f : files)
228
                        fileIds.add(f.getUri()+"?trash=");
229
                MultiplePostCommand tot = new MultiplePostCommand(fileIds.toArray(new String[0]),200){
230

  
231
                        @Override
232
                        public void onComplete() {
233
                                GSS.get().showFileList(true);
234
                        }
235

  
236
                        @Override
237
                        public void onError(String p, Throwable t) {
238
                                GWT.log("", t);
239
                                if(t instanceof RestException){
240
                                        int statusCode = ((RestException)t).getHttpStatusCode();
241
                                        if(statusCode == 405)
242
                                                GSS.get().displayError("You don't have the necessary permissions");
243
                                        else if(statusCode == 404)
244
                                                GSS.get().displayError("File does not exist");
245
                                        else
246
                                                GSS.get().displayError("Unable to trash file:"+((RestException)t).getHttpStatusText());
247
                                }
248
                                else
249
                                        GSS.get().displayError("System error trashing file:"+t.getMessage());
250
                        }
251
                };
252
                DeferredCommand.addCommand(tot);
253
        }
254

  
255

  
256
        private void executeCopyOrMoveFiles(final int index, final List<String> paths) {
257
                if (index >= paths.size()) {
258
                        GSS.get().showFileList(true);
259
                        GSS.get().getStatusPanel().updateStats();
260
                        return;
56
                hide();
57
            }
58
        }).setVisible(target != null);
59

  
60
        contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new Command() {
61

  
62
            @Override
63
            public void execute() {
64
                if (toCopy instanceof Folder)
65
                    copyFolder(target, (Folder) toCopy);
66
                else if (toCopy instanceof List) {
67
                    List<File> files = GSS.get().getFileList().getSelectedFiles();
68
                    copyFiles(target, files);
261 69
                }
262
                PostCommand cf = new PostCommand(paths.get(index), "", 200) {
263

  
264
                        @Override
265
                        public void onComplete() {
266
                                executeCopyOrMoveFiles(index + 1, paths);
267
                        }
70
                hide();
71
            }
72
        }).setVisible(target != null);
268 73

  
269
                        @Override
270
                        public void onError(Throwable t) {
271
                                GWT.log("", t);
272
                                if (t instanceof RestException) {
273
                                        int statusCode = ((RestException) t).getHttpStatusCode();
274
                                        if (statusCode == 405)
275
                                                GSS.get().displayError("You don't have the necessary permissions");
276
                                        else if (statusCode == 404)
277
                                                GSS.get().displayError("File not found");
278
                                        else if (statusCode == 409)
279
                                                GSS.get().displayError("A file with the same name already exists");
280
                                        else if (statusCode == 413)
281
                                                GSS.get().displayError("Your quota has been exceeded");
282
                                        else
283
                                                GSS.get().displayError("Unable to copy file:" + ((RestException)t).getHttpStatusText());
284
                                } else
285
                                        GSS.get().displayError("System error copying file:" + t.getMessage());
74
        contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.trash()).getHTML() + "&nbsp;Delete (Trash)</span>", true, new Command() {
286 75

  
287
                        }
288
                };
289
                DeferredCommand.addCommand(cf);
76
            @Override
77
            public void execute() {
78
                GWT.log("EXECUTE TRASH:" + toCopy.getClass().getName());
79
                if (toCopy instanceof RestResourceWrapper) {
80
                    trashFolder(((RestResourceWrapper) toCopy).getResource());
81
                }
82
                else if (toCopy instanceof List) {
83
                    List<File> files = GSS.get().getFileList().getSelectedFiles();
84
                    trashFiles(files);
85
                }
86
                hide();
87
            }
88
        }).setVisible(target == null);
89
        contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Cancel</span>", true, cancelCmd);
90

  
91
        add(contextMenu);
92
    }
93

  
94
    private void copyFolder(final Folder target, Folder toCopy) {
95
//        String atarget = target.getUri();
96
//        atarget = atarget.endsWith("/") ? atarget : atarget + '/';
97
//        atarget = atarget + toCopy.getName();
98
//        PostCommand cf = new PostCommand(toCopy.getUri() + "?copy=" + atarget, "", 200) {
99
//
100
//            @Override
101
//            public void onComplete() {
102
//                GSS.get().getTreeView().updateNodeChildren(new RestResourceWrapper(target));
103
//                GSS.get().getStatusPanel().updateStats();
104
//            }
105
//
106
//            @Override
107
//            public void onError(Throwable t) {
108
//                GWT.log("", t);
109
//                if (t instanceof RestException) {
110
//                    int statusCode = ((RestException) t).getHttpStatusCode();
111
//                    if (statusCode == 405)
112
//                        GSS.get().displayError("You don't have the necessary permissions");
113
//
114
//                    else if (statusCode == 409)
115
//                        GSS.get().displayError("A folder with the same name already exists");
116
//                    else if (statusCode == 413)
117
//                        GSS.get().displayError("Your quota has been exceeded");
118
//                    else
119
//                        GSS.get().displayError("Unable to copy folder:" + ((RestException) t).getHttpStatusText());
120
//                }
121
//                else
122
//                    GSS.get().displayError("System error copying folder:" + t.getMessage());
123
//            }
124
//        };
125
//        DeferredCommand.addCommand(cf);
126
    }
127

  
128
    private void moveFolder(final Folder target, final Folder toCopy) {
129
//        String atarget = target.getUri();
130
//        atarget = atarget.endsWith("/") ? atarget : atarget + '/';
131
//        atarget = atarget + toCopy.getName();
132
//
133
//        PostCommand cf = new PostCommand(toCopy.getUri() + "?move=" + atarget, "", 200) {
134
//
135
//            @Override
136
//            public void onComplete() {
137
//                GWT.log("[MOVE]" + target.getUri() + "   " + toCopy.getParentURI());
138
//                GSS.get().getTreeView().updateNodeChildren(new RestResourceWrapper(target));
139
//                GSS.get().getTreeView().updateNodeChildrenForRemove(toCopy.getParentURI());
140
//                GSS.get().getStatusPanel().updateStats();
141
//            }
142
//
143
//            @Override
144
//            public void onError(Throwable t) {
145
//                GWT.log("", t);
146
//                if (t instanceof RestException) {
147
//                    int statusCode = ((RestException) t).getHttpStatusCode();
148
//                    if (statusCode == 405)
149
//                        GSS.get().displayError("You don't have the necessary permissions");
150
//
151
//                    else if (statusCode == 409)
152
//                        GSS.get().displayError("A folder with the same name already exists");
153
//                    else if (statusCode == 413)
154
//                        GSS.get().displayError("Your quota has been exceeded");
155
//                    else
156
//                        GSS.get().displayError("Unable to copy folder:" + ((RestException) t).getHttpStatusText());
157
//                }
158
//                else
159
//                    GSS.get().displayError("System error copying folder:" + t.getMessage());
160
//            }
161
//        };
162
//        DeferredCommand.addCommand(cf);
163
    }
164

  
165
    private void copyFiles(final Folder ftarget, List<File> files) {
166
//        List<String> fileIds = new ArrayList<String>();
167
//        String target = ftarget.getUri();
168
//        target = target.endsWith("/") ? target : target + '/';
169
//        for (File file : files) {
170
//            String fileTarget = target + URL.encodeComponent(file.getName());
171
//            fileIds.add(file.getUri() + "?copy=" + fileTarget);
172
//        }
173
//        int index = 0;
174
//        executeCopyOrMoveFiles(index, fileIds);
175
    }
176

  
177
    private void moveFiles(final Folder ftarget, List<File> files) {
178
//        List<String> fileIds = new ArrayList<String>();
179
//        String target = ftarget.getUri();
180
//        target = target.endsWith("/") ? target : target + '/';
181
//        for (File file : files) {
182
//            String fileTarget = target + URL.encodeComponent(file.getName());
183
//            fileIds.add(file.getUri() + "?move=" + fileTarget);
184
//        }
185
//        int index = 0;
186
//        executeCopyOrMoveFiles(index, fileIds);
187
    }
188

  
189
    private void trashFolder(final FolderResource folder) {
190
        PostCommand tot = new PostCommand(folder.getUri() + "?trash=", "", 200) {
191

  
192
            @Override
193
            public void onComplete() {
194
                GSS.get().getTreeView().updateNodeChildrenForRemove(folder.getParentURI());
195
                GSS.get().getTreeView().updateTrashNode();
196
                /*for(TreeItem item : items)
197
                        GSS.get().getFolders().updateFolder((DnDTreeItem) item);
198
                GSS.get().getFolders().update(GSS.get().getFolders().getTrashItem());
199

  
200
                GSS.get().showFileList(true);
201
                */
202
            }
203

  
204
            @Override
205
            public void onError(Throwable t) {
206
                GWT.log("", t);
207
                if (t instanceof RestException) {
208
                    int statusCode = ((RestException) t).getHttpStatusCode();
209
                    if (statusCode == 405)
210
                        GSS.get().displayError("You don't have the necessary permissions");
211
                    else if (statusCode == 404)
212
                        GSS.get().displayError("Folder does not exist");
213
                    else
214
                        GSS.get().displayError("Unable to trash folder:" + ((RestException) t).getHttpStatusText());
215
                }
216
                else
217
                    GSS.get().displayError("System error trashing folder:" + t.getMessage());
218
            }
219
        };
220
        DeferredCommand.addCommand(tot);
221
    }
222

  
223
    private void trashFiles(List<File> files) {
224
        final List<String> fileIds = new ArrayList<String>();
225
        for (File f : files)
226
            fileIds.add(f.getUri() + "?trash=");
227
        MultiplePostCommand tot = new MultiplePostCommand(fileIds.toArray(new String[0]), 200) {
228

  
229
            @Override
230
            public void onComplete() {
231
                GSS.get().showFileList(true);
232
            }
233

  
234
            @Override
235
            public void onError(String p, Throwable t) {
236
                GWT.log("", t);
237
                if (t instanceof RestException) {
238
                    int statusCode = ((RestException) t).getHttpStatusCode();
239
                    if (statusCode == 405)
240
                        GSS.get().displayError("You don't have the necessary permissions");
241
                    else if (statusCode == 404)
242
                        GSS.get().displayError("File does not exist");
243
                    else
244
                        GSS.get().displayError("Unable to trash file:" + ((RestException) t).getHttpStatusText());
245
                }
246
                else
247
                    GSS.get().displayError("System error trashing file:" + t.getMessage());
248
            }
249
        };
250
        DeferredCommand.addCommand(tot);
251
    }
252

  
253
    private void executeCopyOrMoveFiles(final int index, final List<String> paths) {
254
        if (index >= paths.size()) {
255
            GSS.get().showFileList(true);
256
            GSS.get().getStatusPanel().updateStats();
257
            return;
290 258
        }
291

  
259
        PostCommand cf = new PostCommand(paths.get(index), "", 200) {
260

  
261
            @Override
262
            public void onComplete() {
263
                executeCopyOrMoveFiles(index + 1, paths);
264
            }
265

  
266
            @Override
267
            public void onError(Throwable t) {
268
                GWT.log("", t);
269
                if (t instanceof RestException) {
270
                    int statusCode = ((RestException) t).getHttpStatusCode();
271
                    if (statusCode == 405)
272
                        GSS.get().displayError("You don't have the necessary permissions");
273
                    else if (statusCode == 404)
274
                        GSS.get().displayError("File not found");
275
                    else if (statusCode == 409)
276
                        GSS.get().displayError("A file with the same name already exists");
277
                    else if (statusCode == 413)
278
                        GSS.get().displayError("Your quota has been exceeded");
279
                    else
280
                        GSS.get().displayError("Unable to copy file:" + ((RestException) t).getHttpStatusText());
281
                }
282
                else
283
                    GSS.get().displayError("System error copying file:" + t.getMessage());
284
            }
285
        };
286
        DeferredCommand.addCommand(cf);
287
    }
292 288
}
b/web_client/src/gr/grnet/pithos/web/client/FileList.java
7 7
import static com.google.gwt.query.client.GQuery.$;
8 8

  
9 9
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
10
import gr.grnet.pithos.web.client.foldertree.File;
11
import gr.grnet.pithos.web.client.foldertree.Folder;
12
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
10 13
import gr.grnet.pithos.web.client.rest.GetCommand;
11 14
import gr.grnet.pithos.web.client.rest.RestCommand;
12 15
import gr.grnet.pithos.web.client.rest.resource.FileResource;
......
19 22
import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
20 23
import gr.grnet.pithos.web.client.rest.resource.TrashResource;
21 24
import gr.grnet.pithos.web.client.rest.resource.UserResource;
22
import gr.grnet.pithos.web.client.rest.resource.UserSearchResource;
23 25
import gwtquery.plugins.draggable.client.DraggableOptions;
24 26
import gwtquery.plugins.draggable.client.StopDragException;
25 27
import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction;
......
44 46
import com.google.gwt.cell.client.TextCell;
45 47
import com.google.gwt.cell.client.ValueUpdater;
46 48
import com.google.gwt.core.client.GWT;
47
import com.google.gwt.core.client.Scheduler;
48
import com.google.gwt.core.client.Scheduler.RepeatingCommand;
49 49
import com.google.gwt.dom.client.Style.Cursor;
50 50
import com.google.gwt.event.dom.client.ClickEvent;
51 51
import com.google.gwt.event.dom.client.ClickHandler;
52
import com.google.gwt.http.client.URL;
53 52
import com.google.gwt.i18n.client.DateTimeFormat;
54 53
import com.google.gwt.resources.client.ClientBundle;
55 54
import com.google.gwt.resources.client.ImageResource;
......
59 58
import com.google.gwt.user.cellview.client.CellTable;
60 59
import com.google.gwt.user.cellview.client.GssSimplePager;
61 60
import com.google.gwt.user.client.DOM;
62
import com.google.gwt.user.client.DeferredCommand;
63 61
import com.google.gwt.user.client.Event;
64 62
import com.google.gwt.user.client.Window;
65 63
import com.google.gwt.user.client.ui.AbstractImagePrototype;
......
72 70
import com.google.gwt.view.client.ProvidesKey;
73 71
import com.google.gwt.view.client.SelectionChangeEvent;
74 72
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
73
import java.util.Set;
75 74

  
76 75
/**
77 76
 * A composite that displays the list of files in a particular folder.
78 77
 */
79 78
public class FileList extends Composite {
80
	ListDataProvider<FileResource> provider = new ListDataProvider<FileResource>();
79

  
80
	ListDataProvider<File> provider = new ListDataProvider<File>();
81

  
82
    /**
83
       * The styles applied to the table.
84
       */
85
    interface TableStyle extends CellTable.Style {
86
    }
87

  
81 88
	interface TableResources extends DragAndDropCellTable.Resources {
82 89
	    @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
83 90
	    TableStyle cellTableStyle();
84
	  }
91
	}
85 92
	
86 93
	static interface Templates extends SafeHtmlTemplates {
87 94
	    Templates INSTANCE = GWT.create(Templates.class);
......
100 107

  
101 108
        @Template("<span id='{0}' class='{1}'>{2}</span>")
102 109
        public SafeHtml spanWithIdAndClass(String id, String cssClass, String content);
103
	  }
104
	
105
	
106
	/**
107
	   * The styles applied to the table.
108
	   */
109
	  interface TableStyle extends CellTable.Style {
110
	  }
110
	}
111 111

  
112
	private String showingStats = "";
112
    private String showingStats = "";
113 113

  
114 114
	private int startIndex = 0;
115 115

  
......
118 118
	 */
119 119
	public static final boolean DONE = false;
120 120

  
121
	
122
	
123 121
	private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
124 122

  
125 123
	/**
......
202 200

  
203 201
	}
204 202
	
205
	DragStopEventHandler dragStop = new DragStopEventHandler() {
206
		
207
		@Override
208
		public void onDragStop(DragStopEvent event) {
209
			GWT.log("DRAG STOPPED");
210
			
211
		}
212
	};
213
	
214
	private static class ContactCell extends AbstractCell<gr.grnet.pithos.web.client.rest.resource.FileResource> {
215

  
216
	    /**
217
	     * The html of the image used for contacts.
218
	     * 
219
	     */
220
	    private final String imageHtml;
221

  
222
	    public ContactCell(ImageResource image) {
223
	      this.imageHtml = AbstractImagePrototype.create(image).getHTML();
224
	    }
225

  
226
	    
227

  
228
		
229

  
230
	    @Override
231
	    public void render(Context context, FileResource value, SafeHtmlBuilder sb) {
232
	      // Value can be null, so do a null check..
233
	      if (value == null) {
234
	        return;
235
	      }
236

  
237
          sb.append(Templates.INSTANCE.rendelContactCell(imageHtml, value.getName(), value.getFileSizeAsString()));
238
	    }
239

  
240

  
241
	  }
242
	/**
243
	 * Retrieve the celltable.
244
	 *
245
	 * @return the celltable
246
	 */
247
	public DragAndDropCellTable<FileResource> getCelltable() {
248
		return celltable;
249
	}
250
	
251
	
252 203
	/**
253 204
	 * The number of files in this folder.
254 205
	 */
......
262 213
	/**
263 214
	 * A cache of the files in the list.
264 215
	 */
265
	private List<FileResource> files;
216
	private List<File> files;
266 217

  
267 218
	/**
268 219
	 * The widget's image bundle.
......
270 221
	private final Images images;
271 222
	
272 223
	private FileContextMenu menuShowing;
273
	private DragAndDropCellTable<FileResource> celltable;
274
	private final MultiSelectionModel<FileResource> selectionModel;
224

  
225
	private DragAndDropCellTable<File> celltable;
226

  
227
	private final MultiSelectionModel<File> selectionModel;
228

  
275 229
	private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
230

  
276 231
	SortableHeader nameHeader;
232

  
277 233
	GssSimplePager pagerBottom;
234

  
278 235
	GssSimplePager pagerTop;
236

  
279 237
	Button uploadButtonBottom;
238

  
280 239
	Button uploadButtonTop;
281
	/**
240

  
241
    FolderTreeView treeView;
242

  
243
    /**
282 244
	 * Construct the file list widget. This entails setting up the widget
283 245
	 * layout, fetching the number of files in the current folder from the
284 246
	 * server and filling the local file cache of displayed files with data from
......
286 248
	 *
287 249
	 * @param _images
288 250
	 */
289
	public FileList(Images _images) {
251
	public FileList(Images _images, FolderTreeView treeView) {
290 252
		images = _images;
291
		DragAndDropCellTable.Resources resources = GWT.create(TableResources.class);
292
		ProvidesKey<FileResource> keyProvider = new ProvidesKey<FileResource>(){
253
        this.treeView = treeView;
254

  
255
        DragAndDropCellTable.Resources resources = GWT.create(TableResources.class);
256

  
257
        ProvidesKey<File> keyProvider = new ProvidesKey<File>(){
293 258

  
294 259
			@Override
295
			public Object getKey(FileResource item) {
260
			public Object getKey(File item) {
296 261
				return item.getUri();
297 262
			}
298
			
299 263
		};
300
		celltable = new DragAndDropCellTable<FileResource>(GSS.VISIBLE_FILE_COUNT,resources,keyProvider);
301
		
302
		DragAndDropColumn<FileResource, ImageResource> status = new DragAndDropColumn<FileResource, ImageResource>(new ImageResourceCell(){
303
			@Override
304
	          public boolean handlesSelection() {
305
	        	    return false;
306
	        	  }
307
		}) {
308
	          @Override
309
	          public ImageResource getValue(FileResource entity) {
310
	            return getFileIcon(entity);
311
	          }
312
	          
313
	       };
264

  
265
		celltable = new DragAndDropCellTable<File>(GSS.VISIBLE_FILE_COUNT, resources, keyProvider);
266
        celltable.setWidth("100%");
267
        celltable.setStyleName("pithos-List");
268

  
269
		DragAndDropColumn<File, ImageResource> status = new DragAndDropColumn<File, ImageResource>(new ImageResourceCell() {
270
		    @Override
271
	        public boolean handlesSelection() {
272
	            return false;
273
	        }
274
		})
275
        {
276
	         @Override
277
	         public ImageResource getValue(File entity) {
278
	             return getFileIcon(entity);
279
	         }
280
	    };
314 281
	    celltable.addColumn(status,"");
315
	    
316 282
	    initDragOperation(status);
317
		final DragAndDropColumn<FileResource,SafeHtml> nameColumn = new DragAndDropColumn<FileResource,SafeHtml>(new SafeHtmlCell()) {
283

  
284
        final DragAndDropColumn<File,SafeHtml> nameColumn = new DragAndDropColumn<File,SafeHtml>(new SafeHtmlCell()) {
318 285

  
319 286
			@Override
320
			public SafeHtml getValue(FileResource object) {
287
			public SafeHtml getValue(File object) {
321 288
				SafeHtmlBuilder sb = new SafeHtmlBuilder();
322 289
                sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
323
				if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg") ){
324
					sb.appendHtmlConstant("&nbsp;").append(Templates.INSTANCE.viewLink(GSS.get().getTopPanel().getFileMenu().getDownloadURL(object), object.getOwner() + " : " + object.getPath() + object.getName()));
290
				if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg")) {
291
        			sb.appendHtmlConstant("&nbsp;")
292
                      .append(Templates.INSTANCE.viewLink(object.getUri(), object.getOwner() + " : " + object.getPath() + object.getName()));
325 293
				}
326 294
				
327 295
				return sb.toSafeHtml();
328 296
			}
329 297
			
330 298
		};
331
		initDragOperation(nameColumn);
332
		celltable.addColumn(nameColumn,nameHeader = new SortableHeader("Name"));
299
        initDragOperation(nameColumn);
300
        celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name"));
333 301
		allHeaders.add(nameHeader);
334
		//nameHeader.setSorted(true);
335
		//nameHeader.toggleReverseSort();
336 302
		nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name"));
303

  
337 304
		celltable.redrawHeaders();
338 305
		
339
		
340
	    
341
	    
342
	    SortableHeader aheader;
343
	    DragAndDropColumn<FileResource,String> aColumn;
344
		celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
306
	    DragAndDropColumn<File,String> aColumn = new DragAndDropColumn<File, String>(new TextCell()) {
345 307
			@Override
346
			public String getValue(FileResource object) {
347
				return GSS.get().findUserFullName(object.getOwner());
348
			}			
349
		},aheader = new SortableHeader("Owner"));
308
			public String getValue(File object) {
309
				return object.getOwner();
310
			}
311
		};
312
        SortableHeader aheader = new SortableHeader("Owner");
313
		celltable.addColumn(aColumn, aheader);
350 314
		initDragOperation(aColumn);
351 315
		allHeaders.add(aheader);
352
		aheader.setUpdater(new FileValueUpdater(aheader, "owner"));
353
		celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
316
        aheader.setUpdater(new FileValueUpdater(aheader, "owner"));
317

  
318
        aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
354 319
			@Override
355
			public String getValue(FileResource object) {
356
				// TODO Auto-generated method stub
320
			public String getValue(File object) {
357 321
				return object.getPath();
358
			}			
359
		},aheader = new SortableHeader("Path"));
322
			}
323
		};
324
        aheader = new SortableHeader("Path");
325
		celltable.addColumn(aColumn, aheader);
360 326
		initDragOperation(aColumn);
361 327
		allHeaders.add(aheader);
362
		
363
		aheader.setUpdater(new FileValueUpdater(aheader, "path"));	
364
		celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
328
		aheader.setUpdater(new FileValueUpdater(aheader, "path"));
329

  
330
        aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
365 331
			@Override
366
			public String getValue(FileResource object) {
367
				if(object.isVersioned())
368
					return object.getVersion().toString();
369
				return "-";
370
			}			
371
		},aheader = new SortableHeader("Version"));
332
			public String getValue(File object) {
333
    			return String.valueOf(object.getVersion());
334
			}
335
		};
336
        aheader = new SortableHeader("Version");
337
		celltable.addColumn(aColumn, aheader);
372 338
		initDragOperation(aColumn);
373 339
		allHeaders.add(aheader);
374 340
		aheader.setUpdater(new FileValueUpdater(aheader, "version"));
375
		celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
341

  
342
        aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
376 343
			@Override
377
			public String getValue(FileResource object) {
344
			public String getValue(File object) {
378 345
				// TODO Auto-generated method stub
379
				return object.getFileSizeAsString();
380
			}			
381
		},aheader = new SortableHeader("Size"));
346
				return object.getSizeAsString();
347
			}
348
		};
349
        aheader = new SortableHeader("Size");
350
        celltable.addColumn(aColumn, aheader);
382 351
		initDragOperation(aColumn);
383 352
		allHeaders.add(aheader);
384
		aheader.setUpdater(new FileValueUpdater(aheader, "size"));	
385
		celltable.addColumn(aColumn=new DragAndDropColumn<FileResource,String>(new TextCell()) {
353
		aheader.setUpdater(new FileValueUpdater(aheader, "size"));
354

  
355
        aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
386 356
			@Override
387
			public String getValue(FileResource object) {
388
				return formatter.format(object.getModificationDate());
389
			}			
390
		},aheader = new SortableHeader("Last Modified"));
357
			public String getValue(File object) {
358
				return formatter.format(object.getLastModified());
359
			}
360
		};
361
        aheader = new SortableHeader("Last Modified");
362
		celltable.addColumn(aColumn, aheader);
391 363
		allHeaders.add(aheader);
392 364
		aheader.setUpdater(new FileValueUpdater(aheader, "date"));
393 365
	       
394
		
395 366
		provider.addDataDisplay(celltable);
396
		celltable.addDragStopHandler(dragStop);
367

  
368
		celltable.addDragStopHandler(new DragStopEventHandler() {
369

  
370
	    	@Override
371
		    public void onDragStop(DragStopEvent event) {
372
			    GWT.log("DRAG STOPPED");
373
		    }
374
	    });
397 375
		celltable.addDragStartHandler(new DragStartEventHandler() {
398 376

  
399
		      public void onDragStart(DragStartEvent event) {
377
		    public void onDragStart(DragStartEvent event) {
400 378
		        FileResource value = event.getDraggableData();
401 379
		        
402 380
		        com.google.gwt.dom.client.Element helper = event.getHelper();
......
409 387
		        	sb.appendEscaped(getSelectedFiles().size()+" files");
410 388
		        sb.appendHtmlConstant("</b>");
411 389
		        helper.setInnerHTML(sb.toSafeHtml().asString());
390
		    }
391
		});
412 392

  
413
		      }
414
		    });
415
		
416
		
417
		
418
		
419
		
420
		
421 393
		VerticalPanel vp = new VerticalPanel();
422 394
		vp.setWidth("100%");
395

  
423 396
		pagerTop = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
424
		pagerTop.setDisplay(celltable);	
425
		uploadButtonTop=new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>");
397
        pagerTop.setVisible(false);
398
		pagerTop.setDisplay(celltable);
399
		uploadButtonTop = new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>");
426 400
		uploadButtonTop.addClickHandler(new ClickHandler() {
427 401
			
428 402
			@Override
......
434 408
		topPanel.add(pagerTop);
435 409
		topPanel.add(uploadButtonTop);
436 410
		vp.add(topPanel);
437
		celltable.setWidth("100%");
438
		vp.add(celltable);
411

  
412
        vp.add(celltable);
413

  
439 414
		pagerBottom = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
415
        pagerBottom.setVisible(false);
440 416
		pagerBottom.setDisplay(celltable);
441
		HorizontalPanel bottomPanel = new HorizontalPanel();
442
		bottomPanel.add(pagerBottom);
443 417
		uploadButtonBottom=new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>");
444 418
		uploadButtonBottom.addClickHandler(new ClickHandler() {
445 419
			
......
448 422
				new UploadFileCommand(null).execute();
449 423
			}
450 424
		});
425
        HorizontalPanel bottomPanel = new HorizontalPanel();
426
        bottomPanel.add(pagerBottom);
451 427
		bottomPanel.add(uploadButtonBottom);
428

  
452 429
		vp.add(bottomPanel);
453 430
		vp.setCellWidth(celltable, "100%");
454
		
455 431
		initWidget(vp);
456
		pagerBottom.setVisible(false);
457
		pagerTop.setVisible(false);
458 432

  
459
		celltable.setStyleName("pithos-List");
460
		selectionModel = new MultiSelectionModel<FileResource>(keyProvider);
461
		
433
		selectionModel = new MultiSelectionModel<File>(keyProvider);
462 434

  
463
		 Handler selectionHandler = new SelectionChangeEvent.Handler() { 
435
		 Handler selectionHandler = new SelectionChangeEvent.Handler() {
464 436
             @Override 
465
             public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) {
466
            	 if(getSelectedFiles().size()==1)
437
             public void onSelectionChange(SelectionChangeEvent event) {
438
            	 if(getSelectedFiles().size() == 1)
467 439
            		 GSS.get().setCurrentSelection(getSelectedFiles().get(0));
468 440
            	 else
469 441
            		 GSS.get().setCurrentSelection(getSelectedFiles());
......
471 443
         };
472 444
         selectionModel.addSelectionChangeHandler(selectionHandler);
473 445
         
474
		celltable.setSelectionModel(selectionModel,GSSSelectionEventManager.<FileResource>createDefaultManager());
446
		celltable.setSelectionModel(selectionModel, GSSSelectionEventManager.<File> createDefaultManager());
475 447
		celltable.setPageSize(GSS.VISIBLE_FILE_COUNT);
476 448
		
477
//		Scheduler.get().scheduleIncremental(new RepeatingCommand() {
478
//
479
//			@Override
480
//			public boolean execute() {
481
//				return fetchRootFolder();
482
//			}
483
//		});
484 449
		sinkEvents(Event.ONCONTEXTMENU);
485 450
		sinkEvents(Event.ONMOUSEUP);
486 451
		sinkEvents(Event.ONMOUSEDOWN);
......
489 454
		sinkEvents(Event.ONDBLCLICK);
490 455
		GSS.preventIESelection();
491 456
	}
492
	
493 457

  
458
	public List<File> getSelectedFiles() {
459
        return new ArrayList<File>(selectionModel.getSelectedSet());
460
	}
494 461
	
495
	 public List<FileResource> getSelectedFiles() {
496
         return new ArrayList<FileResource>(selectionModel.getSelectedSet());
497
	 }
498
	
499
	 private void initDragOperation(DragAndDropColumn<?, ?> column) {
500

  
501
		    // retrieve draggableOptions on the column
502
		    DraggableOptions draggableOptions = column.getDraggableOptions();
503
		    // use template to construct the helper. The content of the div will be set
504
		    // after
505
		    draggableOptions.setHelper($(Templates.INSTANCE.outerHelper().asString()));
506
		    //draggableOptions.setZIndex(100);
507
		    // opacity of the helper
508
		    draggableOptions.setAppendTo("body"); 
509
		    //draggableOptions.setOpacity((float) 0.8);
510
		    draggableOptions.setContainment("document");
511
		    // cursor to use during the drag operation
512
		    draggableOptions.setCursor(Cursor.MOVE);
513
		    // set the revert option
514
		    draggableOptions.setRevert(RevertOption.ON_INVALID_DROP);
515
		    // prevents dragging when user click on the category drop-down list
516
		    draggableOptions.setCancel("select");
517
		    
518
		    
519
		    draggableOptions.setOnBeforeDragStart(new DragFunction() {
520
				
521
				@Override
522
				public void f(DragContext context) {
523
					 FileResource value = context.getDraggableData();
524
				     if(!selectionModel.isSelected(value)){
525
				       	throw new StopDragException();
526
				      }
527
					
528
				}
529
			});
530
		  }
462
	private void initDragOperation(DragAndDropColumn<?, ?> column) {
463
        // retrieve draggableOptions on the column
464
		DraggableOptions draggableOptions = column.getDraggableOptions();
465
		// use template to construct the helper. The content of the div will be set
466
		// after
467
		draggableOptions.setHelper($(Templates.INSTANCE.outerHelper().asString()));
468
		//draggableOptions.setZIndex(100);
469
		// opacity of the helper
470
		draggableOptions.setAppendTo("body");
471
		//draggableOptions.setOpacity((float) 0.8);
472
		draggableOptions.setContainment("document");
473
		// cursor to use during the drag operation
474
		draggableOptions.setCursor(Cursor.MOVE);
475
		// set the revert option
476
		draggableOptions.setRevert(RevertOption.ON_INVALID_DROP);
477
		// prevents dragging when user click on the category drop-down list
478
		draggableOptions.setCancel("select");
479
	    draggableOptions.setOnBeforeDragStart(new DragFunction() {
480
			@Override
481
			public void f(DragContext context) {
482
		        File value = context.getDraggableData();
483
				if (!selectionModel.isSelected(value)) {
484
    		       	throw new StopDragException();
485
	    	    }
486
			}
487
		});
488
    }
531 489
	
532
	 public void showContextMenu(Event event){
533
		 menuShowing = new FileContextMenu(images, false, true);
534
			menuShowing=menuShowing.onEmptyEvent(event);
535
	 }
490
	public void showContextMenu(Event event){
491
		menuShowing = new FileContextMenu(images, false, true);
492
		menuShowing=menuShowing.onEmptyEvent(event);
493
	}
536 494
	@Override
537 495
	public void onBrowserEvent(Event event) {
538 496
		
......
559 517
		} else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
560 518
			if (getSelectedFiles().size() == 1) {
561 519
				GSS app = GSS.get();
562
				FileResource file = getSelectedFiles().get(0);
563
				String dateString = RestCommand.getDate();
564
				String resource = file.getUri().substring(app.getApiPath().length() - 1, file.getUri().length());
565
				String sig = app.getCurrentUserResource().getUsername() + " " +
566
						RestCommand.calculateSig("GET", dateString, resource,
567
						RestCommand.base64decode(app.getToken()));
568
				Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date=" + URL.encodeComponent(dateString), "_blank", "");
520
				File file = getSelectedFiles().get(0);
521
				Window.open(file.getUri(), "_blank", "");
569 522
				event.preventDefault();
570 523
				return;
571 524
			}
......
573 526
	}
574 527

  
575 528
	/**
576
	 * Retrieve the root folder for the current user.
577
	 *
578
	 * @return true if the retrieval was successful
579
	 */
580
	protected boolean fetchRootFolder() {
581
		UserResource user = GSS.get().getCurrentUserResource();
582
		if (user == null)
583
			return !DONE;
584
		// Update cache and clear selection.
585
		updateFileCache(true);
586
		return DONE;
587
	}
588

  
589

  
590
	/**
591 529
	 * Update the display of the file list.
592 530
	 */
593 531
	void update(boolean sort) {
......
597 535
			max = count;
598 536
		folderTotalSize = 0;
599 537
		
600
		copyListAndContinue(files);
601
		for(FileResource f : files){
602
			folderTotalSize += f.getContentLength();
538
		for(File f : files){
539
			folderTotalSize += f.getBytes();
603 540
		}
604 541
		if (folderFileCount == 0) {
605 542
			showingStats = "no files";
......
623 560
	 * @param file
624 561
	 * @return the icon
625 562
	 */
626
	private ImageResource getFileIcon(FileResource file) {
563
	private ImageResource getFileIcon(File file) {
627 564
		String mimetype = file.getContentType();
628
		boolean shared = false;
629
		if(GSS.get().getTreeView().getSelection()!=null && (GSS.get().getTreeView().getSelection() instanceof OtherUserResource || GSS.get().getTreeView().getSelection() instanceof OthersFolderResource)){
630
			OtherUserResource otherUser = null;
631
			if(GSS.get().getTreeView().getSelection() instanceof OtherUserResource)
632
				otherUser = (OtherUserResource) GSS.get().getTreeView().getSelection();
633
			else if (GSS.get().getTreeView().getSelection() instanceof OthersFolderResource){
634
				otherUser = GSS.get().getTreeView().getOtherUserResourceOfOtherFolder((OthersFolderResource) GSS.get().getTreeView().getSelection());
635
			}
636
			if(otherUser ==null)
637
				shared=false;
638
			else{
639
				String uname = otherUser.getUsername();
640
				if(uname==null)
641
					uname = GSS.get().getTreeView().getOthers().getUsernameOfUri(otherUser.getUri());
642
				if(uname != null)
643
					shared = file.isShared();
644
			}
645
		}
646
		else
647
			shared = file.isShared();
565
		boolean shared = file.isShared();
648 566
		if (mimetype == null)
649 567
			return shared ? images.documentShared() : images.document();
650 568
		mimetype = mimetype.toLowerCase();
......
682 600
		GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats);
683 601
	}
684 602
	
685
	public void updateFileCache(boolean clearSelection){
686
		if(clearSelection){
687
			clearSelectedRows();
688
		}
689
		
690
		final RestResource folderItem = GSS.get().getTreeView().getSelection();
691
		// Validation.
692
		if (folderItem == null || folderItem.equals(GSS.get().getTreeView().getOthers())) {
693
			setFiles(new ArrayList<FileResource>());
694
			update(true);
695
			return;
696
		}
697
		else if (folderItem instanceof RestResourceWrapper) {
698
			setFiles(((RestResourceWrapper) folderItem).getResource().getFiles());
699
			update(true);
700
		}
701
		else if (folderItem instanceof SharedResource) {
702
			setFiles(((SharedResource) folderItem).getFiles());
703
			update(true);
704
		}
705
		else if (folderItem instanceof OtherUserResource) {
706
			setFiles(((OtherUserResource) folderItem).getFiles());
707
			update(true);
708
		}
709
		else if (folderItem instanceof TrashResource) {
710
			setFiles(((TrashResource) folderItem).getFiles());
711
			update(true);
712
		}
713
	}
714
	
715

  
716 603
	/**
717 604
	 * Fill the file cache with data.
718 605
	 */
719
	public void setFiles(final List<FileResource> _files) {
720
		if (_files.size() > 0 && ! (GSS.get().getTreeView().getSelection() instanceof TrashResource)) {
721
			files = new ArrayList<FileResource>();
722
			for (FileResource fres : _files)
723
				if (!fres.isDeleted())
724
					files.add(fres);
725
		}
726
		else
727
			files = _files;
728
		Collections.sort(files, new Comparator<FileResource>() {
606
	public void setFiles(final List<File> _files) {
607
		files = new ArrayList<File>();
608
    	for (File fres : _files)
609
	    	if (!fres.isInTrash())
610
				files.add(fres);
611
		Collections.sort(files, new Comparator<File>() {
729 612

  
730 613
			@Override
731
			public int compare(FileResource arg0, FileResource arg1) {
614
			public int compare(File arg0, File arg1) {
732 615
				return arg0.getName().compareTo(arg1.getName());
733 616
			}
734 617

  
......
738 621
		nameHeader.setSorted(true);
739 622
		nameHeader.toggleReverseSort();
740 623
		for (SortableHeader otherHeader : allHeaders) {
741
	          if (otherHeader != nameHeader) {
624
	        if (otherHeader != nameHeader) {
742 625
	            otherHeader.setSorted(false);
743 626
	            otherHeader.setReverseSort(true);
744
	          }
745 627
	        }
746
		//
747
	}
628
	    }
748 629

  
749
	
630
        if(files.size() > GSS.VISIBLE_FILE_COUNT){
631
            pagerBottom.setVisible(true);
632
            pagerTop.setVisible(true);
633
        }
634
        else{
635
            pagerTop.setVisible(false);
636
            pagerBottom.setVisible(false);
637
        }
638
        Folder selectedItem = treeView.getSelection();
639

  
640
        provider.setList(files);
641
        provider.refresh();
642
        celltable.redrawHeaders();
643
	}
750 644

  
751
	
752 645
	/**
753 646
	 * Does the list contains the requested filename
754 647
	 *
......
763 656
	}
764 657

  
765 658
	public void clearSelectedRows() {
766
		Iterator<FileResource> it = selectionModel.getSelectedSet().iterator();
659
		Iterator<File> it = selectionModel.getSelectedSet().iterator();
767 660
		while(it.hasNext()){
768 661
			selectionModel.setSelected(it.next(),false);
769 662
		}
......
774 667
	 *
775 668
	 */
776 669
	public void selectAllRows() {
777
		Iterator<FileResource> it = provider.getList().iterator();
670
		Iterator<File> it = provider.getList().iterator();
778 671
		while(it.hasNext()){
779 672
			selectionModel.setSelected(it.next(),true);
780 673
		}
......
784 677

  
785 678
	
786 679
	private void sortFiles(final String sortingProperty, final boolean sortingType){
787
		Collections.sort(files, new Comparator<FileResource>() {
680
		Collections.sort(files, new Comparator<File>() {
788 681

  
789 682
            @Override
790
            public int compare(FileResource arg0, FileResource arg1) {
683
            public int compare(File arg0, File arg1) {
791 684
                    AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc());
792 685
                    AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc());
793 686
                    if (sortingType){
794 687
                            if (sortingProperty.equals("version")) {
795
                                    return arg0.getVersion().compareTo(arg1.getVersion());
688
                                    return arg0.getVersion() - arg1.getVersion();
796 689
                            } else if (sortingProperty.equals("owner")) {
797 690
                                    return arg0.getOwner().compareTo(arg1.getOwner());
798 691
                            } else if (sortingProperty.equals("date")) {
799
                                    return arg0.getModificationDate().compareTo(arg1.getModificationDate());
692
                                    return arg0.getLastModified().compareTo(arg1.getLastModified());
800 693
                            } else if (sortingProperty.equals("size")) {
801
                                    return arg0.getContentLength().compareTo(arg1.getContentLength());
694
                                    return (int) (arg0.getBytes() - arg1.getBytes());
802 695
                            } else if (sortingProperty.equals("name")) {
803 696
                                    return arg0.getName().compareTo(arg1.getName());
804 697
                            } else if (sortingProperty.equals("path")) {
......
809 702
                    }
810 703
                    else if (sortingProperty.equals("version")) {
811 704
                            
812
                            return arg1.getVersion().compareTo(arg0.getVersion());
705
                            return arg1.getVersion() - arg0.getVersion();
813 706
                    } else if (sortingProperty.equals("owner")) {
814 707
                            
815 708
                            return arg1.getOwner().compareTo(arg0.getOwner());
816 709
                    } else if (sortingProperty.equals("date")) {
817 710
                            
818
                            return arg1.getModificationDate().compareTo(arg0.getModificationDate());
711
                            return arg1.getLastModified().compareTo(arg0.getLastModified());
819 712
                    } else if (sortingProperty.equals("size")) {
820
                            
821
                            return arg1.getContentLength().compareTo(arg0.getContentLength());
713
                            return (int) (arg1.getBytes() - arg0.getBytes());
822 714
                    } else if (sortingProperty.equals("name")) {
823 715
                            
824 716
                            return arg1.getName().compareTo(arg0.getName());
......
861 753
		}
862 754
		
863 755
	}
864
	/**
865
	 * Creates a new ArrayList<FileResources> from the given files ArrayList 
866
	 * in order that the input files remain untouched 
867
	 * and continues to find user's full names of each FileResource element
868
	 * in the new ArrayList
869
	 *    
870
	 * @param filesInput
871
	 */
872
	private void copyListAndContinue(List<FileResource> filesInput){
873
		List<FileResource> copiedFiles = new ArrayList<FileResource>();		
874
		for(FileResource file : filesInput) {
875
			copiedFiles.add(file);
876
		}
877
		handleFullNames(copiedFiles);
878
	}
879
	
880
	/**
881
	 * Examines whether or not the user's full name exists in the 
882
	 * userFullNameMap in the GSS.java for every element of the input list.
883
	 * If the user's full name does not exist in the map then a command is being made.  
884
	 * 
885
	 * @param filesInput
886
	 */
887
	private void handleFullNames(List<FileResource> filesInput){		
888
		if(filesInput.size() == 0){
889
			showCellTable();
890
			return;
891
		}		
892

  
893
		if(GSS.get().findUserFullName(filesInput.get(0).getOwner()) == null){
894
			findFullNameAndUpdate(filesInput);		
895
			return;
896
		}
897
				
898
		if(filesInput.size() >= 1){
899
			filesInput.remove(filesInput.get(0));
900
			if(filesInput.isEmpty()){
901
				showCellTable();				
902
			}else{
903
				handleFullNames(filesInput);
904
			}
905
		}		
906
	}
907
	
908
	/**
909
	 * Makes a command to search for full name from a given username. 
910
	 * Only after the completion of the command the celltable is shown
911
	 * or the search for the next full name continues.
912
	 *  
913
	 * @param filesInput
914
	 */
915
	private void findFullNameAndUpdate(final List<FileResource> filesInput){		
916
		String aUserName = filesInput.get(0).getOwner();
917
		String path = GSS.get().getApiPath() + "users/" + aUserName; 
918 756

  
919
		GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path, false,null) {
920
			@Override
921
			public void onComplete() {
922
				final UserSearchResource result = getResult();
923
				for (UserResource user : result.getUsers()){
924
					String username = user.getUsername();
925
					String userFullName = user.getName();
926
					GSS.get().putUserToMap(username, userFullName);
927
					if(filesInput.size() >= 1){
928
						filesInput.remove(filesInput.get(0));
929
						if(filesInput.isEmpty()){
930
							showCellTable();
931
						}else{
932
							handleFullNames(filesInput);
933
						}												
934
					}									
935
				}
936
			}
937
			@Override
938
			public void onError(Throwable t) {
939
				GWT.log("", t);
940
				GSS.get().displayError("Unable to fetch user's full name from the given username " + filesInput.get(0).getOwner());
941
				if(filesInput.size() >= 1){
942
					filesInput.remove(filesInput.get(0));
943
					handleFullNames(filesInput);					
944
				}
945
			}
946
		};
947
		DeferredCommand.addCommand(gg);
948
	
949
	}
950 757
	/**
951 758
	 * Shows the files in the cellTable 
952
	 */
953

  
759
     */
954 760
	private void showCellTable(){
955 761
		if(files.size()>GSS.VISIBLE_FILE_COUNT){
956 762
			pagerBottom.setVisible(true);
......
960 766
			pagerTop.setVisible(false);
961 767
			pagerBottom.setVisible(false);
962 768
		}
963
		RestResource selectedItem = GSS.get().getTreeView().getSelection();
964
		boolean uploadVisible = !(selectedItem != null && (selectedItem instanceof TrashResource || selectedItem instanceof TrashFolderResource || selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource));
965
		uploadButtonBottom.setVisible(uploadVisible&&files.size()>=GSS.VISIBLE_FILE_COUNT);
966
		uploadButtonTop.setVisible(uploadVisible&&files.size()>=GSS.VISIBLE_FILE_COUNT);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff