/** * Removes all of the children from this component. */ void removeAll() { while (getChildCount() > 0) { remove(getChildAt(0)); } }
parent.remove(child1); Assert.assertNull("Removed child's parent should be null", child1.getParent()); Assert.assertEquals("getChildCount() incorrect after remove", 1, parent.getChildCount());
@Test public void testDynamicMove() { UIContext uic = createUIContext(); AbstractWComponent parent1 = new MockContainer(); AbstractWComponent parent2 = new MockContainer(); AbstractWComponent child = new SimpleComponent(); parent1.add(child); setActiveContext(uic); parent1.remove(child); parent2.add(child); Assert.assertEquals("Child component should have been moved to parent2", parent2, child. getParent()); }
/** * test remove - child from shared list. */ @Test public void testRemoveCommon() { AbstractWComponent comp = new MockContainer(); WText text1 = new WText("XYZ"); WText text2 = new WText("ABC"); comp.add(text1); comp.add(text2); comp.remove(text1); // from shared list Assert.assertNull("shared should not contain text1", text1.getParent()); Assert.assertSame("shared should contain text2", text2, comp.getChildAt(0)); }
assertEquals("Incorrect number of children for 'a' after reset", 1, a. getChildCount()); a.remove(b); Assert.assertEquals("Incorrect number of children for 'a' after remove", 0, a. getChildCount());
/** * test tidyUpUIContextForTree. */ @Test public void testTidyUpUIContextForTree() { UIContext uic1 = createUIContext(); UIContext uic2 = createUIContext(); AbstractWComponent comp = new MockContainer(); comp.setLocked(true); WText text1 = new WText("XYZ"); WText text2 = new WText("ABC"); setActiveContext(uic1); comp.add(text1); setActiveContext(uic2); comp.add(text2); Assert.assertFalse("should have a component model", comp.hasNoComponentModel(uic1)); Assert.assertFalse("should have a component model", comp.hasNoComponentModel(uic2)); setActiveContext(uic1); comp.remove(text1); comp.tidyUpUIContextForTree(); // do it for uic1 only setActiveContext(uic2); comp.tidyUpUIContextForTree(); // do it for uic2 only - but no effect since not in default state Assert.assertTrue("uic1 should not have a component model", comp.hasNoComponentModel(uic1)); Assert.assertFalse("uic2 should still have a component model", comp. hasNoComponentModel(uic2)); }
/** * test remove - child from specific uic list. */ @Test public void testRemoveSpecific() { UIContext uic1 = createUIContext(); UIContext uic2 = createUIContext(); AbstractWComponent comp = new MockContainer(); WText text1 = new WText("XYZ"); WText text2 = new WText("ABC"); comp.add(text1); comp.add(text2); comp.setLocked(true); // from uic2 list setActiveContext(uic2); comp.remove(text1); resetContext(); Assert.assertSame("shared should contain text1", text1, comp.getChildAt(0)); Assert.assertSame("shared should contain text2", text2, comp.getChildAt(1)); setActiveContext(uic1); Assert.assertSame("uic1 should contain text1", text1, comp.getChildAt(0)); Assert.assertSame("uic1 should contain text2", text2, comp.getChildAt(1)); setActiveContext(uic2); Assert.assertNull("uic2 should not contain text1", text1.getParent()); Assert.assertSame("uic2 should contain text2", text2, comp.getChildAt(0)); }