Enable focus inside the text box when creating a new group. This solves Issue 36.
[pithos] / src / gr / ebs / gss / client / AbstractPropertiesDialog.java
index d54685a..b940e66 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.\r
+ * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.\r
  *\r
  * This file is part of GSS.\r
  *\r
@@ -21,19 +21,21 @@ package gr.ebs.gss.client;
 import gr.ebs.gss.client.rest.GetCommand;\r
 import gr.ebs.gss.client.rest.resource.TagsResource;\r
 \r
-import java.util.Iterator;\r
 import java.util.List;\r
 \r
 import com.google.gwt.core.client.GWT;\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.user.client.DeferredCommand;\r
-import com.google.gwt.user.client.ui.Button;\r
-import com.google.gwt.user.client.ui.ClickListener;\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.DialogBox;\r
 import com.google.gwt.user.client.ui.FlowPanel;\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.Widget;\r
 \r
 /**\r
  * Abstract class, parent of all 'File properties' dialog boxes.\r
@@ -42,6 +44,7 @@ import com.google.gwt.user.client.ui.Widget;
  */\r
 public abstract class AbstractPropertiesDialog extends DialogBox {\r
 \r
+       protected static final String MULTIPLE_VALUES_TEXT = "(Multiple values)";\r
 \r
        /**\r
         * Text box with the tags associated with the file\r
@@ -70,34 +73,42 @@ public abstract class AbstractPropertiesDialog extends DialogBox {
                setAnimationEnabled(true);\r
 \r
        }\r
-\r
        /**\r
         * Retrieves all user tags from the server and updates the FlowPanel\r
         *\r
         * @param userId\r
         */\r
        protected void updateTags() {\r
-               GetCommand<TagsResource> tc = new GetCommand<TagsResource>(TagsResource.class, GSS.get().getCurrentUserResource().getTagsPath()) {\r
+               GetCommand<TagsResource> tc = new GetCommand<TagsResource>(TagsResource.class, GSS.get().getCurrentUserResource().getTagsPath(),null) {\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
+                               Anchor tag = null;\r
+                               for(String usrTag : userTags){\r
+                                       tag = new Anchor(usrTag.toString(), false);\r
+                                       tag.addStyleName("gss-tag");\r
+                                       allTagsContent.add(tag);\r
+                                       Label separator = new Label(", ");\r
+                                       separator.addStyleName("gss-tag");\r
+                                       allTagsContent.add(separator);\r
+                                       tag.addClickHandler( new ClickHandler() {\r
 \r
-                                               public void onClick(Widget sender) {\r
+                                               @Override\r
+                                               public void onClick(ClickEvent event) {\r
                                                        String existing = tags.getText();\r
-                                                       String newTag = ((Button) sender).getText().trim();\r
+                                                       if (MULTIPLE_VALUES_TEXT.equals(existing)) existing = "";\r
+                                                       String newTag = ((Anchor) event.getSource()).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
+                                                       if (existing.indexOf(newTag) == -1 && !existing.trim().endsWith(newTag))\r
+                                                               tags.setText(existing.trim()\r
+                                                                                       + (existing.length() > 0 ? ", " : "")\r
+                                                                                       + newTag);\r
                                                }\r
                                        });\r
-                                       allTagsContent.add(tag);\r
                                }\r
                        }\r
 \r
@@ -119,19 +130,22 @@ public abstract class AbstractPropertiesDialog extends DialogBox {
 \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
+       protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
+           super.onPreviewNativeEvent(preview);\r
+\r
+           NativeEvent evt = preview.getNativeEvent();\r
+           if (evt.getType().equals("keydown"))\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
+                               accept();\r
+                           case KeyCodes.KEY_ESCAPE:\r
+                             closeDialog();\r
+                             break;\r
+                         }\r
+         }\r
+\r
 \r
 \r
        public void selectTab(int _tab) {\r