Revision fbff60ff web_client/src/gr/grnet/pithos/web/client/FileList.java

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);
967 769
		provider.setList(files);
968 770
		
969 771
		provider.refresh();
......
971 773
		//celltable.redraw();
972 774
		celltable.redrawHeaders();		
973 775
	}
974

  
975
	
976 776
}

Also available in: Unified diff