improved version of bug (almost)fix 371. Abstract methods implemented inside RestReso...
[pithos] / src / gr / ebs / gss / client / FilePropertiesDialog.java
index df97ec8..be108cc 100644 (file)
  */\r
 package gr.ebs.gss.client;\r
 \r
-import gr.ebs.gss.client.rest.GetCommand;\r
 import gr.ebs.gss.client.rest.PostCommand;\r
 import gr.ebs.gss.client.rest.RestException;\r
 import gr.ebs.gss.client.rest.resource.FileResource;\r
 import gr.ebs.gss.client.rest.resource.GroupResource;\r
 import gr.ebs.gss.client.rest.resource.PermissionHolder;\r
-import gr.ebs.gss.client.rest.resource.TagsResource;\r
 \r
 import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.Set;\r
 \r
 import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.event.dom.client.ClickEvent;\r
+import com.google.gwt.event.dom.client.ClickHandler;\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.ui.Button;\r
 import com.google.gwt.user.client.ui.CheckBox;\r
-import com.google.gwt.user.client.ui.ClickListener;\r
-import com.google.gwt.user.client.ui.DialogBox;\r
+import com.google.gwt.user.client.ui.DecoratedTabPanel;\r
 import com.google.gwt.user.client.ui.DisclosurePanel;\r
 import com.google.gwt.user.client.ui.FlexTable;\r
 import com.google.gwt.user.client.ui.FlowPanel;\r
@@ -50,19 +51,16 @@ import com.google.gwt.user.client.ui.FocusPanel;
 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.KeyboardListener;\r
 import com.google.gwt.user.client.ui.Label;\r
-import com.google.gwt.user.client.ui.TabPanel;\r
 import com.google.gwt.user.client.ui.TextBox;\r
 import com.google.gwt.user.client.ui.VerticalPanel;\r
-import com.google.gwt.user.client.ui.Widget;\r
 \r
 /**\r
  * The 'File properties' dialog box implementation.\r
  *\r
  * @author past\r
  */\r
-public class FilePropertiesDialog extends DialogBox {\r
+public class FilePropertiesDialog extends AbstractPropertiesDialog {\r
 \r
        final PermissionsList permList;\r
 \r
@@ -71,22 +69,22 @@ public class FilePropertiesDialog extends DialogBox {
        /**\r
         * An image bundle for this widgets images.\r
         */\r
-       public interface Images extends MessagePanel.Images {\r
+       public interface Images extends ClientBundle,MessagePanel.Images {\r
 \r
-               @Resource("gr/ebs/gss/resources/edit_user.png")\r
-               AbstractImagePrototype permUser();\r
+               @Source("gr/ebs/gss/resources/edit_user.png")\r
+               ImageResource permUser();\r
 \r
-               @Resource("gr/ebs/gss/resources/groupevent.png")\r
-               AbstractImagePrototype permGroup();\r
+               @Source("gr/ebs/gss/resources/groupevent.png")\r
+               ImageResource permGroup();\r
 \r
-               @Resource("gr/ebs/gss/resources/editdelete.png")\r
-               AbstractImagePrototype delete();\r
+               @Source("gr/ebs/gss/resources/editdelete.png")\r
+               ImageResource delete();\r
 \r
-               @Resource("gr/ebs/gss/resources/db_update.png")\r
-               AbstractImagePrototype restore();\r
+               @Source("gr/ebs/gss/resources/db_update.png")\r
+               ImageResource restore();\r
 \r
-               @Resource("gr/ebs/gss/resources/folder_inbox.png")\r
-               AbstractImagePrototype download();\r
+               @Source("gr/ebs/gss/resources/folder_inbox.png")\r
+               ImageResource download();\r
        }\r
 \r
        /**\r
@@ -94,24 +92,10 @@ public class FilePropertiesDialog extends DialogBox {
         */\r
        private TextBox name = new TextBox();\r
 \r
-       /**\r
-        * Text box with the tags associated with the file\r
-        */\r
-       private TextBox tags = new TextBox();\r
-\r
-       /**\r
-        * A FlowPanel with all user tags\r
-        */\r
-       private FlowPanel allTagsContent;\r
-\r
        private final CheckBox versioned = new CheckBox();\r
 \r
        final FileResource file;\r
 \r
-       String initialTagText;\r
-\r
-       final TabPanel inner;\r
-\r
        /**\r
         * The widget's constructor.\r
         *\r
@@ -121,12 +105,9 @@ public class FilePropertiesDialog extends DialogBox {
         */\r
        public FilePropertiesDialog(final Images images, final List<GroupResource> groups, List<FileResource> bodies) {\r
 \r
-               // Enable IE selection for the dialog (must disable it upon closing it)\r
-               GSS.enableIESelection();\r
-\r
                // Set the dialog's caption.\r
                setText("File properties");\r
-               setAnimationEnabled(true);\r
+\r
                file = (FileResource) GSS.get().getCurrentSelection();\r
                permList = new PermissionsList(images, file.getPermissions(), file.getOwner());\r
 \r
@@ -134,7 +115,8 @@ public class FilePropertiesDialog extends DialogBox {
                final VerticalPanel outer = new VerticalPanel();\r
                final FocusPanel focusPanel = new FocusPanel(outer);\r
                // Inner contains generalPanel and permPanel.\r
-               inner = new TabPanel();\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
@@ -145,7 +127,7 @@ public class FilePropertiesDialog extends DialogBox {
                final HorizontalPanel vPanel = new HorizontalPanel();\r
                final HorizontalPanel vPanel2 = new HorizontalPanel();\r
 \r
-               versioned.setChecked(file.isVersioned());\r
+               versioned.setValue(file.isVersioned());\r
                inner.add(generalPanel, "General");\r
                inner.add(permPanel, "Sharing");\r
                inner.add(verPanel, "Versions");\r
@@ -155,7 +137,7 @@ public class FilePropertiesDialog extends DialogBox {
                generalTable.setText(0, 0, "Name");\r
                generalTable.setText(1, 0, "Folder");\r
                generalTable.setText(2, 0, "Owner");\r
-               generalTable.setText(3, 0, "Date");\r
+               generalTable.setText(3, 0, "Last modified");\r
                generalTable.setText(4, 0, "Tags");\r
                name.setText(file.getName());\r
                generalTable.setWidget(0, 1, name);\r
@@ -165,7 +147,7 @@ public class FilePropertiesDialog extends DialogBox {
                        generalTable.setText(1, 1, "-");\r
                generalTable.setText(2, 1, file.getOwner());\r
                final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
-               generalTable.setText(3, 1, formatter.format(file.getCreationDate()));\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
@@ -192,9 +174,9 @@ public class FilePropertiesDialog extends DialogBox {
 \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 ClickListener() {\r
-\r
-                       public void onClick(Widget sender) {\r
+               final Button ok = new Button("OK", new ClickHandler() {\r
+                       @Override\r
+                       public void onClick(ClickEvent event) {\r
                                accept();\r
                                closeDialog();\r
                        }\r
@@ -203,16 +185,16 @@ public class FilePropertiesDialog extends DialogBox {
                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 ClickListener() {\r
-\r
-                       public void onClick(Widget sender) {\r
+               final Button cancel = new Button("Cancel", new ClickHandler() {\r
+                       @Override\r
+                       public void onClick(ClickEvent event) {\r
                                closeDialog();\r
                        }\r
                });\r
                buttons.add(cancel);\r
                buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
                buttons.setSpacing(8);\r
-               buttons.addStyleName("gwt-TabPanelBottom");\r
+               buttons.addStyleName("gss-TabPanelBottom");\r
 \r
                generalPanel.add(generalTable);\r
 \r
@@ -230,9 +212,9 @@ public class FilePropertiesDialog extends DialogBox {
                generalPanel.add(allTags);\r
                generalPanel.setSpacing(4);\r
 \r
-               final Button add = new Button("Add Group", new ClickListener() {\r
-\r
-                       public void onClick(Widget sender) {\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
@@ -240,9 +222,9 @@ public class FilePropertiesDialog extends DialogBox {
                permButtons.add(add);\r
                permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);\r
 \r
-               final Button addUser = new Button("Add User", new ClickListener() {\r
-\r
-                       public void onClick(Widget sender) {\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
                        }\r
@@ -252,7 +234,7 @@ public class FilePropertiesDialog extends DialogBox {
 \r
                permButtons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
                permButtons.setSpacing(8);\r
-               permButtons.addStyleName("gwt-TabPanelBottom");\r
+               permButtons.addStyleName("gss-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
@@ -261,11 +243,11 @@ public class FilePropertiesDialog extends DialogBox {
                readForAllNote.setStylePrimaryName("gss-readForAllNote");\r
 \r
                readForAll = new CheckBox();\r
-               readForAll.setChecked(file.isReadForAll());\r
-               readForAll.addClickListener(new ClickListener() {\r
-\r
-                       public void onClick(Widget sender) {\r
-                               if (readForAll.isChecked()) {\r
+               readForAll.setValue(file.isReadForAll());\r
+               readForAll.addClickHandler(new ClickHandler() {\r
+                       @Override\r
+                       public void onClick(ClickEvent event) {\r
+                               if (readForAll.getValue()) {\r
                                        readForAllNote.setVisible(true);\r
                                        pathPanel.setVisible(true);\r
                                }\r
@@ -284,31 +266,31 @@ public class FilePropertiesDialog extends DialogBox {
                        permForAll.add(new Label("Make Public"));\r
                        permForAll.add(readForAll);\r
                        permForAll.setSpacing(8);\r
-                       permForAll.addStyleName("gwt-TabPanelBottom");\r
+                       permForAll.addStyleName("gss-TabPanelBottom");\r
                        permForAll.add(readForAllNote);\r
                        permPanel.add(permForAll);\r
                }\r
 \r
                TextBox path = new TextBox();\r
                path.setWidth("100%");\r
-               path.addClickListener(new ClickListener () {\r
-\r
-                       public void onClick(Widget sender) {\r
+               path.addClickHandler(new ClickHandler() {\r
+                       @Override\r
+                       public void onClick(ClickEvent event) {\r
                                GSS.enableIESelection();\r
-                               ((TextBox) sender).selectAll();\r
+                               ((TextBox) event.getSource()).selectAll();\r
                                GSS.preventIESelection();\r
                        }\r
 \r
                });\r
                path.setText(file.getUri());\r
-               path.setTitle("Use this URI for sharing this file with the world (crtl-C to copy to system clipboard)");\r
+               path.setTitle("Use this URI for sharing this file with the world (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("Sharing URI"));\r
                pathPanel.setSpacing(8);\r
-               pathPanel.addStyleName("gwt-TabPanelBottom");\r
+               pathPanel.addStyleName("gss-TabPanelBottom");\r
                pathPanel.add(path);\r
                pathPanel.setVisible(file.isReadForAll());\r
                permPanel.add(pathPanel);\r
@@ -318,17 +300,17 @@ public class FilePropertiesDialog extends DialogBox {
 \r
                vPanel.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
                vPanel.setSpacing(8);\r
-               vPanel.addStyleName("gwt-TabPanelBottom");\r
+               vPanel.addStyleName("gss-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("gwt-TabPanelBottom");\r
-               Button removeVersionsButton = new Button(images.delete().getHTML(), new ClickListener() {\r
-\r
-                       public void onClick(Widget sender) {\r
+               vPanel2.addStyleName("gss-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
@@ -356,85 +338,33 @@ public class FilePropertiesDialog extends DialogBox {
                outer.add(inner);\r
                outer.add(buttons);\r
                outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);\r
-               outer.addStyleName("gwt-TabPanelBottom");\r
+               outer.addStyleName("gss-TabPanelBottom");\r
 \r
                focusPanel.setFocus(true);\r
                setWidget(outer);\r
        }\r
 \r
-       /**\r
-        * Retrieves all user tags from the server and updates the FlowPanel\r
-        *\r
-        * @param userId\r
-        */\r
-       private void updateTags() {\r
-               GetCommand<TagsResource> tc = new GetCommand<TagsResource>(TagsResource.class, GSS.get().getCurrentUserResource().getTagsPath()) {\r
-\r
-                       @Override\r
-                       public void onComplete() {\r
-                               allTagsContent.clear();\r
-                               TagsResource tagr = getResult();\r
-                               List<String> userTags = tagr.getTags();\r
-                               Iterator t = userTags.iterator();\r
-                               while (t.hasNext()) {\r
-                                       final Button tag = new Button((String) t.next(), new ClickListener() {\r
-\r
-                                               public void onClick(Widget sender) {\r
-                                                       String existing = tags.getText();\r
-                                                       String newTag = ((Button) sender).getText().trim();\r
-                                                       // insert the new tag only if it is not in the list\r
-                                                       // already\r
-                                                       if (existing.indexOf(newTag + ",") == -1 && !existing.trim().endsWith(newTag))\r
-                                                               tags.setText(existing.trim() + (existing.length() > 0 ? ", " : "") + newTag);\r
-                                               }\r
-                                       });\r
-                                       allTagsContent.add(tag);\r
-                               }\r
-                       }\r
-\r
-                       @Override\r
-                       public void onError(Throwable t) {\r
-                               GWT.log("", t);\r
-                               GSS.get().displayError("Unable to fetch user tags");\r
-                       }\r
-               };\r
-               DeferredCommand.addCommand(tc);\r
-\r
-       }\r
-\r
-       @Override\r
-       @SuppressWarnings("fallthrough")\r
-       public boolean onKeyDownPreview(char key, int modifiers) {\r
-               // Use the popup's key preview hooks to close the dialog when either\r
-               // enter or escape is pressed.\r
-               switch (key) {\r
-                       case KeyboardListener.KEY_ENTER:\r
-                               accept();\r
-                       case KeyboardListener.KEY_ESCAPE:\r
-                               closeDialog();\r
-                               break;\r
-               }\r
-\r
-               return true;\r
-       }\r
 \r
        /**\r
         * Accepts any change and updates the file\r
         *\r
-        * @param userId\r
         */\r
-       private void accept() {\r
+       @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
-                       json.put("name", new JSONString(name.getText()));\r
-               if (versioned.isChecked() != file.isVersioned())\r
-                       json.put("versioned", JSONBoolean.getInstance(versioned.isChecked()));\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.isChecked() != file.isReadForAll())\r
+               if (readForAll.getValue() != file.isReadForAll())\r
                        if (file.getOwner().equals(GSS.get().getCurrentUserResource().getUsername()))\r
-                               json.put("readForAll", JSONBoolean.getInstance(readForAll.isChecked()));\r
+                               json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue()));\r
                int i = 0;\r
                if (permList.hasChanges()) {\r
                        GWT.log("Permissions change", null);\r
@@ -470,11 +400,12 @@ public class FilePropertiesDialog extends DialogBox {
                        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().getFileList().updateFileCache(true, false /* do not clear selected file*/);\r
+                               GSS.get().getFileList().updateFileCache(true, false /* do not clear selected file*/, newFilenameFinal);\r
                        }\r
 \r
                        @Override\r
@@ -567,17 +498,5 @@ public class FilePropertiesDialog extends DialogBox {
                DeferredCommand.addCommand(cf);\r
        }\r
 \r
-       public void selectTab(int _tab) {\r
-               inner.selectTab(_tab);\r
-       }\r
-\r
-       /**\r
-        * Enables IE selection prevention and hides the dialog\r
-        * (we disable the prevention on creation of the dialog)\r
-        */\r
-       public void closeDialog() {\r
-               GSS.preventIESelection();\r
-               hide();\r
-       }\r
 \r
 }\r