Revision cdd90acb src/gr/grnet/pithos/web/client/Pithos.java

b/src/gr/grnet/pithos/web/client/Pithos.java
34 34
 */
35 35
package gr.grnet.pithos.web.client;
36 36

  
37
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
38
import gr.grnet.pithos.web.client.foldertree.AccountResource;
39
import gr.grnet.pithos.web.client.foldertree.File;
40
import gr.grnet.pithos.web.client.foldertree.Folder;
41
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
42
import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel;
43
import gr.grnet.pithos.web.client.foldertree.Resource;
44
import gr.grnet.pithos.web.client.grouptree.Group;
45
import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
46
import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel;
47
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView;
48
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel;
49
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView;
50
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeViewModel;
51
import gr.grnet.pithos.web.client.rest.DeleteRequest;
52
import gr.grnet.pithos.web.client.rest.GetRequest;
53
import gr.grnet.pithos.web.client.rest.HeadRequest;
54
import gr.grnet.pithos.web.client.rest.PutRequest;
55
import gr.grnet.pithos.web.client.rest.RestException;
56

  
57
import java.util.ArrayList;
58
import java.util.Date;
59
import java.util.HashMap;
60
import java.util.Iterator;
61
import java.util.List;
62
import java.util.Set;
63

  
64
import org.apache.http.HttpStatus;
65

  
66 37
import com.google.gwt.core.client.EntryPoint;
67 38
import com.google.gwt.core.client.GWT;
68 39
import com.google.gwt.core.client.JsArrayString;
......
82 53
import com.google.gwt.resources.client.CssResource;
83 54
import com.google.gwt.resources.client.ImageResource;
84 55
import com.google.gwt.resources.client.ImageResource.ImageOptions;
85
import com.google.gwt.user.client.Command;
86
import com.google.gwt.user.client.Cookies;
87
import com.google.gwt.user.client.Event;
88
import com.google.gwt.user.client.History;
89
import com.google.gwt.user.client.Window;
90
import com.google.gwt.user.client.ui.AbstractImagePrototype;
91
import com.google.gwt.user.client.ui.Button;
92
import com.google.gwt.user.client.ui.Composite;
93
import com.google.gwt.user.client.ui.FlowPanel;
94
import com.google.gwt.user.client.ui.HTML;
95
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
96
import com.google.gwt.user.client.ui.HasVerticalAlignment;
97
import com.google.gwt.user.client.ui.HorizontalPanel;
98
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
99
import com.google.gwt.user.client.ui.PopupPanel;
100
import com.google.gwt.user.client.ui.RootPanel;
101
import com.google.gwt.user.client.ui.VerticalPanel;
56
import com.google.gwt.user.client.*;
57
import com.google.gwt.user.client.ui.*;
102 58
import com.google.gwt.view.client.SelectionChangeEvent;
103 59
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
104 60
import com.google.gwt.view.client.SingleSelectionModel;
61
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
62
import gr.grnet.pithos.web.client.foldertree.*;
63
import gr.grnet.pithos.web.client.grouptree.Group;
64
import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
65
import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel;
66
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView;
67
import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel;
68
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView;
69
import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeViewModel;
70
import gr.grnet.pithos.web.client.rest.*;
71
import org.apache.http.HttpStatus;
72

  
73
import java.util.*;
105 74

  
106 75
/**
107 76
 * Entry point classes define <code>onModuleLoad()</code>.
108 77
 */
109 78
public class Pithos implements EntryPoint, ResizeHandler {
110 79

  
111
	public static final String HOME_CONTAINER = "pithos";
112

  
113
	public static final String TRASH_CONTAINER = "trash";
114

  
115
	public static final Configuration config = GWT.create(Configuration.class);
116
	
117
	public interface Style extends CssResource {
118
		String commandAnchor();
119
		
120
		String statistics();
121
		
122
		@ClassName("gwt-HTML")
123
		String html();
124
		
125
		String uploadAlert();
126

  
127
		String uploadAlertLink();
128

  
129
		String uploadAlertProgress();
130
		
131
		String uploadAlertPercent();
132
		
133
		String uploadAlertClose();
134
	}
135
	
136
	public interface Resources extends ClientBundle {
137
		@Source("Pithos.css")
138
		Style pithosCss();
139
		
140
		@Source("gr/grnet/pithos/resources/close-popup.png")
141
		ImageResource closePopup();
142
	}
143

  
144
	public static Resources resources = GWT.create(Resources.class);
145
	
146
	/**
147
	 * Instantiate an application-level image bundle. This object will provide
148
	 * programmatic access to all the images needed by widgets.
149
	 */
150
	static Images images = (Images) GWT.create(Images.class);
80
    public static final String HOME_CONTAINER = "pithos";
81

  
82
    public static final String TRASH_CONTAINER = "trash";
83

  
84
    public static final Configuration config = GWT.create(Configuration.class);
85

  
86
    public interface Style extends CssResource {
87
        String commandAnchor();
88

  
89
        String statistics();
90

  
91
        @ClassName("gwt-HTML")
92
        String html();
93

  
94
        String uploadAlert();
95

  
96
        String uploadAlertLink();
97

  
98
        String uploadAlertProgress();
99

  
100
        String uploadAlertPercent();
101

  
102
        String uploadAlertClose();
103
    }
104

  
105
    public interface Resources extends ClientBundle {
106
        @Source("Pithos.css")
107
        Style pithosCss();
108

  
109
        @Source("gr/grnet/pithos/resources/close-popup.png")
110
        ImageResource closePopup();
111
    }
112

  
113
    public static Resources resources = GWT.create(Resources.class);
114

  
115
    /**
116
     * Instantiate an application-level image bundle. This object will provide
117
     * programmatic access to all the images needed by widgets.
118
     */
119
    static Images images = (Images) GWT.create(Images.class);
151 120

  
152 121
    public String getUsername() {
153 122
        return username;
......
170 139
    }
171 140

  
172 141
    public void updateMySharedRoot() {
173
    	mysharedTreeView.updateRoot();
142
        mysharedTreeView.updateRoot();
174 143
    }
175
    
144

  
176 145
    public void updateSharedFolder(Folder f, boolean showfiles, Command callback) {
177
    	mysharedTreeView.updateFolder(f, showfiles, callback);
146
        mysharedTreeView.updateFolder(f, showfiles, callback);
178 147
    }
179
    
148

  
180 149
    public void updateSharedFolder(Folder f, boolean showfiles) {
181
    	updateSharedFolder(f, showfiles, null);
150
        updateSharedFolder(f, showfiles, null);
182 151
    }
183 152

  
184 153
    public void updateOtherSharedFolder(Folder f, boolean showfiles, Command callback) {
185
    	otherSharedTreeView.updateFolder(f, showfiles, callback);
154
        otherSharedTreeView.updateFolder(f, showfiles, callback);
186 155
    }
187 156

  
188 157
    public MysharedTreeView getMySharedTreeView() {
......
190 159
    }
191 160

  
192 161
    /**
193
	 * An aggregate image bundle that pulls together all the images for this
194
	 * application into a single bundle.
195
	 */
196
	public interface Images extends TopPanel.Images, FileList.Images, ToolsMenu.Images {
197

  
198
		@Source("gr/grnet/pithos/resources/document.png")
199
		ImageResource folders();
200

  
201
		@Source("gr/grnet/pithos/resources/advancedsettings.png")
202
		@ImageOptions(width=32, height=32)
203
		ImageResource tools();
204
	}
205

  
206
	private Throwable error;
207
	
208
	/**
209
	 * The Application Clipboard implementation;
210
	 */
211
	private Clipboard clipboard = new Clipboard();
212

  
213
	/**
214
	 * The top panel that contains the menu bar.
215
	 */
216
	private TopPanel topPanel;
217

  
218
	/**
219
	 * The panel that contains the various system messages.
220
	 */
221
	private MessagePanel messagePanel = new MessagePanel(this, Pithos.images);
222

  
223
	/**
224
	 * The bottom panel that contains the status bar.
225
	 */
226
	StatusPanel statusPanel = null;
227

  
228
	/**
229
	 * The file list widget.
230
	 */
231
	private FileList fileList;
232

  
233
	/**
234
	 * The tab panel that occupies the right side of the screen.
235
	 */
236
	private VerticalPanel inner = new VerticalPanel();
237

  
238

  
239
	/**
240
	 * The split panel that will contain the left and right panels.
241
	 */
242
	private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
243

  
244
	/**
245
	 * The currently selected item in the application, for use by the Edit menu
246
	 * commands. Potential types are Folder, File, User and Group.
247
	 */
248
	private Object currentSelection;
249

  
250
	public HashMap<String, String> userFullNameMap = new HashMap<String, String>();
162
     * An aggregate image bundle that pulls together all the images for this
163
     * application into a single bundle.
164
     */
165
    public interface Images extends TopPanel.Images, FileList.Images, ToolsMenu.Images {
166

  
167
        @Source("gr/grnet/pithos/resources/document.png")
168
        ImageResource folders();
169

  
170
        @Source("gr/grnet/pithos/resources/advancedsettings.png")
171
        @ImageOptions(width = 32, height = 32)
172
        ImageResource tools();
173
    }
174

  
175
    private Throwable error;
176

  
177
    /**
178
     * The Application Clipboard implementation;
179
     */
180
    private Clipboard clipboard = new Clipboard();
181

  
182
    /**
183
     * The top panel that contains the menu bar.
184
     */
185
    private TopPanel topPanel;
186

  
187
    /**
188
     * The panel that contains the various system messages.
189
     */
190
    private MessagePanel messagePanel = new MessagePanel(this, Pithos.images);
191

  
192
    /**
193
     * The bottom panel that contains the status bar.
194
     */
195
    StatusPanel statusPanel = null;
196

  
197
    /**
198
     * The file list widget.
199
     */
200
    private FileList fileList;
201

  
202
    /**
203
     * The tab panel that occupies the right side of the screen.
204
     */
205
    private VerticalPanel inner = new VerticalPanel();
206

  
207

  
208
    /**
209
     * The split panel that will contain the left and right panels.
210
     */
211
    private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
212

  
213
    /**
214
     * The currently selected item in the application, for use by the Edit menu
215
     * commands. Potential types are Folder, File, User and Group.
216
     */
217
    private Object currentSelection;
218

  
219
    public HashMap<String, String> userFullNameMap = new HashMap<String, String>();
251 220

  
252 221
    private String username = null;
253 222

  
......
257 226
    private String token;
258 227

  
259 228
    VerticalPanel trees;
260
    
229

  
261 230
    SingleSelectionModel<Folder> folderTreeSelectionModel;
262 231
    FolderTreeViewModel folderTreeViewModel;
263 232
    FolderTreeView folderTreeView;
264 233

  
265 234
    SingleSelectionModel<Folder> mysharedTreeSelectionModel;
266 235
    MysharedTreeViewModel mysharedTreeViewModel;
267
    MysharedTreeView mysharedTreeView = null;;
236
    MysharedTreeView mysharedTreeView = null;
268 237

  
269 238
    protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel;
270 239
    OtherSharedTreeViewModel otherSharedTreeViewModel;
......
275 244

  
276 245
    TreeView selectedTree;
277 246
    protected AccountResource account;
278
    
247

  
279 248
    Folder trash;
280
    
249

  
281 250
    List<Composite> treeViews = new ArrayList<Composite>();
282 251

  
283
    @SuppressWarnings("rawtypes") List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
284
    
252
    @SuppressWarnings("rawtypes")
253
    List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
254

  
285 255
    public Button upload;
286
    
256

  
287 257
    private HTML numOfFiles;
288
    
258

  
289 259
    private Toolbar toolbar;
290
    
260

  
291 261
    private FileUploadDialog fileUploadDialog = new FileUploadDialog(this);
292 262

  
293
	UploadAlert uploadAlert;
294
	
295
	Date lastModified;
263
    UploadAlert uploadAlert;
264

  
265
    Date lastModified;
296 266

  
297
	@Override
298
	public void onModuleLoad() {
299
		if (parseUserCredentials())
267
    @Override
268
    public void onModuleLoad() {
269
        if(parseUserCredentials()) {
300 270
            initialize();
301
	}
271
        }
272
    }
302 273

  
303 274
    private void initialize() {
304
    	lastModified = new Date(); //Initialize if-modified-since value with now.
305
    	resources.pithosCss().ensureInjected();
306
    	boolean bareContent = Window.Location.getParameter("noframe") != null;
307
    	String contentWidth = bareContent ? "100%" : "75%";
275
        lastModified = new Date(); //Initialize if-modified-since value with now.
276
        resources.pithosCss().ensureInjected();
277
        boolean bareContent = Window.Location.getParameter("noframe") != null;
278
        String contentWidth = bareContent ? "100%" : "75%";
308 279

  
309
    	VerticalPanel outer = new VerticalPanel();
280
        VerticalPanel outer = new VerticalPanel();
310 281
        outer.setWidth("100%");
311
    	if (!bareContent) {
312
    		outer.addStyleName("pithos-outer");
313
    	}
314

  
315
        if (!bareContent) {
316
	        topPanel = new TopPanel(this, Pithos.images);
317
	        topPanel.setWidth("100%");
318
	        outer.add(topPanel);
319
	        outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER);
282
        if(!bareContent) {
283
            outer.addStyleName("pithos-outer");
284
        }
285

  
286
        if(!bareContent) {
287
            topPanel = new TopPanel(this, Pithos.images);
288
            topPanel.setWidth("100%");
289
            outer.add(topPanel);
290
            outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER);
320 291
        }
321
        
292

  
322 293
        messagePanel.setVisible(false);
323 294
        outer.add(messagePanel);
324 295
        outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
......
327 298
        HorizontalPanel header = new HorizontalPanel();
328 299
        header.addStyleName("pithos-header");
329 300
        header.setWidth(contentWidth);
330
        if (bareContent)
331
        	header.addStyleName("pithos-header-noframe");
301
        if(bareContent) {
302
            header.addStyleName("pithos-header-noframe");
303
        }
332 304
        upload = new Button("Upload", new ClickHandler() {
333 305
            @Override
334 306
            public void onClick(ClickEvent event) {
335
            	if (getSelection() != null)
336
            		new UploadFileCommand(Pithos.this, null, getSelection()).execute();
307
                if(getSelection() != null) {
308
                    new UploadFileCommand(Pithos.this, null, getSelection()).execute();
309
                }
337 310
            }
338 311
        });
339 312
        upload.addStyleName("pithos-uploadButton");
......
345 318
        header.add(toolbar);
346 319
        header.setCellHorizontalAlignment(toolbar, HasHorizontalAlignment.ALIGN_CENTER);
347 320
        header.setCellVerticalAlignment(toolbar, HasVerticalAlignment.ALIGN_MIDDLE);
348
        
321

  
349 322
        HorizontalPanel folderStatistics = new HorizontalPanel();
350 323
        folderStatistics.addStyleName("pithos-folderStatistics");
351 324
        numOfFiles = new HTML();
......
368 341
        folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
369 342
            @Override
370 343
            public void onSelectionChange(SelectionChangeEvent event) {
371
                if (folderTreeSelectionModel.getSelectedObject() != null) {
344
                if(folderTreeSelectionModel.getSelectedObject() != null) {
372 345
                    deselectOthers(folderTreeView, folderTreeSelectionModel);
373 346
                    applyPermissions(folderTreeSelectionModel.getSelectedObject());
374 347
                    Folder f = folderTreeSelectionModel.getSelectedObject();
375
            		updateFolder(f, true, new Command() {
376
            			
377
            			@Override
378
            			public void execute() {
379
            				updateStatistics();
380
            			}
381
            		}, true);
382
            		showRelevantToolbarButtons();
348
                    updateFolder(f, true, new Command() {
349

  
350
                        @Override
351
                        public void execute() {
352
                            updateStatistics();
353
                        }
354
                    }, true);
355
                    showRelevantToolbarButtons();
356
                }
357
                else {
358
                    if(getSelectedTree().equals(folderTreeView)) {
359
                        setSelectedTree(null);
360
                    }
361
                    if(getSelectedTree() == null) {
362
                        showRelevantToolbarButtons();
363
                    }
383 364
                }
384
				else {
385
					if (getSelectedTree().equals(folderTreeView))
386
						setSelectedTree(null);
387
					if (getSelectedTree() == null)
388
						showRelevantToolbarButtons();
389
				}
390 365
            }
391 366
        });
392 367
        selectionModels.add(folderTreeSelectionModel);
......
394 369
        folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel);
395 370
        folderTreeView = new FolderTreeView(folderTreeViewModel);
396 371
        treeViews.add(folderTreeView);
397
        
372

  
398 373
        fileList = new FileList(this, images);
399 374
        inner.add(fileList);
400 375

  
401 376
        trees = new VerticalPanel();
402 377
        trees.setWidth("100%");
403
        
378

  
404 379
        // Add the left and right panels to the split panel.
405 380
        splitPanel.setLeftWidget(trees);
406 381
        FlowPanel right = new FlowPanel();
......
414 389
        outer.add(splitPanel);
415 390
        outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER);
416 391

  
417
        if (!bareContent) {
418
	        statusPanel = new StatusPanel();
419
	        statusPanel.setWidth("100%");
420
	        outer.add(statusPanel);
421
	        outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER);
392
        if(!bareContent) {
393
            statusPanel = new StatusPanel();
394
            statusPanel.setWidth("100%");
395
            outer.add(statusPanel);
396
            outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER);
397
        }
398
        else {
399
            splitPanel.addStyleName("pithos-splitPanel-noframe");
422 400
        }
423
        else
424
        	splitPanel.addStyleName("pithos-splitPanel-noframe");
425 401

  
426 402
        // Hook the window resize event, so that we can adjust the UI.
427 403
        Window.addResizeHandler(this);
......
435 411
        // this in a deferred command causes it to occur after all widgets'
436 412
        // sizes have been computed by the browser.
437 413
        Scheduler.get().scheduleIncremental(new RepeatingCommand() {
438
			
439
			@Override
440
			public boolean execute() {
441
				if (!isCloudbarReady())
442
					return true;
414

  
415
            @Override
416
            public boolean execute() {
417
                if(!isCloudbarReady()) {
418
                    return true;
419
                }
443 420
                onWindowResized(Window.getClientHeight());
444
				return false;
445
			}
446
		});
447
        
421
                return false;
422
            }
423
        });
424

  
448 425
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
449 426
            @Override
450 427
            public void execute() {
451 428
                fetchAccount(new Command() {
452
					
453
					@Override
454
					public void execute() {
455
		                if (!account.hasHomeContainer())
456
		                    createHomeContainer(account, this);
457
		                else if (!account.hasTrashContainer())
458
		                	createTrashContainer(this);
459
		                else {
460
		                	for (Folder f : account.getContainers())
461
		                		if (f.getName().equals(Pithos.TRASH_CONTAINER)) {
462
		                			trash = f;
463
		                			break;
464
		                		}
465
		                    trees.add(folderTreeView);
466
		                    folderTreeViewModel.initialize(account, new Command() {
467
								
468
								@Override
469
								public void execute() {
470
				                    createMySharedTree();
471
								}
472
							});
473

  
474
		                    HorizontalPanel separator = new HorizontalPanel();
475
		                    separator.addStyleName("pithos-statisticsSeparator");
476
		                    separator.add(new HTML(""));
477
		                    trees.add(separator);
478

  
479
		                    groupTreeViewModel = new GroupTreeViewModel(Pithos.this);
480
		                    groupTreeView = new GroupTreeView(groupTreeViewModel);
481
		                    treeViews.add(groupTreeView);
482
		                    trees.add(groupTreeView);
483
		                    folderTreeView.showStatistics(account);
484
		                }
485
					}
486
				});
429

  
430
                    @Override
431
                    public void execute() {
432
                        if(!account.hasHomeContainer()) {
433
                            createHomeContainer(account, this);
434
                        }
435
                        else if(!account.hasTrashContainer()) {
436
                            createTrashContainer(this);
437
                        }
438
                        else {
439
                            for(Folder f : account.getContainers()) {
440
                                if(f.getName().equals(Pithos.TRASH_CONTAINER)) {
441
                                    trash = f;
442
                                    break;
443
                                }
444
                            }
445
                            trees.add(folderTreeView);
446
                            folderTreeViewModel.initialize(account, new Command() {
447

  
448
                                @Override
449
                                public void execute() {
450
                                    createMySharedTree();
451
                                }
452
                            });
453

  
454
                            HorizontalPanel separator = new HorizontalPanel();
455
                            separator.addStyleName("pithos-statisticsSeparator");
456
                            separator.add(new HTML(""));
457
                            trees.add(separator);
458

  
459
                            groupTreeViewModel = new GroupTreeViewModel(Pithos.this);
460
                            groupTreeView = new GroupTreeView(groupTreeViewModel);
461
                            treeViews.add(groupTreeView);
462
                            trees.add(groupTreeView);
463
                            folderTreeView.showStatistics(account);
464
                        }
465
                    }
466
                });
487 467
            }
488 468
        });
489 469
    }
490
    
470

  
491 471
    public void scheduleResfresh() {
492
		Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
493
			
494
			@Override
495
			public boolean execute() {
496
				final Folder f = getSelection();
497
				if (f == null)
498
					return true;
499
				
500
		    	HeadRequest<Folder> head = new HeadRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer()) {
501

  
502
					@Override
503
					public void onSuccess(Folder _result) {
504
						lastModified = new Date();
505
						if (getSelectedTree().equals(folderTreeView))
506
							updateFolder(f, true, new Command() {
507
	
508
								@Override
509
								public void execute() {
510
									scheduleResfresh();
511
								}
512
								
513
							}, false);
514
						else if (getSelectedTree().equals(mysharedTreeView))
515
							updateSharedFolder(f, true, new Command() {
516
	
517
								@Override
518
								public void execute() {
519
									scheduleResfresh();
520
								}
521
							});
522
						else
523
							scheduleResfresh();
524
					}
525

  
526
					@Override
527
					public void onError(Throwable t) {
528
						if (t instanceof RestException && ((RestException) t).getHttpStatusCode() == HttpStatus.SC_NOT_MODIFIED)
529
							scheduleResfresh();
530
						else if (retries >= MAX_RETRIES) {
531
			                GWT.log("Error heading folder", t);
532
							setError(t);
533
			                if (t instanceof RestException)
534
			                    displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
535
			                else
536
			                    displayError("System error heading folder: " + t.getMessage());
537
		            	}
538
		            	else {//retry
539
		            		GWT.log("Retry " + retries);
540
		            		Scheduler.get().scheduleDeferred(this);
541
		            	}
542
					}
543

  
544
					@Override
545
					protected void onUnauthorized(Response response) {
546
						if (retries >= MAX_RETRIES)
547
							sessionExpired();
548
		            	else //retry
549
		            		Scheduler.get().scheduleDeferred(this);
550
					}
551
				};
552
				head.setHeader("X-Auth-Token", getToken());
553
				head.setHeader("If-Modified-Since", DateTimeFormat.getFormat("EEE, dd MMM yyyy HH:mm:ss").format(lastModified, TimeZone.createTimeZone(0)) + " GMT");
554
				Scheduler.get().scheduleDeferred(head);
555
				
556
				return false;
557
			}
558
		}, 3000);
472
        Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
473

  
474
            @Override
475
            public boolean execute() {
476
                final Folder f = getSelection();
477
                if(f == null) {
478
                    return true;
479
                }
480

  
481
                HeadRequest<Folder> head = new HeadRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer()) {
482

  
483
                    @Override
484
                    public void onSuccess(Folder _result) {
485
                        lastModified = new Date();
486
                        if(getSelectedTree().equals(folderTreeView)) {
487
                            updateFolder(f, true, new Command() {
488

  
489
                                @Override
490
                                public void execute() {
491
                                    scheduleResfresh();
492
                                }
493

  
494
                            }, false);
495
                        }
496
                        else if(getSelectedTree().equals(mysharedTreeView)) {
497
                            updateSharedFolder(f, true, new Command() {
498

  
499
                                @Override
500
                                public void execute() {
501
                                    scheduleResfresh();
502
                                }
503
                            });
504
                        }
505
                        else {
506
                            scheduleResfresh();
507
                        }
508
                    }
509

  
510
                    @Override
511
                    public void onError(Throwable t) {
512
                        if(t instanceof RestException && ((RestException) t).getHttpStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
513
                            scheduleResfresh();
514
                        }
515
                        else if(retries >= MAX_RETRIES) {
516
                            GWT.log("Error heading folder", t);
517
                            setError(t);
518
                            if(t instanceof RestException) {
519
                                displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
520
                            }
521
                            else {
522
                                displayError("System error heading folder: " + t.getMessage());
523
                            }
524
                        }
525
                        else {//retry
526
                            GWT.log("Retry " + retries);
527
                            Scheduler.get().scheduleDeferred(this);
528
                        }
529
                    }
530

  
531
                    @Override
532
                    protected void onUnauthorized(Response response) {
533
                        if(retries >= MAX_RETRIES) {
534
                            sessionExpired();
535
                        }
536
                        else //retry
537
                        {
538
                            Scheduler.get().scheduleDeferred(this);
539
                        }
540
                    }
541
                };
542
                head.setHeader("X-Auth-Token", getToken());
543
                head.setHeader("If-Modified-Since", DateTimeFormat.getFormat("EEE, dd MMM yyyy HH:mm:ss").format(lastModified, TimeZone.createTimeZone(0)) + " GMT");
544
                Scheduler.get().scheduleDeferred(head);
545

  
546
                return false;
547
            }
548
        }, 3000);
559 549
    }
560 550

  
561 551
    public void applyPermissions(Folder f) {
562
    	if (f != null) {
563
    		if (f.isInTrash()) {
564
    			upload.setEnabled(false);
565
    			disableUploadArea();
566
    		}
567
    		else {
568
		    	Boolean[] perms = f.getPermissions().get(username);
569
		    	if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) {
570
		    		upload.setEnabled(true);
571
		    		enableUploadArea();
572
		    	}
573
		    	else {
574
		    		upload.setEnabled(false);
575
		    		disableUploadArea();
576
		    	}
577
    		}
578
    	}
579
    	else {
580
    		upload.setEnabled(false);
581
    		disableUploadArea();
582
    	}
583
	}
584

  
585
	@SuppressWarnings({ "rawtypes", "unchecked" })
586
	public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) {
587
    	selectedTree = _selectedTree;
588
    	
589
        for (SingleSelectionModel s : selectionModels)
590
            if (!s.equals(model) && s.getSelectedObject() != null)
552
        if(f != null) {
553
            if(f.isInTrash()) {
554
                upload.setEnabled(false);
555
                disableUploadArea();
556
            }
557
            else {
558
                Boolean[] perms = f.getPermissions().get(username);
559
                if(f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) {
560
                    upload.setEnabled(true);
561
                    enableUploadArea();
562
                }
563
                else {
564
                    upload.setEnabled(false);
565
                    disableUploadArea();
566
                }
567
            }
568
        }
569
        else {
570
            upload.setEnabled(false);
571
            disableUploadArea();
572
        }
573
    }
574

  
575
    @SuppressWarnings({"rawtypes", "unchecked"})
576
    public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) {
577
        selectedTree = _selectedTree;
578

  
579
        for(SingleSelectionModel s : selectionModels) {
580
            if(!s.equals(model) && s.getSelectedObject() != null) {
591 581
                s.setSelected(s.getSelectedObject(), false);
582
            }
583
        }
592 584
    }
593 585

  
594 586
    public void showFiles(final Folder f) {
......
601 593
    }
602 594

  
603 595
    /**
604
	 * Parse and store the user credentials to the appropriate fields.
605
	 */
606
	private boolean parseUserCredentials() {
596
     * Parse and store the user credentials to the appropriate fields.
597
     */
598
    private boolean parseUserCredentials() {
607 599
        Configuration conf = (Configuration) GWT.create(Configuration.class);
608
		Dictionary otherProperties = Dictionary.getDictionary("otherProperties");
600
        Dictionary otherProperties = Dictionary.getDictionary("otherProperties");
609 601
        String cookie = otherProperties.get("authCookie");
610 602
        String auth = Cookies.getCookie(cookie);
611
        if (auth == null) {
603
        if(auth == null) {
604
            authenticateUser();
605
            return false;
606
        }
607
        if(auth.startsWith("\"")) {
608
            auth = auth.substring(1);
609
        }
610
        if(auth.endsWith("\"")) {
611
            auth = auth.substring(0, auth.length() - 1);
612
        }
613
        String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
614
        if(authSplit.length != 2) {
612 615
            authenticateUser();
613 616
            return false;
614 617
        }
615
        if (auth.startsWith("\""))
616
        	auth = auth.substring(1);
617
        if (auth.endsWith("\""))
618
        	auth = auth.substring(0, auth.length() - 1);
619
		String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
620
		if (authSplit.length != 2) {
621
		    authenticateUser();
622
		    return false;
623
		}
624
		username = authSplit[0];
625
		token = authSplit[1];
618
        username = authSplit[0];
619
        token = authSplit[1];
626 620

  
627 621
        String gotoUrl = Window.Location.getParameter("goto");
628
		if (gotoUrl != null && gotoUrl.length() > 0) {
629
			Window.Location.assign(gotoUrl);
630
			return false;
631
		}
632
		return true;
622
        if(gotoUrl != null && gotoUrl.length() > 0) {
623
            Window.Location.assign(gotoUrl);
624
            return false;
625
        }
626
        return true;
633 627
    }
634 628

  
635 629
    /**
636
	 * Redirect the user to the login page for authentication.
637
	 */
638
	protected void authenticateUser() {
639
		Dictionary otherProperties = Dictionary.getDictionary("otherProperties");
630
     * Redirect the user to the login page for authentication.
631
     */
632
    protected void authenticateUser() {
633
        Dictionary otherProperties = Dictionary.getDictionary("otherProperties");
640 634
        Window.Location.assign(otherProperties.get("loginUrl") + Window.Location.getHref());
641
	}
635
    }
642 636

  
643
	public void fetchAccount(final Command callback) {
637
    public void fetchAccount(final Command callback) {
644 638
        String path = "?format=json";
645 639

  
646 640
        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
647 641
            @Override
648 642
            public void onSuccess(AccountResource _result) {
649 643
                account = _result;
650
                if (callback != null)
651
                	callback.execute();
644
                if(callback != null) {
645
                    callback.execute();
646
                }
652 647
            }
653 648

  
654 649
            @Override
655 650
            public void onError(Throwable t) {
656 651
                GWT.log("Error getting account", t);
657
				setError(t);
658
                if (t instanceof RestException)
652
                setError(t);
653
                if(t instanceof RestException) {
659 654
                    displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
660
                else
655
                }
656
                else {
661 657
                    displayError("System error fetching user data: " + t.getMessage());
658
                }
662 659
            }
663 660

  
664
			@Override
665
			protected void onUnauthorized(Response response) {
666
				sessionExpired();
667
			}
661
            @Override
662
            protected void onUnauthorized(Response response) {
663
                sessionExpired();
664
            }
668 665
        };
669 666
        getAccount.setHeader("X-Auth-Token", token);
670 667
        Scheduler.get().scheduleDeferred(getAccount);
671 668
    }
672 669

  
673 670
    public void updateStatistics() {
674
    	HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) {
671
        HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) {
675 672

  
676
			@Override
677
			public void onSuccess(AccountResource _result) {
678
				folderTreeView.showStatistics(account);
679
			}
673
            @Override
674
            public void onSuccess(AccountResource _result) {
675
                folderTreeView.showStatistics(account);
676
            }
680 677

  
681
			@Override
682
			public void onError(Throwable t) {
678
            @Override
679
            public void onError(Throwable t) {
683 680
                GWT.log("Error getting account", t);
684
				setError(t);
685
                if (t instanceof RestException)
681
                setError(t);
682
                if(t instanceof RestException) {
686 683
                    displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
687
                else
684
                }
685
                else {
688 686
                    displayError("System error fetching user data: " + t.getMessage());
689
			}
690

  
691
			@Override
692
			protected void onUnauthorized(Response response) {
693
				sessionExpired();
694
			}
695
		};
696
		headAccount.setHeader("X-Auth-Token", token);
697
		Scheduler.get().scheduleDeferred(headAccount);
698
	}
699

  
700
	protected void createHomeContainer(final AccountResource _account, final Command callback) {
687
                }
688
            }
689

  
690
            @Override
691
            protected void onUnauthorized(Response response) {
692
                sessionExpired();
693
            }
694
        };
695
        headAccount.setHeader("X-Auth-Token", token);
696
        Scheduler.get().scheduleDeferred(headAccount);
697
    }
698

  
699
    protected void createHomeContainer(final AccountResource _account, final Command callback) {
701 700
        String path = "/" + Pithos.HOME_CONTAINER;
702 701
        PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
703 702
            @Override
704 703
            public void onSuccess(Resource result) {
705
            	if (!_account.hasTrashContainer())
706
            		createTrashContainer(callback);
707
            	else
708
            		fetchAccount(callback);
704
                if(!_account.hasTrashContainer()) {
705
                    createTrashContainer(callback);
706
                }
707
                else {
708
                    fetchAccount(callback);
709
                }
709 710
            }
710 711

  
711 712
            @Override
712 713
            public void onError(Throwable t) {
713 714
                GWT.log("Error creating pithos", t);
714
				setError(t);
715
                if (t instanceof RestException)
715
                setError(t);
716
                if(t instanceof RestException) {
716 717
                    displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
717
                else
718
                }
719
                else {
718 720
                    displayError("System error Error creating pithos: " + t.getMessage());
721
                }
719 722
            }
720 723

  
721
			@Override
722
			protected void onUnauthorized(Response response) {
723
				sessionExpired();
724
			}
724
            @Override
725
            protected void onUnauthorized(Response response) {
726
                sessionExpired();
727
            }
725 728
        };
726 729
        createPithos.setHeader("X-Auth-Token", getToken());
727 730
        Scheduler.get().scheduleDeferred(createPithos);
......
732 735
        PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
733 736
            @Override
734 737
            public void onSuccess(Resource result) {
735
           		fetchAccount(callback);
738
                fetchAccount(callback);
736 739
            }
737 740

  
738 741
            @Override
739 742
            public void onError(Throwable t) {
740 743
                GWT.log("Error creating pithos", t);
741
				setError(t);
742
                if (t instanceof RestException)
744
                setError(t);
745
                if(t instanceof RestException) {
743 746
                    displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
744
                else
747
                }
748
                else {
745 749
                    displayError("System error Error creating pithos: " + t.getMessage());
750
                }
746 751
            }
747 752

  
748
			@Override
749
			protected void onUnauthorized(Response response) {
750
				sessionExpired();
751
			}
753
            @Override
754
            protected void onUnauthorized(Response response) {
755
                sessionExpired();
756
            }
752 757
        };
753 758
        createPithos.setHeader("X-Auth-Token", getToken());
754 759
        Scheduler.get().scheduleDeferred(createPithos);
755 760
    }
756 761

  
757 762
    /**
758
	 * Creates an HTML fragment that places an image & caption together, for use
759
	 * in a group header.
760
	 *
761
	 * @param imageProto an image prototype for an image
762
	 * @param caption the group caption
763
	 * @return the header HTML fragment
764
	 */
765
	private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
766
		String captionHTML = "<table class='caption' cellpadding='0' " 
767
		+ "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() 
768
		+ "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'>&nbsp;" 
769
		+ caption + "</b></td></tr></table>";
770
		return captionHTML;
771
	}
772

  
773
	protected void onWindowResized(int height) {
774
		// Adjust the split panel to take up the available room in the window.
775
		int newHeight = height - splitPanel.getAbsoluteTop() - 153;
776
		if (newHeight < 1)
777
			newHeight = 1;
778
		splitPanel.setHeight("" + newHeight);
779
		inner.setHeight("" + newHeight);
780
	}
781
	
782
	native boolean isCloudbarReady()/*-{
783
		if ($wnd.$("div.cloudbar") && $wnd.$("div.cloudbar").height() > 0)
784
			return true;
785
		return false;
786
	}-*/;
787
	
788
	@Override
789
	public void onResize(ResizeEvent event) {
790
		int height = event.getHeight();
791
		onWindowResized(height);
792
	}
793

  
794
	/**
795
	 * Display an error message.
796
	 *
797
	 * @param msg the message to display
798
	 */
799
	public void displayError(String msg) {
800
		messagePanel.displayError(msg);
801
		onWindowResized(Window.getClientHeight());
802
	}
803

  
804
	/**
805
	 * Display a warning message.
806
	 *
807
	 * @param msg the message to display
808
	 */
809
	public void displayWarning(String msg) {
810
		messagePanel.displayWarning(msg);
811
		onWindowResized(Window.getClientHeight());
812
	}
813

  
814
	/**
815
	 * Display an informational message.
816
	 *
817
	 * @param msg the message to display
818
	 */
819
	public void displayInformation(String msg) {
820
		messagePanel.displayInformation(msg);
821
		onWindowResized(Window.getClientHeight());
822
	}
823

  
824
	/**
825
	 * Retrieve the fileList.
826
	 *
827
	 * @return the fileList
828
	 */
829
	public FileList getFileList() {
830
		return fileList;
831
	}
832

  
833
	/**
834
	 * Retrieve the topPanel.
835
	 *
836
	 * @return the topPanel
837
	 */
838
	TopPanel getTopPanel() {
839
		return topPanel;
840
	}
841

  
842
	/**
843
	 * Retrieve the clipboard.
844
	 *
845
	 * @return the clipboard
846
	 */
847
	public Clipboard getClipboard() {
848
		return clipboard;
849
	}
850

  
851
	public StatusPanel getStatusPanel() {
852
		return statusPanel;
853
	}
854

  
855
	public String getToken() {
856
		return token;
857
	}
858

  
859
	public static native void preventIESelection() /*-{
860
		$doc.body.onselectstart = function() {
861
			return false;
862
		};
863
	}-*/;
864

  
865
	public static native void enableIESelection() /*-{
866
		if ($doc.body.onselectstart != null)
867
			$doc.body.onselectstart = null;
868
	}-*/;
869

  
870
	/**
871
	 * @return the absolute path of the API root URL
872
	 */
873
	public String getApiPath() {
874
		Configuration conf = (Configuration) GWT.create(Configuration.class);
875
		return conf.apiPath();
876
	}
877

  
878
	/**
879
	 * History support for folder navigation
880
	 * adds a new browser history entry
881
	 *
882
	 * @param key
883
	 */
884
	public void updateHistory(String key){
763
     * Creates an HTML fragment that places an image & caption together, for use
764
     * in a group header.
765
     *
766
     * @param imageProto an image prototype for an image
767
     * @param caption    the group caption
768
     * @return the header HTML fragment
769
     */
770
    private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
771
        String captionHTML = "<table class='caption' cellpadding='0' "
772
            + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML()
773
            + "</td><td id =" + caption + " class='rcaption'><b style='white-space:nowrap'>&nbsp;"
774
            + caption + "</b></td></tr></table>";
775
        return captionHTML;
776
    }
777

  
778
    protected void onWindowResized(int height) {
779
        // Adjust the split panel to take up the available room in the window.
780
        int newHeight = height - splitPanel.getAbsoluteTop() - 153;
781
        if(newHeight < 1) {
782
            newHeight = 1;
783
        }
784
        splitPanel.setHeight("" + newHeight);
785
        inner.setHeight("" + newHeight);
786
    }
787

  
788
    native boolean isCloudbarReady()/*-{
789
      if ($wnd.$("div.cloudbar") && $wnd.$("div.cloudbar").height() > 0)
790
        return true;
791
      return false;
792
    }-*/;
793

  
794
    @Override
795
    public void onResize(ResizeEvent event) {
796
        int height = event.getHeight();
797
        onWindowResized(height);
798
    }
799

  
800
    /**
801
     * Display an error message.
802
     *
803
     * @param msg the message to display
804
     */
805
    public void displayError(String msg) {
806
        messagePanel.displayError(msg);
807
        onWindowResized(Window.getClientHeight());
808
    }
809

  
810
    /**
811
     * Display a warning message.
812
     *
813
     * @param msg the message to display
814
     */
815
    public void displayWarning(String msg) {
816
        messagePanel.displayWarning(msg);
817
        onWindowResized(Window.getClientHeight());
818
    }
819

  
820
    /**
821
     * Display an informational message.
822
     *
823
     * @param msg the message to display
824
     */
825
    public void displayInformation(String msg) {
826
        messagePanel.displayInformation(msg);
827
        onWindowResized(Window.getClientHeight());
828
    }
829

  
830
    /**
831
     * Retrieve the fileList.
832
     *
833
     * @return the fileList
834
     */
835
    public FileList getFileList() {
836
        return fileList;
837
    }
838

  
839
    /**
840
     * Retrieve the topPanel.
841
     *
842
     * @return the topPanel
843
     */
844
    TopPanel getTopPanel() {
845
        return topPanel;
846
    }
847

  
848
    /**
849
     * Retrieve the clipboard.
850
     *
851
     * @return the clipboard
852
     */
853
    public Clipboard getClipboard() {
854
        return clipboard;
855
    }
856

  
857
    public StatusPanel getStatusPanel() {
858
        return statusPanel;
859
    }
860

  
861
    public String getToken() {
862
        return token;
863
    }
864

  
865
    public static native void preventIESelection() /*-{
866
      $doc.body.onselectstart = function () {
867
        return false;
868
      };
869
    }-*/;
870

  
871
    public static native void enableIESelection() /*-{
872
      if ($doc.body.onselectstart != null)
873
        $doc.body.onselectstart = null;
874
    }-*/;
875

  
876
    /**
877
     * @return the absolute path of the API root URL
878
     */
879
    public String getApiPath() {
880
        Configuration conf = (Configuration) GWT.create(Configuration.class);
881
        return conf.apiPath();
882
    }
883

  
884
    /**
885
     * History support for folder navigation
886
     * adds a new browser history entry
887
     *
888
     * @param key
889
     */
890
    public void updateHistory(String key) {
885 891
//		Replace any whitespace of the initial string to "+"
886 892
//		String result = key.replaceAll("\\s","+");
887 893
//		Add a new browser history entry.
888 894
//		History.newItem(result);
889
		History.newItem(key);
890
	}
895
        History.newItem(key);
896
    }
891 897

  
892 898
    public void deleteFolder(final Folder folder, final Command callback) {
893
    	final PleaseWaitPopup pwp = new PleaseWaitPopup();
894
    	pwp.center();
899
        final PleaseWaitPopup pwp = new PleaseWaitPopup();
900
        pwp.center();
895 901
        String path = "/" + folder.getContainer() + "/" + folder.getPrefix() + "?delimiter=/" + "&t=" + System.currentTimeMillis();
896 902
        DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), folder.getOwner(), path) {
897
			
898
			@Override
899
			protected void onUnauthorized(Response response) {
900
				pwp.hide();
901
				sessionExpired();
902
			}
903
			
904
			@Override
905
			public void onSuccess(Resource result) {
903

  
904
            @Override
905
            protected void onUnauthorized(Response response) {
906
                pwp.hide();
907
                sessionExpired();
908
            }
909

  
910
            @Override
911
            public void onSuccess(Resource result) {
906 912
                updateFolder(folder.getParent(), true, new Command() {
907
					
908
					@Override
909
					public void execute() {
910
						folderTreeSelectionModel.setSelected(folder.getParent(), true);
911
						updateStatistics();
912
						if (callback != null)
913
							callback.execute();
914
						pwp.hide();
915
					}
916
				}, true);
917
			}
918
			
919
			@Override
920
			public void onError(Throwable t) {
913

  
914
                    @Override
915
                    public void execute() {
916
                        folderTreeSelectionModel.setSelected(folder.getParent(), true);
917
                        updateStatistics();
918
                        if(callback != null) {
919
                            callback.execute();
920
                        }
921
                        pwp.hide();
922
                    }
923
                }, true);
924
            }
925

  
926
            @Override
927
            public void onError(Throwable t) {
921 928
                GWT.log("", t);
922
				setError(t);
923
                if (t instanceof RestException) {
924
                	if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND)
925
                		displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
926
                	else
927
                		onSuccess(null);
929
                setError(t);
930
                if(t instanceof RestException) {
931
                    if(((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND) {
932
                        displayError("Unable to delete folder: " + ((RestException) t).getHttpStatusText());
933
                    }
934
                    else {
935
                        onSuccess(null);
936
                    }
928 937
                }
929
                else
938
                else {
930 939
                    displayError("System error unable to delete folder: " + t.getMessage());
931
				pwp.hide();
932
			}
933
		};
934
		deleteFolder.setHeader("X-Auth-Token", getToken());
935
		Scheduler.get().scheduleDeferred(deleteFolder);
940
                }
941
                pwp.hide();
942
            }
943
        };
944
        deleteFolder.setHeader("X-Auth-Token", getToken());
945
        Scheduler.get().scheduleDeferred(deleteFolder);
936 946
    }
937 947

  
938 948
    public FolderTreeView getFolderTreeView() {
......
940 950
    }
941 951

  
942 952
    public void copyFiles(final Iterator<File> iter, final String targetUsername, final String targetUri, final Command callback) {
943
        if (iter.hasNext()) {
953
        if(iter.hasNext()) {
944 954
            File file = iter.next();
945 955
            String path = targetUri + "/" + file.getName();
946 956
            PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
......
952 962
                @Override
953 963
                public void onError(Throwable t) {
954 964
                    GWT.log("", t);
955
					setError(t);
956
                    if (t instanceof RestException) {
965
                    setError(t);
966
                    if(t instanceof RestException) {
957 967
                        displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
958 968
                    }
959
                    else
960
                        displayError("System error unable to copy file: "+t.getMessage());
969
                    else {
970
                        displayError("System error unable to copy file: " + t.getMessage());
971
                    }
961 972
                }
962 973

  
963
				@Override
964
				protected void onUnauthorized(Response response) {
965
					sessionExpired();
966
				}
974
                @Override
975
                protected void onUnauthorized(Response response) {
976
                    sessionExpired();
977
                }
967 978
            };
968 979
            copyFile.setHeader("X-Auth-Token", getToken());
969 980
            copyFile.setHeader("X-Copy-From", URL.encodePathSegment(file.getUri()));
970
            if (!file.getOwner().equals(targetUsername))
971
            	copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner()));
981
            if(!file.getOwner().equals(targetUsername)) {
982
                copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner()));
983
            }
972 984
            copyFile.setHeader("Content-Type", file.getContentType());
973 985
            Scheduler.get().scheduleDeferred(copyFile);
974 986
        }
975
        else  if (callback != null) {
987
        else if(callback != null) {
976 988
            callback.execute();
977 989
        }
978 990
    }
......
982 994
        PutRequest copyFolder = new PutRequest(getApiPath(), targetUsername, path) {
983 995
            @Override
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff