Replaced simple prompts for creating groups and adding users with normal dialogs
authorChristos Stathis <chstath@ebs.gr>
Wed, 2 May 2012 14:11:59 +0000 (17:11 +0300)
committerChristos Stathis <chstath@ebs.gr>
Wed, 2 May 2012 14:11:59 +0000 (17:11 +0300)
src/gr/grnet/pithos/web/client/AddUserDialog.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/GroupCreateDialog.java [new file with mode: 0644]
src/gr/grnet/pithos/web/client/commands/AddUserCommand.java
src/gr/grnet/pithos/web/client/commands/CreateGroupCommand.java

diff --git a/src/gr/grnet/pithos/web/client/AddUserDialog.java b/src/gr/grnet/pithos/web/client/AddUserDialog.java
new file mode 100644 (file)
index 0000000..a5b7d67
--- /dev/null
@@ -0,0 +1,214 @@
+/*\r
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.\r
+ *\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
+ *   1. Redistributions of source code must retain the above\r
+ *      copyright notice, this list of conditions and the following\r
+ *      disclaimer.\r
+ *\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
+ * 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.foldertree.Resource;\r
+import gr.grnet.pithos.web.client.grouptree.Group;\r
+import gr.grnet.pithos.web.client.rest.PostRequest;\r
+import gr.grnet.pithos.web.client.rest.RestException;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.core.client.Scheduler;\r
+import com.google.gwt.dom.client.NativeEvent;\r
+import com.google.gwt.event.dom.client.ClickEvent;\r
+import com.google.gwt.event.dom.client.ClickHandler;\r
+import com.google.gwt.event.dom.client.KeyCodes;\r
+import com.google.gwt.event.dom.client.KeyDownEvent;\r
+import com.google.gwt.http.client.Response;\r
+import com.google.gwt.http.client.URL;\r
+import com.google.gwt.user.client.Event.NativePreviewEvent;\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.DialogBox;\r
+import com.google.gwt.user.client.ui.FlexTable;\r
+import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
+import com.google.gwt.user.client.ui.TextBox;\r
+import com.google.gwt.user.client.ui.VerticalPanel;\r
+\r
+/**\r
+ * The 'Folder properties' dialog box implementation.\r
+ */\r
+public class AddUserDialog extends DialogBox {\r
+\r
+    protected Pithos app;\r
+\r
+    Group group;\r
+       /**\r
+        * The widget that holds the folderName of the folder.\r
+        */\r
+       TextBox userName = new TextBox();\r
+\r
+       final VerticalPanel inner;\r
+\r
+       /**\r
+        * The widget's constructor.\r
+        */\r
+       public AddUserDialog(final Pithos app, Group _group) {\r
+        this.app = app;\r
+        this.group = _group;\r
+        \r
+               Anchor close = new Anchor();\r
+               close.addStyleName("close");\r
+               close.addClickHandler(new ClickHandler() {\r
+                       \r
+                       @Override\r
+                       public void onClick(ClickEvent event) {\r
+                               hide();\r
+                       }\r
+               });\r
+\r
+               setAnimationEnabled(true);\r
+               setGlassEnabled(true);\r
+               setStyleName("pithos-DialogBox");\r
+\r
+               // Enable IE selection for the dialog (must disable it upon closing it)\r
+               Pithos.enableIESelection();\r
+\r
+               // Use this opportunity to set the dialog's caption.\r
+               setText("Add user");\r
+\r
+               // Outer contains inner and buttons\r
+               VerticalPanel outer = new VerticalPanel();\r
+               outer.add(close);\r
+               // Inner contains generalPanel and permPanel\r
+               inner = new VerticalPanel();\r
+               inner.addStyleName("inner");\r
+\r
+               VerticalPanel generalPanel = new VerticalPanel();\r
+        FlexTable generalTable = new FlexTable();\r
+        generalTable.setText(0, 0, "Username");\r
+\r
+        generalTable.setWidget(0, 1, userName);\r
+\r
+        generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
+        generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");\r
+        generalTable.setCellSpacing(4);\r
+        generalPanel.add(generalTable);\r
+        inner.add(generalPanel);\r
+\r
+        outer.add(inner);\r
+\r
+               // Create the 'Create/Update' button, along with a listener that hides the dialog\r
+               // when the button is clicked and quits the application.\r
+               String okLabel = "Create";\r
+               final Button ok = new Button(okLabel, new ClickHandler() {\r
+                       @Override\r
+                       public void onClick(ClickEvent event) {\r
+                               addUser();\r
+                               closeDialog();\r
+                       }\r
+               });\r
+               ok.addStyleName("button");\r
+               outer.add(ok);\r
+        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);\r
+\r
+        setWidget(outer);\r
+       }\r
+\r
+       @Override\r
+       public void center() {\r
+               super.center();\r
+               userName.setFocus(true);\r
+       }\r
+\r
+       @Override\r
+       protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
+               super.onPreviewNativeEvent(preview);\r
+\r
+               NativeEvent evt = preview.getNativeEvent();\r
+               if (evt.getType().equals(KeyDownEvent.getType().getName()))\r
+                       // Use the popup's key preview hooks to close the dialog when either\r
+                       // enter or escape is pressed.\r
+                       switch (evt.getKeyCode()) {\r
+                               case KeyCodes.KEY_ENTER:\r
+                                       addUser();\r
+                    closeDialog();\r
+                                       break;\r
+                               case KeyCodes.KEY_ESCAPE:\r
+                                       closeDialog();\r
+                                       break;\r
+                       }\r
+       }\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
+               Pithos.preventIESelection();\r
+               hide();\r
+       }\r
+\r
+       /**\r
+        * Generate an RPC request to create a new folder.\r
+        */\r
+       void addUser() {\r
+               String name = userName.getText().trim();\r
+               if (name.length() == 0)\r
+                       return;\r
+       group.addMember(name);\r
+       String path = "?update=";\r
+       PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {\r
+                       \r
+                       @Override\r
+                       public void onSuccess(Resource result) {\r
+                               app.updateGroupNode(group);\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 update group:" + ((RestException) t).getHttpStatusText());\r
+                               }\r
+                               else \r
+                                       app.displayError("System error updating group:" + t.getMessage());\r
+                       }\r
+\r
+                       @Override\r
+                       protected void onUnauthorized(Response response) {\r
+                               app.sessionExpired();\r
+                       }\r
+               };\r
+               updateGroup.setHeader("X-Auth-Token", app.getToken());\r
+               String groupMembers = "";\r
+               for (String u : group.getMembers())\r
+                       groupMembers += (URL.encodePathSegment(u) + ",");\r
+               updateGroup.setHeader("X-Account-Group-" + URL.encodePathSegment(group.getName()), groupMembers);\r
+               Scheduler.get().scheduleDeferred(updateGroup);\r
+       }\r
+}\r
diff --git a/src/gr/grnet/pithos/web/client/GroupCreateDialog.java b/src/gr/grnet/pithos/web/client/GroupCreateDialog.java
new file mode 100644 (file)
index 0000000..d55b6a3
--- /dev/null
@@ -0,0 +1,174 @@
+/*\r
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.\r
+ *\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
+ *   1. Redistributions of source code must retain the above\r
+ *      copyright notice, this list of conditions and the following\r
+ *      disclaimer.\r
+ *\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
+ * 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.foldertree.Folder;\r
+\r
+import com.google.gwt.dom.client.NativeEvent;\r
+import com.google.gwt.event.dom.client.ClickEvent;\r
+import com.google.gwt.event.dom.client.ClickHandler;\r
+import com.google.gwt.event.dom.client.KeyCodes;\r
+import com.google.gwt.event.dom.client.KeyDownEvent;\r
+import com.google.gwt.user.client.Event.NativePreviewEvent;\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.DialogBox;\r
+import com.google.gwt.user.client.ui.FlexTable;\r
+import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
+import com.google.gwt.user.client.ui.TextBox;\r
+import com.google.gwt.user.client.ui.VerticalPanel;\r
+\r
+/**\r
+ * The 'Folder properties' dialog box implementation.\r
+ */\r
+public class GroupCreateDialog extends DialogBox {\r
+\r
+    protected Pithos app;\r
+\r
+       /**\r
+        * The widget that holds the folderName of the folder.\r
+        */\r
+       TextBox groupName = new TextBox();\r
+\r
+       final VerticalPanel inner;\r
+\r
+       /**\r
+        * The widget's constructor.\r
+        */\r
+       public GroupCreateDialog(final Pithos app) {\r
+        this.app = app;\r
+               Anchor close = new Anchor();\r
+               close.addStyleName("close");\r
+               close.addClickHandler(new ClickHandler() {\r
+                       \r
+                       @Override\r
+                       public void onClick(ClickEvent event) {\r
+                               hide();\r
+                       }\r
+               });\r
+\r
+               setAnimationEnabled(true);\r
+               setGlassEnabled(true);\r
+               setStyleName("pithos-DialogBox");\r
+\r
+               // Enable IE selection for the dialog (must disable it upon closing it)\r
+               Pithos.enableIESelection();\r
+\r
+               // Use this opportunity to set the dialog's caption.\r
+               setText("Create group");\r
+\r
+               // Outer contains inner and buttons\r
+               VerticalPanel outer = new VerticalPanel();\r
+               outer.add(close);\r
+               // Inner contains generalPanel and permPanel\r
+               inner = new VerticalPanel();\r
+               inner.addStyleName("inner");\r
+\r
+               VerticalPanel generalPanel = new VerticalPanel();\r
+        FlexTable generalTable = new FlexTable();\r
+        generalTable.setText(0, 0, "Name");\r
+\r
+        generalTable.setWidget(0, 1, groupName);\r
+\r
+        generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");\r
+        generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");\r
+        generalTable.setCellSpacing(4);\r
+        generalPanel.add(generalTable);\r
+        inner.add(generalPanel);\r
+\r
+        outer.add(inner);\r
+\r
+               // Create the 'Create/Update' button, along with a listener that hides the dialog\r
+               // when the button is clicked and quits the application.\r
+               String okLabel = "Create";\r
+               final Button ok = new Button(okLabel, new ClickHandler() {\r
+                       @Override\r
+                       public void onClick(ClickEvent event) {\r
+                               createGroup();\r
+                               closeDialog();\r
+                       }\r
+               });\r
+               ok.addStyleName("button");\r
+               outer.add(ok);\r
+        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);\r
+\r
+        setWidget(outer);\r
+       }\r
+\r
+       @Override\r
+       public void center() {\r
+               super.center();\r
+               groupName.setFocus(true);\r
+       }\r
+\r
+       @Override\r
+       protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
+               super.onPreviewNativeEvent(preview);\r
+\r
+               NativeEvent evt = preview.getNativeEvent();\r
+               if (evt.getType().equals(KeyDownEvent.getType().getName()))\r
+                       // Use the popup's key preview hooks to close the dialog when either\r
+                       // enter or escape is pressed.\r
+                       switch (evt.getKeyCode()) {\r
+                               case KeyCodes.KEY_ENTER:\r
+                                       createGroup();\r
+                    closeDialog();\r
+                                       break;\r
+                               case KeyCodes.KEY_ESCAPE:\r
+                                       closeDialog();\r
+                                       break;\r
+                       }\r
+       }\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
+               Pithos.preventIESelection();\r
+               hide();\r
+       }\r
+\r
+       /**\r
+        * Generate an RPC request to create a new folder.\r
+        */\r
+       private void createGroup() {\r
+               String name = groupName.getText().trim();\r
+               if (name.length() == 0)\r
+                       return;\r
+               app.addGroup(name);\r
+       }\r
+}\r
index 075fb5a..5fe90a8 100644 (file)
@@ -34,6 +34,7 @@
  */
 package gr.grnet.pithos.web.client.commands;
 
+import gr.grnet.pithos.web.client.AddUserDialog;
 import gr.grnet.pithos.web.client.Pithos;
 import gr.grnet.pithos.web.client.foldertree.Resource;
 import gr.grnet.pithos.web.client.grouptree.Group;
@@ -72,39 +73,7 @@ public class AddUserCommand implements Command {
        public void execute() {
         if (containerPanel != null)
                    containerPanel.hide();
-        String username = Window.prompt("Enter username:", "");
-        if (username != null && username.length() > 0) {
-               group.addMember(username);
-               String path = "?update=";
-               PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
-                               
-                               @Override
-                               public void onSuccess(Resource result) {
-                                       app.updateGroupNode(group);
-                               }
-                               
-                               @Override
-                               public void onError(Throwable t) {
-                                       GWT.log("", t);
-                                       app.setError(t);
-                                       if (t instanceof RestException) {
-                                               app.displayError("Unable to update group:" + ((RestException) t).getHttpStatusText());
-                                       }
-                                       else 
-                                               app.displayError("System error updating group:" + t.getMessage());
-                               }
-
-                               @Override
-                               protected void onUnauthorized(Response response) {
-                                       app.sessionExpired();
-                               }
-                       };
-                       updateGroup.setHeader("X-Auth-Token", app.getToken());
-                       String groupMembers = "";
-                       for (String u : group.getMembers())
-                               groupMembers += (URL.encodePathSegment(u) + ",");
-                       updateGroup.setHeader("X-Account-Group-" + URL.encodePathSegment(group.getName()), groupMembers);
-                       Scheduler.get().scheduleDeferred(updateGroup);
-        }
+        AddUserDialog dlg = new AddUserDialog(app, group);
+        dlg.center();
        }
 }
index aafb805..95dc5e6 100644 (file)
@@ -34,6 +34,7 @@
  */
 package gr.grnet.pithos.web.client.commands;
 
+import gr.grnet.pithos.web.client.GroupCreateDialog;
 import gr.grnet.pithos.web.client.Pithos;
 
 import com.google.gwt.user.client.Command;
@@ -61,9 +62,7 @@ public class CreateGroupCommand implements Command {
        public void execute() {
         if (containerPanel != null)
                    containerPanel.hide();
-        String groupname = Window.prompt("Enter group name:", "");
-        if (groupname != null && groupname.length() > 0) {
-               app.addGroup(groupname);
-        }
+        GroupCreateDialog dlg = new GroupCreateDialog(app);
+        dlg.center();
        }
 }