Fixed username in all API calls + some other fixes
[pithos-web-client] / src / gr / grnet / pithos / web / client / FilePropertiesDialog.java
index f483339..d5343a8 100644 (file)
@@ -1,48 +1,62 @@
 /*\r
- * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.\r
+ * Copyright 2011 GRNET S.A. All rights reserved.\r
  *\r
- * This file is part of GSS.\r
+ * Redistribution and use in source and binary forms, with or\r
+ * without modification, are permitted provided that the following\r
+ * conditions are met:\r
  *\r
- * GSS is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
+ *   1. Redistributions of source code must retain the above\r
+ *      copyright notice, this list of conditions and the following\r
+ *      disclaimer.\r
  *\r
- * GSS is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
+ *   2. Redistributions in binary form must reproduce the above\r
+ *      copyright notice, this list of conditions and the following\r
+ *      disclaimer in the documentation and/or other materials\r
+ *      provided with the distribution.\r
  *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GSS.  If not, see <http://www.gnu.org/licenses/>.\r
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * The views and conclusions contained in the software and\r
+ * documentation are those of the authors and should not be\r
+ * interpreted as representing official policies, either expressed\r
+ * or implied, of GRNET S.A.\r
  */\r
 package gr.grnet.pithos.web.client;\r
 \r
-import gr.grnet.pithos.web.client.rest.PostCommand;\r
+import gr.grnet.pithos.web.client.foldertree.File;\r
+import gr.grnet.pithos.web.client.foldertree.FileVersions;\r
+import gr.grnet.pithos.web.client.foldertree.Resource;\r
+import gr.grnet.pithos.web.client.foldertree.Version;\r
+import gr.grnet.pithos.web.client.rest.GetRequest;\r
+import gr.grnet.pithos.web.client.rest.PostRequest;\r
+import gr.grnet.pithos.web.client.rest.PutRequest;\r
 import gr.grnet.pithos.web.client.rest.RestException;\r
-import gr.grnet.pithos.web.client.rest.resource.FileResource;\r
-import gr.grnet.pithos.web.client.rest.resource.GroupResource;\r
-import gr.grnet.pithos.web.client.rest.resource.PermissionHolder;\r
+import gr.grnet.pithos.web.client.tagtree.Tag;\r
 \r
-import java.util.Iterator;\r
 import java.util.List;\r
-import java.util.Set;\r
+import java.util.Map;\r
 \r
 import com.google.gwt.core.client.GWT;\r
-import com.google.gwt.event.dom.client.ChangeEvent;\r
-import com.google.gwt.event.dom.client.ChangeHandler;\r
+import com.google.gwt.core.client.Scheduler;\r
 import com.google.gwt.event.dom.client.ClickEvent;\r
 import com.google.gwt.event.dom.client.ClickHandler;\r
+import com.google.gwt.event.logical.shared.SelectionEvent;\r
+import com.google.gwt.event.logical.shared.SelectionHandler;\r
 import com.google.gwt.i18n.client.DateTimeFormat;\r
-import com.google.gwt.json.client.JSONArray;\r
-import com.google.gwt.json.client.JSONBoolean;\r
-import com.google.gwt.json.client.JSONObject;\r
-import com.google.gwt.json.client.JSONString;\r
-import com.google.gwt.resources.client.ClientBundle;\r
 import com.google.gwt.resources.client.ImageResource;\r
-import com.google.gwt.user.client.Command;\r
-import com.google.gwt.user.client.DeferredCommand;\r
-import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
+import com.google.gwt.user.client.Window;\r
+import com.google.gwt.user.client.ui.Anchor;\r
 import com.google.gwt.user.client.ui.Button;\r
 import com.google.gwt.user.client.ui.CheckBox;\r
 import com.google.gwt.user.client.ui.DecoratedTabPanel;\r
@@ -50,7 +64,6 @@ import com.google.gwt.user.client.ui.DisclosurePanel;
 import com.google.gwt.user.client.ui.FlexTable;\r
 import com.google.gwt.user.client.ui.FlowPanel;\r
 import com.google.gwt.user.client.ui.FocusPanel;\r
-import com.google.gwt.user.client.ui.HTML;\r
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
 import com.google.gwt.user.client.ui.HorizontalPanel;\r
 import com.google.gwt.user.client.ui.Label;\r
@@ -60,18 +73,17 @@ import com.google.gwt.user.client.ui.VerticalPanel;
 /**\r
  * The 'File properties' dialog box implementation.\r
  *\r
- * @author past\r
  */\r
 public class FilePropertiesDialog extends AbstractPropertiesDialog {\r
 \r
-       final PermissionsList permList;\r
+       protected PermissionsList permList;\r
 \r
-       private CheckBox readForAll;\r
+       protected CheckBox readForAll;\r
 \r
        /**\r
         * An image bundle for this widgets images.\r
         */\r
-       public interface Images extends ClientBundle,MessagePanel.Images {\r
+       public interface Images extends MessagePanel.Images {\r
 \r
                @Source("gr/grnet/pithos/resources/edit_user.png")\r
                ImageResource permUser();\r
@@ -94,290 +106,266 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
         */\r
        private TextBox name = new TextBox();\r
 \r
-       private final CheckBox versioned = new CheckBox();\r
-\r
-       final FileResource file;\r
+       final File file;\r
 \r
-       private String userFullName;\r
+    Images images = GWT.create(Images.class);\r
 \r
        /**\r
         * The widget's constructor.\r
-        *\r
-        * @param images the dialog's ImageBundle\r
-        * @param groups\r
-        * @param bodies\r
         */\r
-       public FilePropertiesDialog(final Images images, final List<GroupResource> groups, List<FileResource> bodies, String _userFullName) {\r
+       public FilePropertiesDialog(Pithos _app, File _file) {\r
+        super(_app);\r
+        file = _file;\r
 \r
                // Set the dialog's caption.\r
                setText("File properties");\r
 \r
-               file = (FileResource) GSS.get().getCurrentSelection();\r
-               userFullName = _userFullName;\r
-               permList = new PermissionsList(images, file.getPermissions(), file.getOwner());\r
-\r
-               GWT.log("FILE PERMISSIONS:"+file.getPermissions());\r
                // Outer contains inner and buttons.\r
                final VerticalPanel outer = new VerticalPanel();\r
                final FocusPanel focusPanel = new FocusPanel(outer);\r
                // Inner contains generalPanel and permPanel.\r
                inner = new DecoratedTabPanel();\r
                inner.setAnimationEnabled(true);\r
-               final VerticalPanel generalPanel = new VerticalPanel();\r
-               final VerticalPanel permPanel = new VerticalPanel();\r
-               final HorizontalPanel buttons = new HorizontalPanel();\r
-               final HorizontalPanel permButtons = new HorizontalPanel();\r
-               final HorizontalPanel permForAll = new HorizontalPanel();\r
-               final HorizontalPanel pathPanel = new HorizontalPanel();\r
-               final VerticalPanel verPanel = new VerticalPanel();\r
-               final HorizontalPanel vPanel = new HorizontalPanel();\r
-               final HorizontalPanel vPanel2 = new HorizontalPanel();\r
-\r
-               versioned.setValue(file.isVersioned());\r
-               versioned.getElement().setId("filePropertiesDialog.chechBox.versioned");\r
-               inner.add(generalPanel, "General");\r
-               inner.add(permPanel, "Sharing");\r
-               inner.add(verPanel, "Versions");\r
-               inner.selectTab(0);\r
-\r
-               final Label fileNameNote = new Label("Please note that slashes ('/') are not allowed in file names.", true);\r
-               fileNameNote.setVisible(false);\r
-               fileNameNote.setStylePrimaryName("pithos-readForAllNote");\r
-\r
-               final FlexTable generalTable = new FlexTable();\r
-               generalTable.setText(0, 0, "Name");\r
-               generalTable.setText(1, 0, "Folder");\r
-               generalTable.setText(2, 0, "Owner");\r
-               generalTable.setText(3, 0, "Last modified");\r
-               generalTable.setText(4, 0, "Tags");\r
-               name.setWidth("100%");\r
-               name.setText(file.getName());\r
-               name.getElement().setId("filePropertiesDialog.textBox.name");\r
-               generalTable.setWidget(0, 1, name);\r
-               name.addChangeHandler(new ChangeHandler() {\r
 \r
-                       @Override\r
-                       public void onChange(ChangeEvent event) {\r
-                               if(name.getText().contains("/"))\r
-                                       fileNameNote.setVisible(true);\r
-                               else\r
-                                       fileNameNote.setVisible(false);\r
 \r
-                       }\r
-               });\r
+        inner.add(createGeneralPanel(), "General");\r
 \r
-               if(file.getFolderName() != null)\r
-                       generalTable.setText(1, 1, file.getFolderName());\r
-               else\r
-                       generalTable.setText(1, 1, "-");\r
-               generalTable.setWidget(0, 2, fileNameNote);\r
-               generalTable.setText(2, 1,userFullName);\r
+        inner.add(createSharingPanel(), "Sharing");\r
 \r
-               final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
-               generalTable.setText(3, 1, formatter.format(file.getModificationDate()));\r
-               // Get the tags.\r
-               StringBuffer tagsBuffer = new StringBuffer();\r
-               Iterator i = file.getTags().iterator();\r
-               while (i.hasNext()) {\r
-                       String tag = (String) i.next();\r
-                       tagsBuffer.append(tag).append(", ");\r
-               }\r
-               if (tagsBuffer.length() > 1)\r
-                       tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);\r
-               initialTagText = tagsBuffer.toString();\r
-               tags.setWidth("100%");\r
-               tags.getElement().setId("filePropertiesDialog.textBox.tags");\r
-               tags.setText(initialTagText);\r
-               generalTable.setWidget(4, 1, tags);\r
-               generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
-               generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");\r
-               generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");\r
-               generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");\r
-               generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");\r
-               generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");\r
-               generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");\r
-               generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");\r
-               generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");\r
-               generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");\r
-               generalTable.setCellSpacing(4);\r
+               fetchVersions();\r
+                       \r
+        inner.selectTab(0);\r
+\r
+        outer.add(inner);\r
 \r
+               final HorizontalPanel buttons = new HorizontalPanel();\r
                // Create the 'OK' button, along with a listener that hides the dialog\r
                // when the button is clicked.\r
                final Button ok = new Button("OK", new ClickHandler() {\r
                        @Override\r
-                       public void onClick(ClickEvent event) {\r
-                               if(name.getText().contains("/"))\r
-                                       fileNameNote.setVisible(true);\r
-                               else{\r
-                                       fileNameNote.setVisible(false);\r
-                                       accept();\r
-                                       closeDialog();\r
-                               }               \r
+                       public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
+                               accept();\r
+                               closeDialog();\r
                        }\r
                });\r
-               ok.getElement().setId("filePropertiesDialog.button.ok");                \r
+\r
                buttons.add(ok);\r
                buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);\r
                // Create the 'Cancel' button, along with a listener that hides the\r
                // dialog when the button is clicked.\r
                final Button cancel = new Button("Cancel", new ClickHandler() {\r
                        @Override\r
-                       public void onClick(ClickEvent event) {\r
+                       public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
                                closeDialog();\r
                        }\r
                });\r
-               cancel.getElement().setId("filePropertiesDialog.button.cancel");\r
                buttons.add(cancel);\r
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
                buttons.setSpacing(8);\r
                buttons.addStyleName("pithos-TabPanelBottom");\r
 \r
-               generalPanel.add(generalTable);\r
-\r
-               // Asynchronously retrieve the tags defined by this user.\r
-               DeferredCommand.addCommand(new Command() {\r
-\r
-                       @Override\r
-                       public void execute() {\r
-                               updateTags();\r
-                       }\r
-               });\r
+        outer.add(buttons);\r
+        outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
+        outer.addStyleName("pithos-TabPanelBottom");\r
 \r
-               DisclosurePanel allTags = new DisclosurePanel("All tags");\r
-               allTagsContent = new FlowPanel();\r
-               allTagsContent.setWidth("100%");\r
-               allTags.setContent(allTagsContent);\r
-               generalPanel.add(allTags);\r
-               generalPanel.setSpacing(4);\r
+        focusPanel.setFocus(true);\r
+        setWidget(outer);\r
+       }\r
 \r
-               final Button add = new Button("Add Group", new ClickHandler() {\r
-                       @Override\r
-                       public void onClick(ClickEvent event) {\r
-                               PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, false);\r
-                               dlg.center();\r
-                       }\r
-               });\r
-               add.getElement().setId("filePropertiesDialog.button.addGroup");\r
-               permButtons.add(add);\r
-               permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);\r
+    protected void fetchVersions() {\r
+       String path = file.getUri() + "?format=json&version=list";\r
+       GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwner(), path) {\r
 \r
-               final Button addUser = new Button("Add User", new ClickHandler() {\r
                        @Override\r
-                       public void onClick(ClickEvent event) {\r
-                               PermissionsAddDialog dlg = new PermissionsAddDialog(groups, permList, true);\r
-                               dlg.center();\r
+                       public void onSuccess(FileVersions _result) {\r
+                       inner.add(createVersionPanel(_result.getVersions()), "Versions");\r
                        }\r
-               });\r
-               add.getElement().setId("filePropertiesDialog.button.addUser");\r
-               permButtons.add(addUser);\r
-               permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);\r
-\r
-               permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
-               permButtons.setSpacing(8);\r
-               permButtons.addStyleName("pithos-TabPanelBottom");\r
-\r
-               final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +\r
-                                       " by everyone. By checking this option, you are certifying that you have the right to " +\r
-                                       "distribute this file and that it does not violate the Terms of Use.", true);\r
-               readForAllNote.setVisible(false);\r
-               readForAllNote.setStylePrimaryName("pithos-readForAllNote");\r
-\r
-               readForAll = new CheckBox();\r
-               readForAll.getElement().setId("filePropertiesDialog.checkBox.public");\r
-               readForAll.setValue(file.isReadForAll());\r
-               readForAll.addClickHandler(new ClickHandler() {\r
-                       @Override\r
-                       public void onClick(ClickEvent event) {\r
-                               readForAllNote.setVisible(readForAll.getValue());\r
-                       }\r
-\r
-               });\r
-\r
-               permPanel.add(permList);\r
-               permPanel.add(permButtons);\r
-               // Only show the read for all permission if the user is the owner.\r
-               if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername())) {\r
-                       permForAll.add(new Label("Public"));\r
-                       permForAll.add(readForAll);\r
-                       permForAll.setSpacing(8);\r
-                       permForAll.addStyleName("pithos-TabPanelBottom");\r
-                       permForAll.add(readForAllNote);\r
-                       permPanel.add(permForAll);\r
-               }\r
 \r
-               TextBox path = new TextBox();\r
-               path.setWidth("100%");\r
-               path.addClickHandler(new ClickHandler() {\r
                        @Override\r
-                       public void onClick(ClickEvent event) {\r
-                               GSS.enableIESelection();\r
-                               ((TextBox) event.getSource()).selectAll();\r
-                               GSS.preventIESelection();\r
+                       public void onError(Throwable t) {\r
+                if (t instanceof RestException) {\r
+                    app.displayError("Unable to fetch versions: " + ((RestException) t).getHttpStatusText());\r
+                }\r
+                else\r
+                    app.displayError("System error unable to fetch versions: "+t.getMessage());\r
                        }\r
+               };\r
+               getVersions.setHeader("X-Auth-Token", app.getToken());\r
+               Scheduler.get().scheduleDeferred(getVersions);\r
+       }\r
 \r
-               });\r
-               path.setText(file.getUri());\r
-               path.getElement().setId("filePropertiesDialog.textBox.link");\r
-               path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");\r
-               path.setWidth("100%");\r
-               path.setReadOnly(true);\r
-               pathPanel.setWidth("100%");\r
-               pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);\r
-               pathPanel.add(new Label("Link"));\r
-               pathPanel.setSpacing(8);\r
-               pathPanel.addStyleName("pithos-TabPanelBottom");\r
-               pathPanel.add(path);\r
-               permPanel.add(pathPanel);\r
-\r
-               VersionsList verList = new VersionsList(this, images, bodies);\r
-               verPanel.add(verList);\r
-\r
-               vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
-               vPanel.setSpacing(8);\r
-               vPanel.addStyleName("pithos-TabPanelBottom");\r
-               vPanel.add(new Label("Versioned"));\r
-\r
-               vPanel.add(versioned);\r
-               verPanel.add(vPanel);\r
-               vPanel2.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
-               vPanel2.setSpacing(8);\r
-               vPanel2.addStyleName("pithos-TabPanelBottom");\r
-               Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() {\r
-                       @Override\r
-                       public void onClick(ClickEvent event) {\r
-                               ConfirmationDialog confirm = new ConfirmationDialog("Really " +\r
-                                               "remove all previous versions?", "Remove") {\r
-\r
-                                       @Override\r
-                                       public void cancel() {\r
-                                       }\r
-\r
-                                       @Override\r
-                                       public void confirm() {\r
-                                               FilePropertiesDialog.this.closeDialog();\r
-                                               removeAllOldVersions();\r
-                                       }\r
-\r
-                               };\r
-                               confirm.center();\r
-                       }\r
+       private VerticalPanel createGeneralPanel() {\r
+        final VerticalPanel generalPanel = new VerticalPanel();\r
+        final FlexTable generalTable = new FlexTable();\r
+        generalTable.setText(0, 0, "Name");\r
+        generalTable.setText(1, 0, "Folder");\r
+        generalTable.setText(2, 0, "Owner");\r
+        generalTable.setText(3, 0, "Last modified");\r
+        generalTable.setText(4, 0, "Tags");\r
+\r
+        name.setWidth("100%");\r
+        name.setText(file.getName());\r
+        generalTable.setWidget(0, 1, name);\r
+        if(file.getParent() != null)\r
+            generalTable.setText(1, 1, file.getParent().getName());\r
+        else\r
+            generalTable.setText(1, 1, "-");\r
+        generalTable.setText(2, 1, file.getOwner());\r
+\r
+        final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
+        generalTable.setText(3, 1, formatter.format(file.getLastModified()));\r
 \r
-               });\r
-               HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>");\r
-               vPanel2.add(removeAllVersion);\r
-               vPanel2.add(removeVersionsButton);\r
-               verPanel.add(vPanel2);\r
-               if(!file.isVersioned())\r
-                       vPanel2.setVisible(false);\r
-               outer.add(inner);\r
-               outer.add(buttons);\r
-               outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
-               outer.addStyleName("pithos-TabPanelBottom");\r
-\r
-               focusPanel.setFocus(true);\r
-               setWidget(outer);\r
-       }\r
+               StringBuffer tagsBuffer = new StringBuffer();\r
+        for (String t : file.getTags())\r
+                       tagsBuffer.append(t).append(", ");\r
+               if (tagsBuffer.length() > 1)\r
+                       tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);\r
+               initialTagText = tagsBuffer.toString();\r
+               tags.setWidth("100%");\r
+               tags.setText(initialTagText);\r
+               generalTable.setWidget(4, 1, tags);\r
 \r
+        generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
+        generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");\r
+        generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");\r
+        generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");\r
+        generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");\r
+        generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");\r
+        generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");\r
+        generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");\r
+        generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");\r
+        generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");\r
+        generalTable.setCellSpacing(4);\r
+\r
+        generalPanel.add(generalTable);\r
+\r
+        DisclosurePanel allTags = new DisclosurePanel("All tags");\r
+        allTagsContent = new FlowPanel();\r
+        allTagsContent.setWidth("100%");\r
+        for (Tag t : app.getAllTags()) {\r
+            final Anchor tagAnchor = new Anchor(t.getName(), false);\r
+            tagAnchor.addStyleName("pithos-tag");\r
+            allTagsContent.add(tagAnchor);\r
+            Label separator = new Label(", ");\r
+            separator.addStyleName("pithos-tag");\r
+            allTagsContent.add(separator);\r
+            tagAnchor.addClickHandler(new ClickHandler() {\r
+\r
+                @Override\r
+                public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
+                    String existing = tags.getText().trim();\r
+                    if (MULTIPLE_VALUES_TEXT.equals(existing))\r
+                        existing = "";\r
+                    String newTag = tagAnchor.getText().trim();\r
+                    // insert the new tag only if it is not in the list\r
+                    // already\r
+                    if (existing.indexOf(newTag) == -1)\r
+                        tags.setText(existing + (existing.length() > 0 ? ", " : "") + newTag);\r
+                }\r
+            });\r
+        }\r
+        allTags.setContent(allTagsContent);\r
+        generalPanel.add(allTags);\r
+        generalPanel.setSpacing(4);\r
+        return generalPanel;\r
+    }\r
+\r
+    private VerticalPanel createSharingPanel() {\r
+        VerticalPanel permPanel = new VerticalPanel();\r
+\r
+        permList = new PermissionsList(images, file.getPermissions(), file.getOwner(), file.getInheritedPermissionsFrom() != null);\r
+        permPanel.add(permList);\r
+\r
+        if (file.getInheritedPermissionsFrom() == null) {\r
+            HorizontalPanel permButtons = new HorizontalPanel();\r
+            Button add = new Button("Add Group", new ClickHandler() {\r
+                @Override\r
+                public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
+                    PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);\r
+                    dlg.center();\r
+                    permList.updatePermissionTable();\r
+                }\r
+            });\r
+            permButtons.add(add);\r
+            permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);\r
+\r
+            final Button addUser = new Button("Add User", new ClickHandler() {\r
+                @Override\r
+                public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
+                    PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true);\r
+                    dlg.center();\r
+                    permList.updatePermissionTable();\r
+                }\r
+            });\r
+            permButtons.add(addUser);\r
+            permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);\r
+\r
+            permButtons.setSpacing(8);\r
+            permButtons.addStyleName("pithos-TabPanelBottom");\r
+            permPanel.add(permButtons);\r
+        }\r
+\r
+        final Label readForAllNote = new Label("When this option is enabled, the file will be readable" +\r
+                    " by everyone. By checking this option, you are certifying that you have the right to " +\r
+                    "distribute this file and that it does not violate the Terms of Use.", true);\r
+        readForAllNote.setVisible(false);\r
+        readForAllNote.setStylePrimaryName("pithos-readForAllNote");\r
+\r
+        readForAll = new CheckBox();\r
+        readForAll.setValue(file.isPublished());\r
+        readForAll.addClickHandler(new ClickHandler() {\r
+            @Override\r
+            public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
+                readForAllNote.setVisible(readForAll.getValue());\r
+            }\r
+        });\r
+\r
+        // Only show the read for all permission if the user is the owner.\r
+        if (file.getOwner().equals(app.getUsername())) {\r
+            final HorizontalPanel permForAll = new HorizontalPanel();\r
+            permForAll.add(new Label("Public"));\r
+            permForAll.add(readForAll);\r
+            permForAll.setSpacing(8);\r
+            permForAll.addStyleName("pithos-TabPanelBottom");\r
+            permForAll.add(readForAllNote);\r
+            permPanel.add(permForAll);\r
+        }\r
+\r
+        if (file.isPublished()) {\r
+            final HorizontalPanel pathPanel = new HorizontalPanel();\r
+            pathPanel.setWidth("100%");\r
+            pathPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);\r
+            pathPanel.add(new Label("Link"));\r
+            pathPanel.setSpacing(8);\r
+            pathPanel.addStyleName("pithos-TabPanelBottom");\r
+\r
+            TextBox path = new TextBox();\r
+            path.setWidth("100%");\r
+            path.addClickHandler(new ClickHandler() {\r
+                @Override\r
+                public void onClick(ClickEvent event) {\r
+                    Pithos.enableIESelection();\r
+                    ((TextBox) event.getSource()).selectAll();\r
+                    Pithos.preventIESelection();\r
+                }\r
+            });\r
+            path.setText(Window.Location.getHost() + file.getPublicUri());\r
+            path.setTitle("Use this link for sharing the file via e-mail, IM, etc. (crtl-C/cmd-C to copy to system clipboard)");\r
+            path.setWidth("100%");\r
+            path.setReadOnly(true);\r
+            pathPanel.add(path);\r
+            permPanel.add(pathPanel);\r
+        }\r
+\r
+        return permPanel;\r
+    }\r
+\r
+    private VerticalPanel createVersionPanel(List<Version> versions) {\r
+        VerticalPanel versionPanel = new VerticalPanel();\r
+        VersionsList verList = new VersionsList(app, this, images, file, versions);\r
+        versionPanel.add(verList);\r
+        return versionPanel;\r
+    }\r
 \r
        /**\r
         * Accepts any change and updates the file\r
@@ -386,150 +374,97 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
        @Override\r
        protected void accept() {\r
                String newFilename = null;\r
-               permList.updatePermissionsAccordingToInput();\r
-               Set<PermissionHolder> perms = permList.getPermissions();\r
-               JSONObject json = new JSONObject();\r
-               if (!name.getText().equals(file.getName())) {\r
-                       newFilename = name.getText();\r
-                       json.put("name", new JSONString(newFilename));\r
-               }\r
-               if (versioned.getValue() != file.isVersioned())\r
-                       json.put("versioned", JSONBoolean.getInstance(versioned.getValue()));\r
-               //only update the read for all perm if the user is the owner\r
-               if (readForAll.getValue() != file.isReadForAll())\r
-                       if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))\r
-                               json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));\r
-               int i = 0;\r
-               if (permList.hasChanges()) {\r
-                       GWT.log("Permissions change", null);\r
-                       JSONArray perma = new JSONArray();\r
-\r
-                       for (PermissionHolder p : perms) {\r
-                               JSONObject po = new JSONObject();\r
-                               if (p.getUser() != null)\r
-                                       po.put("user", new JSONString(p.getUser()));\r
-                               if (p.getGroup() != null)\r
-                                       po.put("group", new JSONString(p.getGroup()));\r
-                               po.put("read", JSONBoolean.getInstance(p.isRead()));\r
-                               po.put("write", JSONBoolean.getInstance(p.isWrite()));\r
-                               po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL()));\r
-                               perma.set(i, po);\r
-                               i++;\r
-                       }\r
-                       json.put("permissions", perma);\r
-               }\r
-               JSONArray taga = new JSONArray();\r
-               i = 0;\r
-               if (!tags.getText().equals(initialTagText)) {\r
-                       String[] tagset = tags.getText().split(",");\r
-                       for (String t : tagset) {\r
-                               JSONString to = new JSONString(t);\r
-                               taga.set(i, to);\r
-                               i++;\r
-                       }\r
-                       json.put("tags", taga);\r
-               }\r
-               String jsonString = json.toString();\r
-               if(jsonString.equals("{}")){\r
-                       GWT.log("NO CHANGES", null);\r
-                       return;\r
-               }\r
-               final String newFilenameFinal = newFilename;\r
-               PostCommand cf = new PostCommand(file.getUri() + "?update=", jsonString, 200) {\r
-\r
-                       @Override\r
-                       public void onComplete() {\r
-                               GSS.get().getTreeView().refreshCurrentNode(false);\r
-                       }\r
 \r
-                       @Override\r
-                       public void onError(Throwable t) {\r
-                               GWT.log("", t);\r
-                               if (t instanceof RestException) {\r
-                                       int statusCode = ((RestException) t).getHttpStatusCode();\r
-                                       if (statusCode == 405)\r
-                                               GSS.get().displayError("You don't have the necessary permissions");\r
-                                       else if (statusCode == 404)\r
-                                               GSS.get().displayError("User in permissions does not exist");\r
-                                       else if (statusCode == 409)\r
-                                               GSS.get().displayError("A file with the same name already exists");\r
-                                       else if (statusCode == 413)\r
-                                               GSS.get().displayError("Your quota has been exceeded");\r
-                                       else\r
-                                               GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
-                               } else\r
-                                       GSS.get().displayError("System error modifying file:" + t.getMessage());\r
-                       }\r
-\r
-               };\r
-               DeferredCommand.addCommand(cf);\r
+               final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null);\r
 \r
-       }\r
-\r
-       private void removeAllOldVersions() {\r
-               JSONObject json = new JSONObject();\r
-               json.put("versioned", JSONBoolean.getInstance(false));\r
-               GWT.log(json.toString(), null);\r
-               PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {\r
-\r
-                       @Override\r
-                       public void onComplete() {\r
-                               toggleVersioned(true);\r
-                       }\r
+               if (!name.getText().trim().equals(file.getName())) {\r
+                       newFilename = name.getText().trim();\r
+               }\r
 \r
-                       @Override\r
-                       public void onError(Throwable t) {\r
-                               GWT.log("", t);\r
-                               if (t instanceof RestException) {\r
-                                       int statusCode = ((RestException) t).getHttpStatusCode();\r
-                                       if (statusCode == 405)\r
-                                               GSS.get().displayError("You don't have the necessary permissions");\r
-                                       else if (statusCode == 404)\r
-                                               GSS.get().displayError("User in permissions does not exist");\r
-                                       else if (statusCode == 409)\r
-                                               GSS.get().displayError("A folder with the same name already exists");\r
-                                       else if (statusCode == 413)\r
-                                               GSS.get().displayError("Your quota has been exceeded");\r
-                                       else\r
-                                               GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
-                               } else\r
-                                       GSS.get().displayError("System error moifying file:" + t.getMessage());\r
-                       }\r
-               };\r
-               DeferredCommand.addCommand(cf);\r
+               //only update the read for all perm if the user is the owner\r
+        Boolean published = null;\r
+               if (readForAll.getValue() != file.isPublished())\r
+                       if (file.getOwner().equals(app.getUsername()))\r
+                published = readForAll.getValue();\r
+        final Boolean finalPublished = published;\r
+\r
+        String[] tagset = null;\r
+               if (!tags.getText().equals(initialTagText))\r
+                       tagset = tags.getText().split(",");\r
+        final String[] newTags = tagset;\r
+\r
+        if (newFilename != null) {\r
+            final String path = file.getParent().getUri() + "/" + newFilename;\r
+            PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUsername(), path) {\r
+                @Override\r
+                public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
+                    updateMetaData(app.getApiPath(), file.getOwner(), path + "?update=", newTags, finalPublished, perms);\r
+                }\r
+\r
+                @Override\r
+                public void onError(Throwable t) {\r
+                    GWT.log("", t);\r
+                    app.displayError("System error modifying file:" + t.getMessage());\r
+                }\r
+            };\r
+            updateFile.setHeader("X-Auth-Token", app.getToken());\r
+            updateFile.setHeader("X-Move-From", file.getUri());\r
+            updateFile.setHeader("Content-Type", file.getContentType());\r
+            Scheduler.get().scheduleDeferred(updateFile);\r
+        }\r
+        else\r
+            updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newTags, finalPublished, perms);\r
        }\r
 \r
-       private void toggleVersioned(boolean versionedValue) {\r
-               JSONObject json = new JSONObject();\r
-               json.put("versioned", JSONBoolean.getInstance(versionedValue));\r
-               GWT.log(json.toString(), null);\r
-               PostCommand cf = new PostCommand(file.getUri() + "?update=", json.toString(), 200) {\r
+       protected void updateMetaData(String api, String owner, String path, String[] newTags, Boolean published, Map<String, Boolean[]> newPermissions) {\r
+        if (newTags != null || published != null || newPermissions != null) {\r
+            PostRequest updateFile = new PostRequest(api, owner, path) {\r
+                @Override\r
+                public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
+                    app.updateFolder(file.getParent(), true, null);\r
+                }\r
+\r
+                @Override\r
+                public void onError(Throwable t) {\r
+                    GWT.log("", t);\r
+                    app.displayError("System error modifying file:" + t.getMessage());\r
+                }\r
+            };\r
+            updateFile.setHeader("X-Auth-Token", app.getToken());\r
+            if (newTags != null)\r
+                for (String t : newTags)\r
+                    updateFile.setHeader("X-Object-Meta-" + t.trim(), "true");\r
+            if (published != null)\r
+                updateFile.setHeader("X-Object-Public", published.toString());\r
+            if (newPermissions != null) {\r
+                String readPermHeader = "read=";\r
+                String writePermHeader = "write=";\r
+                for (String u : newPermissions.keySet()) {\r
+                    Boolean[] p = newPermissions.get(u);\r
+                    if (p[0] != null && p[0])\r
+                        readPermHeader += u + ",";\r
+                    if (p[1] != null && p[1])\r
+                        writePermHeader += u + ",";\r
+                }\r
+                if (readPermHeader.endsWith("="))\r
+                    readPermHeader = "";\r
+                else if (readPermHeader.endsWith(","))\r
+                    readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1);\r
+                if (writePermHeader.endsWith("="))\r
+                    writePermHeader = "";\r
+                else if (writePermHeader.endsWith(","))\r
+                    writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1);\r
+                String permHeader = readPermHeader +  ((readPermHeader.length()  > 0 && writePermHeader.length() > 0) ?  ";" : "") + writePermHeader;\r
+                if (permHeader.length() == 0)\r
+                    permHeader="~";\r
+                updateFile.setHeader("X-Object-Sharing", permHeader);\r
+            }\r
+            Scheduler.get().scheduleDeferred(updateFile);\r
+        }\r
+        else\r
+            app.updateFolder(file.getParent(), true, null);\r
+    }\r
 \r
-                       @Override\r
-                       public void onComplete() {\r
-                               GSS.get().getTreeView().refreshCurrentNode(false);\r
-                       }\r
-\r
-                       @Override\r
-                       public void onError(Throwable t) {\r
-                               GWT.log("", t);\r
-                               if (t instanceof RestException) {\r
-                                       int statusCode = ((RestException) t).getHttpStatusCode();\r
-                                       if (statusCode == 405)\r
-                                               GSS.get().displayError("You don't have the necessary permissions");\r
-                                       else if (statusCode == 404)\r
-                                               GSS.get().displayError("User in permissions does not exist");\r
-                                       else if (statusCode == 409)\r
-                                               GSS.get().displayError("A folder with the same name already exists");\r
-                                       else if (statusCode == 413)\r
-                                               GSS.get().displayError("Your quota has been exceeded");\r
-                                       else\r
-                                               GSS.get().displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
-                               } else\r
-                                       GSS.get().displayError("System error moifying file:" + t.getMessage());\r
-                       }\r
-               };\r
-               DeferredCommand.addCommand(cf);\r
+       private void removeAllOldVersions() {\r
        }\r
-\r
 }\r