From: Jouni Koivuviita Date: Wed, 2 Apr 2008 07:28:01 +0000 (+0000) Subject: Fix: IEmbedded won't through exceptions for null-source values. X-Git-Tag: 6.7.0.beta1~4918 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=17e1e59fdf57076e0efdc1bd158dabdbb3023dbe;p=vaadin-framework.git Fix: IEmbedded won't through exceptions for null-source values. 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 --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java index 0bcdea61c0..d6e74fe5b3 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java @@ -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) { diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IEmbedded.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IEmbedded.java index 09c1a2ee87..50b3c3cfe4 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IEmbedded.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IEmbedded.java @@ -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) { diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java index 0874a38e6e..851e6c5628 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java @@ -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")); diff --git a/src/com/itmill/toolkit/tests/TestBench.java b/src/com/itmill/toolkit/tests/TestBench.java index 7245e0aece..b3ee2da104 100644 --- a/src/com/itmill/toolkit/tests/TestBench.java +++ b/src/com/itmill/toolkit/tests/TestBench.java @@ -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(); diff --git a/src/com/itmill/toolkit/tests/testbench/TestBench.java b/src/com/itmill/toolkit/tests/testbench/TestBench.java index dcf41a3ca0..adab11ca1b 100644 --- a/src/com/itmill/toolkit/tests/testbench/TestBench.java +++ b/src/com/itmill/toolkit/tests/testbench/TestBench.java @@ -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();