First implementation of public permission setting
[pithos-web-client] / src / gr / grnet / pithos / web / client / FilePropertiesDialog.java
1 /*\r
2  * Copyright 2011 GRNET S.A. All rights reserved.\r
3  *\r
4  * Redistribution and use in source and binary forms, with or\r
5  * without modification, are permitted provided that the following\r
6  * conditions are met:\r
7  *\r
8  *   1. Redistributions of source code must retain the above\r
9  *      copyright notice, this list of conditions and the following\r
10  *      disclaimer.\r
11  *\r
12  *   2. Redistributions in binary form must reproduce the above\r
13  *      copyright notice, this list of conditions and the following\r
14  *      disclaimer in the documentation and/or other materials\r
15  *      provided with the distribution.\r
16  *\r
17  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
24  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
28  * POSSIBILITY OF SUCH DAMAGE.\r
29  *\r
30  * The views and conclusions contained in the software and\r
31  * documentation are those of the authors and should not be\r
32  * interpreted as representing official policies, either expressed\r
33  * or implied, of GRNET S.A.\r
34  */\r
35 package gr.grnet.pithos.web.client;\r
36 \r
37 import com.google.gwt.core.client.Scheduler;\r
38 import com.google.gwt.json.client.JSONArray;\r
39 import com.google.gwt.json.client.JSONString;\r
40 import com.google.gwt.user.client.ui.Anchor;\r
41 import com.google.gwt.user.client.ui.Label;\r
42 import gr.grnet.pithos.web.client.foldertree.File;\r
43 import gr.grnet.pithos.web.client.foldertree.Resource;\r
44 import gr.grnet.pithos.web.client.rest.PostCommand;\r
45 import gr.grnet.pithos.web.client.rest.PostRequest;\r
46 import gr.grnet.pithos.web.client.rest.PutRequest;\r
47 import gr.grnet.pithos.web.client.rest.RestException;\r
48 \r
49 import com.google.gwt.core.client.GWT;\r
50 import com.google.gwt.event.dom.client.ClickEvent;\r
51 import com.google.gwt.event.dom.client.ClickHandler;\r
52 import com.google.gwt.i18n.client.DateTimeFormat;\r
53 import com.google.gwt.json.client.JSONBoolean;\r
54 import com.google.gwt.json.client.JSONObject;\r
55 import com.google.gwt.resources.client.ClientBundle;\r
56 import com.google.gwt.resources.client.ImageResource;\r
57 import com.google.gwt.user.client.Command;\r
58 import com.google.gwt.user.client.DeferredCommand;\r
59 import com.google.gwt.user.client.ui.Button;\r
60 import com.google.gwt.user.client.ui.CheckBox;\r
61 import com.google.gwt.user.client.ui.DecoratedTabPanel;\r
62 import com.google.gwt.user.client.ui.DisclosurePanel;\r
63 import com.google.gwt.user.client.ui.FlexTable;\r
64 import com.google.gwt.user.client.ui.FlowPanel;\r
65 import com.google.gwt.user.client.ui.FocusPanel;\r
66 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
67 import com.google.gwt.user.client.ui.HorizontalPanel;\r
68 import com.google.gwt.user.client.ui.TextBox;\r
69 import com.google.gwt.user.client.ui.VerticalPanel;\r
70 import gr.grnet.pithos.web.client.tagtree.Tag;\r
71 import java.util.Iterator;\r
72 \r
73 /**\r
74  * The 'File properties' dialog box implementation.\r
75  *\r
76  */\r
77 public class FilePropertiesDialog extends AbstractPropertiesDialog {\r
78 \r
79         private PermissionsList permList;\r
80 \r
81         private CheckBox readForAll;\r
82 \r
83         /**\r
84          * An image bundle for this widgets images.\r
85          */\r
86         public interface Images extends ClientBundle,MessagePanel.Images {\r
87 \r
88                 @Source("gr/grnet/pithos/resources/edit_user.png")\r
89                 ImageResource permUser();\r
90 \r
91                 @Source("gr/grnet/pithos/resources/groupevent.png")\r
92                 ImageResource permGroup();\r
93 \r
94                 @Source("gr/grnet/pithos/resources/editdelete.png")\r
95                 ImageResource delete();\r
96 \r
97                 @Source("gr/grnet/pithos/resources/db_update.png")\r
98                 ImageResource restore();\r
99 \r
100                 @Source("gr/grnet/pithos/resources/folder_inbox.png")\r
101                 ImageResource download();\r
102         }\r
103 \r
104         /**\r
105          * The widget that holds the name of the file.\r
106          */\r
107         private TextBox name = new TextBox();\r
108 \r
109         private final CheckBox versioned = new CheckBox();\r
110 \r
111         final File file;\r
112 \r
113         private String userFullName;\r
114 \r
115     private Pithos app;\r
116 \r
117         /**\r
118          * The widget's constructor.\r
119          */\r
120         public FilePropertiesDialog(Pithos _app, File _file) {\r
121         app = _app;\r
122         file = _file;\r
123 \r
124                 // Set the dialog's caption.\r
125                 setText("File properties");\r
126 \r
127 \r
128 //              permList = new PermissionsList(images, file.getPermissions(), file.getOwner());\r
129 \r
130                 // Outer contains inner and buttons.\r
131                 final VerticalPanel outer = new VerticalPanel();\r
132                 final FocusPanel focusPanel = new FocusPanel(outer);\r
133                 // Inner contains generalPanel and permPanel.\r
134                 inner = new DecoratedTabPanel();\r
135                 inner.setAnimationEnabled(true);\r
136 \r
137 \r
138         inner.add(createGeneralPanel(), "General");\r
139 \r
140         inner.add(createSharingPanel(), "Sharing");\r
141 \r
142         inner.add(createVersionPanel(), "Versions");\r
143 \r
144         inner.selectTab(0);\r
145 \r
146         outer.add(inner);\r
147 \r
148                 final HorizontalPanel buttons = new HorizontalPanel();\r
149                 // Create the 'OK' button, along with a listener that hides the dialog\r
150                 // when the button is clicked.\r
151                 final Button ok = new Button("OK", new ClickHandler() {\r
152                         @Override\r
153                         public void onClick(ClickEvent event) {\r
154                                 accept();\r
155                                 closeDialog();\r
156                         }\r
157                 });\r
158 \r
159                 buttons.add(ok);\r
160                 buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);\r
161                 // Create the 'Cancel' button, along with a listener that hides the\r
162                 // dialog when the button is clicked.\r
163                 final Button cancel = new Button("Cancel", new ClickHandler() {\r
164                         @Override\r
165                         public void onClick(ClickEvent event) {\r
166                                 closeDialog();\r
167                         }\r
168                 });\r
169                 buttons.add(cancel);\r
170                 buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
171                 buttons.setSpacing(8);\r
172                 buttons.addStyleName("pithos-TabPanelBottom");\r
173 \r
174         outer.add(buttons);\r
175         outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
176         outer.addStyleName("pithos-TabPanelBottom");\r
177 \r
178         focusPanel.setFocus(true);\r
179         setWidget(outer);\r
180         }\r
181 \r
182     private VerticalPanel createGeneralPanel() {\r
183         final VerticalPanel generalPanel = new VerticalPanel();\r
184         final FlexTable generalTable = new FlexTable();\r
185         generalTable.setText(0, 0, "Name");\r
186         generalTable.setText(1, 0, "Folder");\r
187         generalTable.setText(2, 0, "Owner");\r
188         generalTable.setText(3, 0, "Last modified");\r
189         generalTable.setText(4, 0, "Tags");\r
190 \r
191         name.setWidth("100%");\r
192         name.setText(file.getName());\r
193         generalTable.setWidget(0, 1, name);\r
194         if(file.getParent() != null)\r
195             generalTable.setText(1, 1, file.getParent().getName());\r
196         else\r
197             generalTable.setText(1, 1, "-");\r
198         generalTable.setText(2, 1, file.getOwner());\r
199 \r
200         final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
201         generalTable.setText(3, 1, formatter.format(file.getLastModified()));\r
202 \r
203                 StringBuffer tagsBuffer = new StringBuffer();\r
204         for (String t : file.getTags())\r
205                         tagsBuffer.append(t).append(", ");\r
206                 if (tagsBuffer.length() > 1)\r
207                         tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);\r
208                 initialTagText = tagsBuffer.toString();\r
209                 tags.setWidth("100%");\r
210                 tags.setText(initialTagText);\r
211                 generalTable.setWidget(4, 1, tags);\r
212 \r
213         generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
214         generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");\r
215         generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");\r
216         generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");\r
217         generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");\r
218         generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");\r
219         generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");\r
220         generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");\r
221         generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");\r
222         generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");\r
223         generalTable.setCellSpacing(4);\r
224 \r
225         generalPanel.add(generalTable);\r
226 \r
227         DisclosurePanel allTags = new DisclosurePanel("All tags");\r
228         allTagsContent = new FlowPanel();\r
229         allTagsContent.setWidth("100%");\r
230         for (Tag t : app.getAllTags()) {\r
231             final Anchor tagAnchor = new Anchor(t.getName(), false);\r
232             tagAnchor.addStyleName("pithos-tag");\r
233             allTagsContent.add(tagAnchor);\r
234             Label separator = new Label(", ");\r
235             separator.addStyleName("pithos-tag");\r
236             allTagsContent.add(separator);\r
237             tagAnchor.addClickHandler(new ClickHandler() {\r
238 \r
239                 @Override\r
240                 public void onClick(ClickEvent event) {\r
241                     String existing = tags.getText().trim();\r
242                     if (MULTIPLE_VALUES_TEXT.equals(existing))\r
243                         existing = "";\r
244                     String newTag = tagAnchor.getText().trim();\r
245                     // insert the new tag only if it is not in the list\r
246                     // already\r
247                     if (existing.indexOf(newTag) == -1)\r
248                         tags.setText(existing + (existing.length() > 0 ? ", " : "") + newTag);\r
249                 }\r
250             });\r
251         }\r
252         allTags.setContent(allTagsContent);\r
253         generalPanel.add(allTags);\r
254         generalPanel.setSpacing(4);\r
255         return generalPanel;\r
256     }\r
257 \r
258     private VerticalPanel createSharingPanel() {\r
259         VerticalPanel permPanel = new VerticalPanel();\r
260 //\r
261 //        permList = new PermissionsList(images, file.getPermissions(), file.getOwner());\r
262 //        permPanel.add(permList);\r
263 //\r
264 //        HorizontalPanel permButtons = new HorizontalPanel();\r
265 //        Button add = new Button("Add Group", new ClickHandler() {\r
266 //            @Override\r
267 //            public void onClick(ClickEvent event) {\r
268 //                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false);\r
269 //                dlg.center();\r
270 //            }\r
271 //        });\r
272 //        permButtons.add(add);\r
273 //        permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);\r
274 //\r
275 //        final Button addUser = new Button("Add User", new ClickHandler() {\r
276 //            @Override\r
277 //            public void onClick(ClickEvent event) {\r
278 //                PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true);\r
279 //                dlg.center();\r
280 //            }\r
281 //        });\r
282 //        permButtons.add(addUser);\r
283 //        permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);\r
284 //\r
285 //        permButtons.setSpacing(8);\r
286 //        permButtons.addStyleName("pithos-TabPanelBottom");\r
287 //        permPanel.add(permButtons);\r
288 //\r
289         final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +\r
290                     " by everyone. By checking this option, you are certifying that you have the right to " +\r
291                     "distribute this file and that it does not violate the Terms of Use.", true);\r
292         readForAllNote.setVisible(false);\r
293         readForAllNote.setStylePrimaryName("pithos-readForAllNote");\r
294 \r
295         readForAll = new CheckBox();\r
296         readForAll.setValue(file.isPublished());\r
297         readForAll.addClickHandler(new ClickHandler() {\r
298             @Override\r
299             public void onClick(ClickEvent event) {\r
300                 readForAllNote.setVisible(readForAll.getValue());\r
301             }\r
302         });\r
303 \r
304         // Only show the read for all permission if the user is the owner.\r
305         if (file.getOwner().equals(app.getUsername())) {\r
306             final HorizontalPanel permForAll = new HorizontalPanel();\r
307             permForAll.add(new Label("Public"));\r
308             permForAll.add(readForAll);\r
309             permForAll.setSpacing(8);\r
310             permForAll.addStyleName("pithos-TabPanelBottom");\r
311             permForAll.add(readForAllNote);\r
312             permPanel.add(permForAll);\r
313         }\r
314 \r
315         final HorizontalPanel pathPanel = new HorizontalPanel();\r
316         pathPanel.setWidth("100%");\r
317         pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);\r
318         pathPanel.add(new Label("Link"));\r
319         pathPanel.setSpacing(8);\r
320         pathPanel.addStyleName("pithos-TabPanelBottom");\r
321 \r
322         TextBox path = new TextBox();\r
323         path.setWidth("100%");\r
324         path.addClickHandler(new ClickHandler() {\r
325             @Override\r
326             public void onClick(ClickEvent event) {\r
327                 Pithos.enableIESelection();\r
328                 ((TextBox) event.getSource()).selectAll();\r
329                 Pithos.preventIESelection();\r
330             }\r
331         });\r
332         path.setText(file.getUri());\r
333         path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");\r
334         path.setWidth("100%");\r
335         path.setReadOnly(true);\r
336         pathPanel.add(path);\r
337         permPanel.add(pathPanel);\r
338 \r
339         return permPanel;\r
340     }\r
341 \r
342     private VerticalPanel createVersionPanel() {\r
343         VerticalPanel versionPanel = new VerticalPanel();\r
344 \r
345 //        VersionsList verList = new VersionsList(this, images, bodies);\r
346 //        versionPanel.add(verList);\r
347 //\r
348 //        HorizontalPanel vPanel = new HorizontalPanel();\r
349 //\r
350 //              vPanel.setSpacing(8);\r
351 //              vPanel.addStyleName("pithos-TabPanelBottom");\r
352 //              vPanel.add(new Label("Versioned"));\r
353 //\r
354 //              versioned.setValue(file.isVersioned());\r
355 //              vPanel.add(versioned);\r
356 //              versionPanel.add(vPanel);\r
357 //\r
358 //        HorizontalPanel vPanel2 = new HorizontalPanel();\r
359 //              vPanel2.setSpacing(8);\r
360 //              vPanel2.addStyleName("pithos-TabPanelBottom");\r
361 //\r
362 //        HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");\r
363 //        vPanel2.add(removeAllVersion);\r
364 //\r
365 //              Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {\r
366 //                      @Override\r
367 //                      public void onClick(ClickEvent event) {\r
368 //                              ConfirmationDialog confirm = new ConfirmationDialog("Really " +\r
369 //                                              "remove all previous versions?", "Remove") {\r
370 //\r
371 //                                      @Override\r
372 //                                      public void cancel() {\r
373 //                                      }\r
374 //\r
375 //                                      @Override\r
376 //                                      public void confirm() {\r
377 //                                              FilePropertiesDialog.this.closeDialog();\r
378 //                                              removeAllOldVersions();\r
379 //                                      }\r
380 //\r
381 //                              };\r
382 //                              confirm.center();\r
383 //                      }\r
384 //\r
385 //              });\r
386 //              vPanel2.add(removeVersionsButton);\r
387 //        if(!file.isVersioned())\r
388 //            vPanel2.setVisible(false);\r
389 //\r
390 //        versionPanel.add(vPanel2);\r
391 \r
392         return versionPanel;\r
393     }\r
394 \r
395         /**\r
396          * Accepts any change and updates the file\r
397          *\r
398          */\r
399         @Override\r
400         protected void accept() {\r
401                 String newFilename = null;\r
402 //              permList.updatePermissionsAccordingToInput();\r
403 //              Set<PermissionHolder> perms = permList.getPermissions();\r
404 //              JSONObject json = new JSONObject();\r
405                 if (!name.getText().trim().equals(file.getName())) {\r
406                         newFilename = name.getText().trim();\r
407 //                      json.put("name", new JSONString(newFilename));\r
408                 }\r
409 //              if (versioned.getValue() != file.isVersioned())\r
410 //                      json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));\r
411                 //only update the read for all perm if the user is the owner\r
412         Boolean published = null;\r
413                 if (readForAll.getValue() != file.isPublished())\r
414                         if (file.getOwner().equals(Pithos.get().getUsername()))\r
415                 published = readForAll.getValue();\r
416         final Boolean finalPublished = published;\r
417 //                              json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));\r
418 //              int i = 0;\r
419 //              if (permList.hasChanges()) {\r
420 //                      GWT.log("Permissions change", null);\r
421 //                      JSONArray perma = new JSONArray();\r
422 //\r
423 //                      for (PermissionHolder p : perms) {\r
424 //                              JSONObject po = new JSONObject();\r
425 //                              if (p.getUser() != null)\r
426 //                                      po.put("user", new JSONString(p.getUser()));\r
427 //                              if (p.getGroup() != null)\r
428 //                                      po.put("group", new JSONString(p.getGroup()));\r
429 //                              po.put("read", JSONBoolean.getInstance(p.isRead()));\r
430 //                              po.put("write", JSONBoolean.getInstance(p.isWrite()));\r
431 //                              po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));\r
432 //                              perma.set(i, po);\r
433 //                              i++;\r
434 //                      }\r
435 //                      json.put("permissions", perma);\r
436 //              }\r
437         String[] tagset = null;\r
438                 if (!tags.getText().equals(initialTagText))\r
439                         tagset = tags.getText().split(",");\r
440 //              String jsonString = json.toString();\r
441 //              if(jsonString.equals("{}")){\r
442 //                      GWT.log("NO CHANGES", null);\r
443 //                      return;\r
444 //              }\r
445         final String[] newTags = tagset;\r
446 \r
447         if (newFilename != null) {\r
448             final String path = file.getParent().getUri() + "/" + newFilename;\r
449             PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUsername(), path) {\r
450                 @Override\r
451                 public void onSuccess(Resource result) {\r
452                     if (newTags != null || finalPublished != null)\r
453                         updateMetaData(app.getApiPath(), app.getUsername(), path + "?update=", newTags, finalPublished);\r
454                     else\r
455                         app.updateFolder(file.getParent());\r
456                 }\r
457 \r
458                 @Override\r
459                 public void onError(Throwable t) {\r
460                     GWT.log("", t);\r
461                     app.displayError("System error modifying file:" + t.getMessage());\r
462                 }\r
463             };\r
464             updateFile.setHeader("X-Auth-Token", app.getToken());\r
465             updateFile.setHeader("X-Move-From", file.getUri());\r
466             updateFile.setHeader("Content-Type", file.getContentType());\r
467             Scheduler.get().scheduleDeferred(updateFile);\r
468         }\r
469         else if (newTags != null || finalPublished != null)\r
470             updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newTags, finalPublished);\r
471         }\r
472 \r
473     private void updateMetaData(String api, String owner, String path, String[] newTags, Boolean published) {\r
474         PostRequest updateFile = new PostRequest(api, owner, path) {\r
475             @Override\r
476             public void onSuccess(Resource result) {\r
477                 app.updateFolder(file.getParent());\r
478             }\r
479 \r
480             @Override\r
481             public void onError(Throwable t) {\r
482                 GWT.log("", t);\r
483                 app.displayError("System error modifying file:" + t.getMessage());\r
484             }\r
485         };\r
486         updateFile.setHeader("X-Auth-Token", app.getToken());\r
487         if (newTags != null)\r
488             for (String t : newTags)\r
489                 updateFile.setHeader("X-Object-Meta-" + t.trim(), "true");\r
490         if (published != null)\r
491             updateFile.setHeader("X-Object-Public", published.toString());\r
492         Scheduler.get().scheduleDeferred(updateFile);\r
493     }\r
494 \r
495         private void removeAllOldVersions() {\r
496                 JSONObject json = new JSONObject();\r
497                 json.put("versioned", JSONBoolean.getInstance(false));\r
498                 GWT.log(json.toString(), null);\r
499                 PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {\r
500 \r
501                         @Override\r
502                         public void onComplete() {\r
503                                 toggleVersioned(true);\r
504                         }\r
505 \r
506                         @Override\r
507                         public void onError(Throwable t) {\r
508                                 GWT.log("", t);\r
509                                 if (t instanceof RestException) {\r
510                                         int statusCode = ((RestException) t).getHttpStatusCode();\r
511                                         if (statusCode == 405)\r
512                                                 Pithos.get().displayError("You don't have the necessary permissions");\r
513                                         else if (statusCode == 404)\r
514                                                 Pithos.get().displayError("User in permissions does not exist");\r
515                                         else if (statusCode == 409)\r
516                                                 Pithos.get().displayError("A folder with the same name already exists");\r
517                                         else if (statusCode == 413)\r
518                                                 Pithos.get().displayError("Your quota has been exceeded");\r
519                                         else\r
520                                                 Pithos.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
521                                 } else\r
522                                         Pithos.get().displayError("System error moifying file:" + t.getMessage());\r
523                         }\r
524                 };\r
525                 DeferredCommand.addCommand(cf);\r
526         }\r
527 \r
528         private void toggleVersioned(boolean versionedValue) {\r
529                 JSONObject json = new JSONObject();\r
530                 json.put("versioned", JSONBoolean.getInstance(versionedValue));\r
531                 GWT.log(json.toString(), null);\r
532                 PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {\r
533 \r
534                         @Override\r
535                         public void onComplete() {\r
536                                 Pithos.get().getTreeView().refreshCurrentNode(false);\r
537                         }\r
538 \r
539                         @Override\r
540                         public void onError(Throwable t) {\r
541                                 GWT.log("", t);\r
542                                 if (t instanceof RestException) {\r
543                                         int statusCode = ((RestException) t).getHttpStatusCode();\r
544                                         if (statusCode == 405)\r
545                                                 Pithos.get().displayError("You don't have the necessary permissions");\r
546                                         else if (statusCode == 404)\r
547                                                 Pithos.get().displayError("User in permissions does not exist");\r
548                                         else if (statusCode == 409)\r
549                                                 Pithos.get().displayError("A folder with the same name already exists");\r
550                                         else if (statusCode == 413)\r
551                                                 Pithos.get().displayError("Your quota has been exceeded");\r
552                                         else\r
553                                                 Pithos.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
554                                 } else\r
555                                         Pithos.get().displayError("System error moifying file:" + t.getMessage());\r
556                         }\r
557                 };\r
558                 DeferredCommand.addCommand(cf);\r
559         }\r
560 \r
561 }\r