FilePropertiesDialog is broken into three dialogs
[pithos-web-client] / src / gr / grnet / pithos / web / client / FilePropertiesDialog.java
index 89e1f67..6943468 100644 (file)
 package gr.grnet.pithos.web.client;\r
 \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
 \r
 import java.util.HashMap;\r
-import java.util.List;\r
 import java.util.Map;\r
 \r
 import com.google.gwt.core.client.GWT;\r
@@ -54,12 +49,9 @@ import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.http.client.Response;\r
 import com.google.gwt.http.client.URL;\r
 import com.google.gwt.i18n.client.DateTimeFormat;\r
-import com.google.gwt.resources.client.ImageResource;\r
 import com.google.gwt.user.client.Command;\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
 import com.google.gwt.user.client.ui.FlexTable;\r
 import com.google.gwt.user.client.ui.FocusPanel;\r
@@ -76,31 +68,6 @@ import com.google.gwt.user.client.ui.VerticalPanel;
  */\r
 public class FilePropertiesDialog extends AbstractPropertiesDialog {\r
 \r
-       protected PermissionsList permList;\r
-\r
-       protected CheckBox readForAll;\r
-\r
-       /**\r
-        * An image bundle for this widgets images.\r
-        */\r
-       public interface Images extends MessagePanel.Images {\r
-\r
-               @Source("gr/grnet/pithos/resources/edit_user.png")\r
-               ImageResource permUser();\r
-\r
-               @Source("gr/grnet/pithos/resources/groups22.png")\r
-               ImageResource permGroup();\r
-\r
-               @Source("gr/grnet/pithos/resources/editdelete.png")\r
-               ImageResource delete();\r
-\r
-               @Source("gr/grnet/pithos/resources/db_update.png")\r
-               ImageResource restore();\r
-\r
-               @Source("gr/grnet/pithos/resources/folder_inbox.png")\r
-               ImageResource download();\r
-       }\r
-\r
        /**\r
         * The widget that holds the name of the file.\r
         */\r
@@ -108,8 +75,6 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
 \r
        final File file;\r
 \r
-    Images images = GWT.create(Images.class);\r
-\r
     FlexTable metaTable;\r
        /**\r
         * The widget's constructor.\r
@@ -136,21 +101,13 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
                // Outer contains inner and buttons.\r
                final VerticalPanel outer = new VerticalPanel();\r
                outer.add(close);\r
-               final FocusPanel focusPanel = new FocusPanel(outer);\r
                // Inner contains generalPanel and permPanel.\r
-               inner = new DecoratedTabPanel();\r
-               inner.setAnimationEnabled(true);\r
+               inner = new VerticalPanel();\r
                inner.addStyleName("inner");\r
-               inner.getDeckPanel().addStyleName("pithos-TabPanelBottom");\r
-\r
+//             inner.getDeckPanel().addStyleName("pithos-TabPanelBottom");\r
 \r
-        inner.add(createGeneralPanel(), "General");\r
 \r
-        inner.add(createSharingPanel(), "Sharing");\r
-\r
-               fetchVersions();\r
-                       \r
-        inner.selectTab(0);\r
+        inner.add(createGeneralPanel());\r
 \r
         outer.add(inner);\r
 \r
@@ -168,39 +125,9 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
         outer.add(ok);\r
         outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);\r
 \r
-        focusPanel.setFocus(true);\r
         setWidget(outer);\r
        }\r
 \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
-                       @Override\r
-                       public void onSuccess(FileVersions _result) {\r
-                       inner.add(createVersionPanel(_result.getVersions()), "Versions");\r
-                       }\r
-\r
-                       @Override\r
-                       public void onError(Throwable t) {\r
-                               GWT.log("", t);\r
-                               app.setError(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
-                       @Override\r
-                       protected void onUnauthorized(@SuppressWarnings("unused") Response response) {\r
-                               app.sessionExpired();\r
-                       }\r
-               };\r
-               getVersions.setHeader("X-Auth-Token", app.getToken());\r
-               Scheduler.get().scheduleDeferred(getVersions);\r
-       }\r
-\r
        private VerticalPanel createGeneralPanel() {\r
         final VerticalPanel generalPanel = new VerticalPanel();\r
         final FlexTable generalTable = new FlexTable();\r
@@ -298,105 +225,6 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
                table.setWidget(row, 2, delete);\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
-            add.addStyleName("button");\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
-            addUser.addStyleName("button");\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
-    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
         *\r
@@ -405,19 +233,10 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
        protected void accept() {\r
                String newFilename = null;\r
 \r
-               final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null);\r
-\r
                if (!name.getText().trim().equals(file.getName())) {\r
                        newFilename = name.getText().trim();\r
                }\r
 \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
         final Map<String, String> newMeta = new HashMap<String, String>();\r
         for (int row = 1; row < metaTable.getRowCount(); row++) {\r
                String key = ((TextBox) metaTable.getWidget(row, 0)).getText().trim();\r
@@ -431,7 +250,7 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
             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=", newMeta, finalPublished, perms);\r
+                    updateMetaData(app.getApiPath(), file.getOwner(), path + "?update=", newMeta);\r
                 }\r
 \r
                 @Override\r
@@ -480,11 +299,11 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
             Scheduler.get().scheduleDeferred(updateFile);\r
         }\r
         else\r
-            updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newMeta, finalPublished, perms);\r
+            updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newMeta);\r
        }\r
 \r
-       protected void updateMetaData(String api, String owner, String path, Map<String, String> newMeta, final Boolean published, final Map<String, Boolean[]> newPermissions) {\r
-        if (newMeta != null || published != null || newPermissions != null) {\r
+       protected void updateMetaData(String api, String owner, String path, Map<String, String> newMeta) {\r
+        if (newMeta != null) {\r
             PostRequest updateFile = new PostRequest(api, owner, path) {\r
                 @Override\r
                 public void onSuccess(@SuppressWarnings("unused") Resource result) {\r
@@ -511,42 +330,13 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
             };\r
             updateFile.setHeader("X-Auth-Token", app.getToken());\r
             \r
-            if (newMeta != null) {\r
-                   for (String t : file.getMeta().keySet()) {\r
-                               updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(t.trim()), "~");\r
-                   }\r
-                   \r
-                   for (String key : newMeta.keySet())\r
-                       updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key)));\r
+            for (String t : file.getMeta().keySet()) {\r
+                       updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(t.trim()), "~");\r
             }\r
             \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
-                else\r
-                       permHeader = URL.encodePathSegment(permHeader);\r
-                updateFile.setHeader("X-Object-Sharing", permHeader);\r
-            }\r
+            for (String key : newMeta.keySet())\r
+                updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key)));\r
+            \r
             Scheduler.get().scheduleDeferred(updateFile);\r
         }\r
         else\r