Formating commit. Comments fixed after code review. 1. Added a 2010 entry in copyrigh...
[pithos] / src / gr / ebs / gss / client / AbstractPropertiesDialog.java
index d54685a..df33037 100644 (file)
@@ -25,15 +25,17 @@ import java.util.Iterator;
 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.Event.NativePreviewEvent;\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.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.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
@@ -77,7 +80,7 @@ public abstract class AbstractPropertiesDialog extends DialogBox {
         * @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
@@ -86,11 +89,13 @@ public abstract class AbstractPropertiesDialog extends DialogBox {
                                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
+                                       final Button tag = new Button((String) t.next(), 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 = ((Button) 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
@@ -119,19 +124,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