]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix: IEmbedded won't through exceptions for null-source values.
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Wed, 2 Apr 2008 07:28:01 +0000 (07:28 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Wed, 2 Apr 2008 07:28:01 +0000 (07:28 +0000)
Fix: IOrderedLayout now handles component additions in between old components with captions (previously the insertion index was calculated wrong because of the caption elements were included in the index).
Small fixes to TestBench.

svn changeset:4107/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IEmbedded.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
src/com/itmill/toolkit/tests/TestBench.java
src/com/itmill/toolkit/tests/testbench/TestBench.java

index 0bcdea61c0353298c7f0c93f5439789561ca6546..d6e74fe5b39185d51f166f5b7f085824e49f8096 100755 (executable)
@@ -121,7 +121,7 @@ public class ApplicationConnection {
 
         initializeClientHooks();
 
-        // TODO remove hardcoded id name
+        // TODO remove hard coded id name
         view = new IView("itmill-ajax-window");
 
         makeUidlRequest("repaintAll=1");
@@ -758,6 +758,9 @@ public class ApplicationConnection {
      * @return translated URI ready for browser
      */
     public String translateToolkitUri(String toolkitUri) {
+        if (toolkitUri == null) {
+            return null;
+        }
         if (toolkitUri.startsWith("theme://")) {
             final String themeUri = getThemeUri();
             if (themeUri == null) {
index 09c1a2ee87e4144761ba354ff11a5c094f87542d..50b3c3cfe40ab6086bb3b58c8109101d6d1f3ea1 100644 (file)
@@ -73,7 +73,11 @@ public class IEmbedded extends HTML implements Paintable {
      * @return
      */
     private String getSrc(UIDL uidl, ApplicationConnection client) {
-        return client.translateToolkitUri(uidl.getStringAttribute("src"));
+        String url =  client.translateToolkitUri(uidl.getStringAttribute("src"));
+        if (url == null) {
+            return "";
+        }
+        return url;
     }
 
     public void setWidth(String width) {
index 0874a38e6e1ac4a6c988c4e1e39b0edde5342d31..851e6c56288a65d4b7329462c89ca418847be59d 100644 (file)
@@ -140,7 +140,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
                 // TODO this might be optimized by moving only container element
                 // to correct position
                 removeCaption(child);
-                int index = getWidgetIndex(oldChild);
+                int index = getPaintableIndex(oldChild);
                 if (componentToCaption.containsKey(oldChild)) {
                     index--;
                 }
@@ -148,7 +148,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
                 this.insert(child, index);
             } else {
                 // insert new child before old one
-                final int index = getWidgetIndex(oldChild);
+                final int index = getPaintableIndex(oldChild); // TODO this returns wrong value if captions are used
                 insert(child, index);
             }
             ((Paintable) child).updateFromUIDL(childUidl, client);
@@ -215,7 +215,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
             remove(c);
             componentToCaption.remove(c);
         }
-        final int index = getWidgetIndex(from);
+        final int index = getPaintableIndex(from);
         if (index >= 0) {
             remove(index);
             insert(to, index);
@@ -240,7 +240,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
     }
 
     public boolean hasChildComponent(Widget component) {
-        return getWidgetIndex(component) >= 0;
+        return getPaintableIndex(component) >= 0;
     }
 
     public void updateCaption(Paintable component, UIDL uidl) {
@@ -249,7 +249,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
 
         if (Caption.isNeeded(uidl)) {
             if (c == null) {
-                final int index = getWidgetIndex((Widget) component);
+                final int index = getPaintableIndex((Widget) component);
                 c = new Caption(component, client);
                 insert(c, index);
                 componentToCaption.put(component, c);
@@ -305,6 +305,30 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
         return getChildren().indexOf(child);
     }
 
+    public int getPaintableCount() {
+        int size = 0;
+        for(Iterator it = getChildren().iterator(); it.hasNext();) {
+            Widget w = (Widget) it.next();
+            if (!(w instanceof Caption)) {
+                size++;
+            }
+        }
+        return size;
+    }
+
+    public int getPaintableIndex(Widget child) {
+        int i = 0;
+        for(Iterator it = getChildren().iterator(); it.hasNext();) {
+            Widget w = (Widget) it.next();
+            if (w == child) {
+                return i;
+            } else if (!(w instanceof Caption)) {
+                i++;
+            }
+        }
+        return -1;
+    }
+
     protected void handleMargins(UIDL uidl) {
         final MarginInfo margins = new MarginInfo(uidl
                 .getIntAttribute("margins"));
index 7245e0aece5b9fa27efcbf85f7be1f3a2641afe3..b3ee2da10411c646f68716d747894ade5e71400b 100644 (file)
@@ -42,7 +42,8 @@ public class TestBench extends com.itmill.toolkit.Application implements
     String[] testablePackages = { "com.itmill.toolkit.tests",
             "com.itmill.toolkit.demo", "com.itmill.toolkit.demo.colorpicker",
             "com.itmill.toolkit.demo.reservation",
-            "com.itmill.toolkit.demo.features" };
+            "com.itmill.toolkit.demo.features",
+            "com.itmill.toolkit.tests.tickets"};
 
     HierarchicalContainer testables = new HierarchicalContainer();
 
@@ -75,12 +76,14 @@ public class TestBench extends com.itmill.toolkit.Application implements
                         testables.addItem(t);
                         itemCaptions.put(t, t.getName());
                         testables.setParent(t, testablePackages[p]);
+                        testables.setChildrenAllowed(t, false);
                         continue;
                     } catch (final Exception e) {
                         try {
                             testables.addItem(t);
                             itemCaptions.put(t, t.getName());
                             testables.setParent(t, testablePackages[p]);
+                            testables.setChildrenAllowed(t, false);
                             continue;
                         } catch (final Exception e1) {
                             e1.printStackTrace();
index dcf41a3ca01825e1fe4ec63979ac82c31341d5d7..adab11ca1b26404b7b600c7620fac37d97756693 100644 (file)
@@ -38,7 +38,7 @@ public class TestBench extends com.itmill.toolkit.Application implements
         Property.ValueChangeListener {
 
     // Add here packages which are used for finding testable classes
-    String[] testablePackages = { "com.itmill.toolkit.demo.testbench" };
+    String[] testablePackages = { "com.itmill.toolkit.demo.testbench", "com.itmill.toolkit.tests.tickets" };
 
     HierarchicalContainer testables = new HierarchicalContainer();
 
@@ -71,12 +71,14 @@ public class TestBench extends com.itmill.toolkit.Application implements
                         testables.addItem(t);
                         itemCaptions.put(t, t.getName());
                         testables.setParent(t, testablePackages[p]);
+                        testables.setChildrenAllowed(t, false);
                         continue;
                     } catch (final Exception e) {
                         try {
                             testables.addItem(t);
                             itemCaptions.put(t, t.getName());
                             testables.setParent(t, testablePackages[p]);
+                            testables.setChildrenAllowed(t, false);
                             continue;
                         } catch (final Exception e1) {
                             e1.printStackTrace();