diff --git a/zk/src/main/java/org/zkoss/zk/ui/AbstractComponent.java b/zk/src/main/java/org/zkoss/zk/ui/AbstractComponent.java index a5bb20925cc..81291b947fa 100644 --- a/zk/src/main/java/org/zkoss/zk/ui/AbstractComponent.java +++ b/zk/src/main/java/org/zkoss/zk/ui/AbstractComponent.java @@ -1416,8 +1416,6 @@ public boolean insertBefore(Component newChild, Component refChild) { ++_chdinf.nChild; onChildAdded(nc); triggerAfterHostChildAdded(nc); - //F80 - store subtree's binder annotation count - updateSubBindingAnnotationCount(nc.initAuxInfo().subAnnotCnt); } return true; } @@ -1589,8 +1587,6 @@ public boolean removeChild(Component child) { ++_chdinf.modCntChd; --_chdinf.nChild; onChildRemoved(child); - //F80 - store subtree's binder annotation count - updateSubBindingAnnotationCount(-oc.initAuxInfo().subAnnotCnt); triggerAfterHostChildRemoved(child); return true; } @@ -4250,16 +4246,18 @@ protected void updateSubBindingAnnotationCount(int diff) { protected void setSubBindingAnnotationCount(int diff, AbstractComponent node) { AuxInfo auxInfo = node.initAuxInfo(); - // the minimum value of subAnnotCnt is 1 if hasBindingAnnotInfo is true. - auxInfo.subAnnotCnt = Math.max(auxInfo.subAnnotCnt + diff, auxInfo.hasBindingAnnotInfo ? 1 : 0); - + // Don't update the count for itself + if (node != this) { + auxInfo.subAnnotCnt += diff; + } } private void initBindingAnnotation() { AuxInfo auxinf = initAuxInfo(); auxinf.hasBindingAnnotInfo = true; - auxinf.subAnnotCnt = 1; // init to 1 for itself - enableBindingAnnotation(); + auxinf.subAnnotCnt = 1; + auxinf.hasBindingAnnot = true; + updateSubBindingAnnotationCount(1); // init to 1 for itself } public void enableBindingAnnotation() { @@ -4274,10 +4272,10 @@ private void toggleBindingAnnotationAndUpdateCount(boolean hasBindingAnnot) { AuxInfo auxinf = initAuxInfo(); boolean old = auxinf.hasBindingAnnot; if (old != hasBindingAnnot) { - int diff = hasBindingAnnot ? 1 : -1; + int multiply = hasBindingAnnot ? 1 : -1; auxinf.hasBindingAnnot = hasBindingAnnot; if (auxinf.subAnnotCnt > 0) { - updateSubBindingAnnotationCount(diff * auxinf.subAnnotCnt); + updateSubBindingAnnotationCount(multiply * auxinf.subAnnotCnt); } } } diff --git a/zktest/src/test/java/org/zkoss/zktest/zats/bind/parser/F80_Parser_StoreSubAnnotCntTest.java b/zktest/src/test/java/org/zkoss/zktest/zats/bind/parser/F80_Parser_StoreSubAnnotCntTest.java index f5a63cce2e2..7f963a8265e 100644 --- a/zktest/src/test/java/org/zkoss/zktest/zats/bind/parser/F80_Parser_StoreSubAnnotCntTest.java +++ b/zktest/src/test/java/org/zkoss/zktest/zats/bind/parser/F80_Parser_StoreSubAnnotCntTest.java @@ -88,69 +88,69 @@ public void test() { assertEquals(w3_scnt, l3_scnt + testb2_scnt + testb3_scnt + l5_scnt + 1); assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt); - //Event - add bind annotation - ComponentAgent add_b = desktop.query("#root #add_bind"); - add_b.click(); - ComponentAgent l4 = desktop.query("#root #w3").getLastChild(); - int l4_scnt = l4.as(Label.class).getSubBindingAnnotationCount(); - assertEquals(l4_scnt, 1); - w3_scnt = w3.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(w3_scnt, l3_scnt + testb2_scnt + testb3_scnt + l5_scnt + l4_scnt + 1); - rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt); - - //Event - remove binding one - ComponentAgent remove_binding_one = desktop.query("#root #remove_binding_one"); - remove_binding_one.click(); - testb2_scnt = testb2.as(Button.class).getSubBindingAnnotationCount(); - assertEquals(testb2_scnt, 1); - w3_scnt = w3.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(w3_scnt, l3_scnt + testb2_scnt + testb3_scnt + l5_scnt + l4_scnt + 1); - rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt); + //Event - add bind annotation (not supported since ZK 10) +// ComponentAgent add_b = desktop.query("#root #add_bind"); +// add_b.click(); +// ComponentAgent l4 = desktop.query("#root #w3").getLastChild(); +// int l4_scnt = l4.as(Label.class).getSubBindingAnnotationCount(); +// assertEquals(l4_scnt, 1); +// w3_scnt = w3.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(w3_scnt, l3_scnt + testb2_scnt + testb3_scnt + l5_scnt + l4_scnt + 1); +// rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt); + + //Event - remove binding one (not supported since ZK 10) +// ComponentAgent remove_binding_one = desktop.query("#root #remove_binding_one"); +// remove_binding_one.click(); +// testb2_scnt = testb2.as(Button.class).getSubBindingAnnotationCount(); +// assertEquals(testb2_scnt, 1); +// w3_scnt = w3.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(w3_scnt, l3_scnt + testb2_scnt + testb3_scnt + l5_scnt + l4_scnt + 1); +// rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt); //Event - remove binding all - ComponentAgent remove_binding_all = desktop.query("#root #remove_binding_all"); - remove_binding_all.click(); - testb3_scnt = testb3.as(Button.class).getSubBindingAnnotationCount(); - assertEquals(testb3_scnt, 0); - w3_scnt = w3.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(w3_scnt, l3_scnt + testb2_scnt + testb3_scnt + l5_scnt + l4_scnt + 1); - rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt); +// ComponentAgent remove_binding_all = desktop.query("#root #remove_binding_all"); +// remove_binding_all.click(); +// testb3_scnt = testb3.as(Button.class).getSubBindingAnnotationCount(); +// assertEquals(testb3_scnt, 0); +// w3_scnt = w3.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(w3_scnt, l3_scnt + testb2_scnt + testb3_scnt + l5_scnt + l4_scnt + 1); +// rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt); //Event - more bind annotation - add_b.click(); - l4_scnt = l4.as(Label.class).getSubBindingAnnotationCount(); - assertEquals(l4_scnt, 1); - rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt); +// add_b.click(); +// l4_scnt = l4.as(Label.class).getSubBindingAnnotationCount(); +// assertEquals(l4_scnt, 1); +// rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt); //Event - add and bind first - ComponentAgent add_bf = desktop.query("#root #add_bindfirst"); - add_bf.click(); - ComponentAgent w_bf = desktop.query("#root").getLastChild(); - ComponentAgent l_bf = w_bf.getFirstChild(); - int l_bf_scnt = l_bf.as(Label.class).getSubBindingAnnotationCount(); - assertEquals(l_bf_scnt, 1); - - int w_bf_scnt = w_bf.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(w_bf_scnt, l_bf_scnt + 1); - - rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt + w_bf_scnt); +// ComponentAgent add_bf = desktop.query("#root #add_bindfirst"); +// add_bf.click(); +// ComponentAgent w_bf = desktop.query("#root").getLastChild(); +// ComponentAgent l_bf = w_bf.getFirstChild(); +// int l_bf_scnt = l_bf.as(Label.class).getSubBindingAnnotationCount(); +// assertEquals(l_bf_scnt, 1); +// +// int w_bf_scnt = w_bf.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(w_bf_scnt, l_bf_scnt + 1); +// +// rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt + w_bf_scnt); //Event - add and bind last - ComponentAgent add_bl = desktop.query("#root #add_bindlast"); - add_bl.click(); - ComponentAgent w_bl = desktop.query("#root").getLastChild(); - ComponentAgent l_bl = w_bf.getFirstChild(); - int l_bl_scnt = l_bl.as(Label.class).getSubBindingAnnotationCount(); - assertEquals(l_bl_scnt, 1); - int w_bl_scnt = w_bl.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(w_bl_scnt, l_bl_scnt + 1); - rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt + w_bf_scnt + w_bl_scnt); +// ComponentAgent add_bl = desktop.query("#root #add_bindlast"); +// add_bl.click(); +// ComponentAgent w_bl = desktop.query("#root").getLastChild(); +// ComponentAgent l_bl = w_bf.getFirstChild(); +// int l_bl_scnt = l_bl.as(Label.class).getSubBindingAnnotationCount(); +// assertEquals(l_bl_scnt, 1); +// int w_bl_scnt = w_bl.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(w_bl_scnt, l_bl_scnt + 1); +// rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); +// assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt + w_bf_scnt + w_bl_scnt); //Event - move w2 to root as last child ComponentAgent move_append = desktop.query("#root #move_append"); @@ -162,7 +162,7 @@ public void test() { assertEquals(w1_scnt, l1_scnt + dabtn_scnt + 1); assertEquals(w2_scnt, l2_scnt + testb1_scnt + 1); - assertEquals(rt_scnt, w1_scnt + w2_scnt + w3_scnt + c_scnt + w_bf_scnt + w_bl_scnt); + assertEquals(rt_scnt, w1_scnt + w2_scnt + w3_scnt + c_scnt/* + w_bf_scnt + w_bl_scnt*/); //Event - move back ComponentAgent move_setParent = desktop.query("#root #move_setParent"); @@ -173,12 +173,12 @@ public void test() { rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); assertEquals(w2_scnt, l2_scnt + testb1_scnt + 1); assertEquals(w1_scnt, l1_scnt + dabtn_scnt + w2_scnt + 1); - assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt + w_bf_scnt + w_bl_scnt); + assertEquals(rt_scnt, w1_scnt + w3_scnt + c_scnt/* + w_bf_scnt + w_bl_scnt*/); //Event - remove w3 ComponentAgent remove = desktop.query("#root #remove"); remove.click(); rt_scnt = rt.as(Window.class).getSubBindingAnnotationCount(); - assertEquals(rt_scnt, w1_scnt + c_scnt + w_bf_scnt + w_bl_scnt); + assertEquals(rt_scnt, w1_scnt + c_scnt/* + w_bf_scnt + w_bl_scnt*/); } }