]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #2909 + cleanup and generics for UIDL class
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 20 May 2009 10:42:21 +0000 (10:42 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 20 May 2009 10:42:21 +0000 (10:42 +0000)
svn changeset:7915/svn branch:6.0

src/com/vaadin/terminal/gwt/client/UIDL.java
src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java
src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java
src/com/vaadin/terminal/gwt/client/ui/VOrderedLayout.java

index 8429c8a0d9d66ad2ce0491ee15e909d136ab6b5a..0fa0672a1522c7dbaa6fe559ee81f7403a2055b2 100644 (file)
@@ -8,6 +8,8 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import com.google.gwt.event.logical.shared.OpenEvent;
+import com.google.gwt.event.logical.shared.OpenHandler;
 import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONBoolean;
 import com.google.gwt.json.client.JSONNumber;
@@ -17,7 +19,6 @@ import com.google.gwt.json.client.JSONValue;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.ui.Tree;
 import com.google.gwt.user.client.ui.TreeItem;
-import com.google.gwt.user.client.ui.TreeListener;
 
 public class UIDL {
 
@@ -47,8 +48,9 @@ public class UIDL {
         return ((JSONString) val).stringValue();
     }
 
-    public Set getAttributeNames() {
-        final HashSet attrs = new HashSet(((JSONObject) json.get(1)).keySet());
+    public Set<String> getAttributeNames() {
+        final HashSet<String> attrs = new HashSet<String>(((JSONObject) json
+                .get(1)).keySet());
         attrs.remove("v");
         return attrs;
     }
@@ -58,7 +60,7 @@ public class UIDL {
         if (val == null) {
             return 0;
         }
-        final double num = ((JSONNumber) val).getValue();
+        final double num = val.isNumber().doubleValue();
         return (int) num;
     }
 
@@ -67,7 +69,7 @@ public class UIDL {
         if (val == null) {
             return 0;
         }
-        final double num = ((JSONNumber) val).getValue();
+        final double num = val.isNumber().doubleValue();
         return (long) num;
     }
 
@@ -76,7 +78,7 @@ public class UIDL {
         if (val == null) {
             return 0;
         }
-        final double num = ((JSONNumber) val).getValue();
+        final double num = val.isNumber().doubleValue();
         return (float) num;
     }
 
@@ -85,7 +87,7 @@ public class UIDL {
         if (val == null) {
             return 0;
         }
-        final double num = ((JSONNumber) val).getValue();
+        final double num = val.isNumber().doubleValue();
         return num;
     }
 
@@ -94,7 +96,7 @@ public class UIDL {
         if (val == null) {
             return false;
         }
-        return ((JSONBoolean) val).booleanValue();
+        return val.isBoolean().booleanValue();
     }
 
     public String[] getStringArrayAttribute(String name) {
@@ -115,9 +117,9 @@ public class UIDL {
         return s;
     }
 
-    public HashSet getStringArrayAttributeAsSet(String string) {
+    public HashSet<String> getStringArrayAttributeAsSet(String string) {
         final JSONArray a = getArrayVariable(string);
-        final HashSet s = new HashSet();
+        final HashSet<String> s = new HashSet<String>();
         for (int i = 0; i < a.size(); i++) {
             s.add(((JSONString) a.get(i)).stringValue());
         }
@@ -161,9 +163,9 @@ public class UIDL {
                 + " is not of type String");
     }
 
-    public Iterator getChildIterator() {
+    public Iterator<Object> getChildIterator() {
 
-        return new Iterator() {
+        return new Iterator<Object>() {
 
             int index = 2;
 
@@ -204,8 +206,8 @@ public class UIDL {
     public String toString() {
         String s = "<" + getTag();
 
-        for (final Iterator i = getAttributeNames().iterator(); i.hasNext();) {
-            final String name = i.next().toString();
+        Set<String> attributeNames = getAttributeNames();
+        for (String name : attributeNames) {
             s += " " + name + "=";
             final JSONValue v = ((JSONObject) json.get(1)).get(name);
             if (v.isString() != null) {
@@ -217,7 +219,7 @@ public class UIDL {
 
         s += ">\n";
 
-        final Iterator i = getChildIterator();
+        final Iterator<Object> i = getChildIterator();
         while (i.hasNext()) {
             final Object c = i.next();
             s += c.toString();
@@ -230,7 +232,7 @@ public class UIDL {
 
     public String getChildrenAsXML() {
         String s = "";
-        final Iterator i = getChildIterator();
+        final Iterator<Object> i = getChildIterator();
         while (i.hasNext()) {
             final Object c = i.next();
             s += c.toString();
@@ -250,25 +252,22 @@ public class UIDL {
             final TreeItem root = new TreeItem(getTag());
             addItem(root);
             root.addItem("");
-            addTreeListener(new TreeListener() {
+            addOpenHandler(new OpenHandler<TreeItem>() {
+                boolean isLoaded;
 
-                public void onTreeItemStateChanged(TreeItem item) {
-                    if (item == root) {
+                public void onOpen(OpenEvent<TreeItem> event) {
+                    TreeItem item = event.getTarget();
+                    if (item == root && !isLoaded) {
                         removeItem(root);
-                        VUIDLBrowser.this.removeTreeListener(this);
                         addItem(dir());
-                        final Iterator it = treeItemIterator();
+                        final Iterator<TreeItem> it = treeItemIterator();
                         while (it.hasNext()) {
-                            ((TreeItem) it.next()).setState(true);
+                            it.next().setState(true);
                         }
+                        isLoaded = true;
                     }
                 }
-
-                public void onTreeItemSelected(TreeItem item) {
-                }
-
             });
-
         }
 
         @Override
@@ -281,8 +280,8 @@ public class UIDL {
     public TreeItem dir() {
 
         String nodeName = getTag();
-        for (final Iterator i = getAttributeNames().iterator(); i.hasNext();) {
-            final String name = i.next().toString();
+        Set<String> attributeNames = getAttributeNames();
+        for (String name : attributeNames) {
             final String value = getAttribute(name);
             nodeName += " " + name + "=" + value;
         }
@@ -290,9 +289,8 @@ public class UIDL {
 
         try {
             TreeItem tmp = null;
-            for (final Iterator i = getVariableHash().keySet().iterator(); i
-                    .hasNext();) {
-                final String name = i.next().toString();
+            Set<String> keySet = getVariableHash().keySet();
+            for (String name : keySet) {
                 String value = "";
                 try {
                     value = getStringVariable(name);
@@ -321,7 +319,7 @@ public class UIDL {
             // Ignored, no variables
         }
 
-        final Iterator i = getChildIterator();
+        final Iterator<Object> i = getChildIterator();
         while (i.hasNext()) {
             final Object child = i.next();
             try {
@@ -344,12 +342,12 @@ public class UIDL {
     }
 
     public boolean hasVariable(String name) {
-        Object v = null;
-        try {
-            v = getVariableHash().get(name);
-        } catch (final IllegalArgumentException e) {
+        final JSONObject variables = (JSONObject) ((JSONObject) json.get(1))
+                .get("v");
+        if (variables == null) {
+            return false;
         }
-        return v != null;
+        return variables.keySet().contains(name);
     }
 
     public String getStringVariable(String name) {
@@ -365,7 +363,7 @@ public class UIDL {
         if (t == null) {
             throw new IllegalArgumentException("No such variable: " + name);
         }
-        return (int) t.getValue();
+        return (int) t.doubleValue();
     }
 
     public long getLongVariable(String name) {
@@ -373,7 +371,7 @@ public class UIDL {
         if (t == null) {
             throw new IllegalArgumentException("No such variable: " + name);
         }
-        return (long) t.getValue();
+        return (long) t.doubleValue();
     }
 
     public float getFloatVariable(String name) {
@@ -381,7 +379,7 @@ public class UIDL {
         if (t == null) {
             throw new IllegalArgumentException("No such variable: " + name);
         }
-        return (float) t.getValue();
+        return (float) t.doubleValue();
     }
 
     public double getDoubleVariable(String name) {
@@ -389,7 +387,7 @@ public class UIDL {
         if (t == null) {
             throw new IllegalArgumentException("No such variable: " + name);
         }
-        return t.getValue();
+        return t.doubleValue();
     }
 
     public boolean getBooleanVariable(String name) {
@@ -431,7 +429,7 @@ public class UIDL {
         final int[] s = new int[a.size()];
         for (int i = 0; i < a.size(); i++) {
             final JSONValue v = a.get(i);
-            s[i] = v.isNumber() != null ? (int) ((JSONNumber) v).getValue()
+            s[i] = v.isNumber() != null ? (int) v.isNumber().doubleValue()
                     : Integer.parseInt(v.toString());
         }
         return s;
@@ -446,8 +444,8 @@ public class UIDL {
 
         public String getXMLAsString() {
             final StringBuffer sb = new StringBuffer();
-            for (final Iterator it = x.keySet().iterator(); it.hasNext();) {
-                final String tag = (String) it.next();
+            Set<String> keySet = x.keySet();
+            for (String tag : keySet) {
                 sb.append("<");
                 sb.append(tag);
                 sb.append(">");
index 0e1f56039a38b74b9b91c97325eb45d4fff6fddd..bd778c8d5ca64fb85e90ca23803f1a3246b85e63 100644 (file)
@@ -132,9 +132,9 @@ public class VAbsoluteLayout extends ComplexPanel implements Container {
         HashSet<String> unrenderedPids = new HashSet<String>(
                 pidToComponentWrappper.keySet());
 
-        for (Iterator<UIDL> childIterator = uidl.getChildIterator(); childIterator
+        for (Iterator<Object> childIterator = uidl.getChildIterator(); childIterator
                 .hasNext();) {
-            UIDL cc = childIterator.next();
+            UIDL cc = (UIDL) childIterator.next();
             UIDL componentUIDL = cc.getChildUIDL(0);
             unrenderedPids.remove(componentUIDL.getId());
             getWrapper(client, componentUIDL).updateFromUIDL(cc);
index a085ceb9ff7d30a7273cc2f898caef2002e280a5..b968390edb49a9bf3ea13bd291a7d85a3f093d5b 100644 (file)
@@ -128,13 +128,13 @@ public class VMenuBar extends Widget implements Paintable, PopupListener {
         }
 
         UIDL uidlItems = uidl.getChildUIDL(1);
-        Iterator<UIDL> itr = uidlItems.getChildIterator();
-        Stack<Iterator<UIDL>> iteratorStack = new Stack<Iterator<UIDL>>();
+        Iterator<Object> itr = uidlItems.getChildIterator();
+        Stack<Iterator<Object>> iteratorStack = new Stack<Iterator<Object>>();
         Stack<VMenuBar> menuStack = new Stack<VMenuBar>();
         VMenuBar currentMenu = this;
 
         while (itr.hasNext()) {
-            UIDL item = itr.next();
+            UIDL item = (UIDL) itr.next();
             CustomMenuItem currentItem = null;
 
             String itemText = item.getStringAttribute("text");
index 5dff7155482d5bb7646c655a734d24d58198ce3e..9df20f7e3313362bb6a1c23ae1bb9178a6e1ea19 100644 (file)
@@ -77,8 +77,8 @@ public class VOrderedLayout extends CellBasedLayout {
         ArrayList<UIDL> relativeSizeComponentUIDL = new ArrayList<UIDL>();\r
 \r
         int pos = 0;\r
-        for (final Iterator<UIDL> it = uidl.getChildIterator(); it.hasNext();) {\r
-            final UIDL childUIDL = it.next();\r
+        for (final Iterator<Object> it = uidl.getChildIterator(); it.hasNext();) {\r
+            final UIDL childUIDL = (UIDL) it.next();\r
             final Paintable child = client.getPaintable(childUIDL);\r
             Widget widget = (Widget) child;\r
 \r