/** * Removes all of the children from this component. */ void removeAll() { while (getChildCount() > 0) { remove(getChildAt(0)); } }
/** * {@inheritDoc} */ @Override // For type safety only protected AudioModel getComponentModel() { return (AudioModel) super.getComponentModel(); }
/** * {@inheritDoc} */ @Override public boolean isTracking() { if (isTrackingEnabled()) { // Check if id name set String idName = getIdName(); if (idName != null) { return true; } LOG.warn( "Trying to track a component that has no id name set. Tracking will be ignored. [" + getId() + " " + this.getClass().getName() + "]"); } return false; }
/** * Creates a String representation of this component, for debugging purposes. * * @param details some additional details to display in the output. * @return a String representation of this component. */ final String toString(final String details) { return toString(details, 0, getChildCount() - 1); }
/** * {@inheritDoc} */ @Override public void setLocked(final boolean lock) { this.locked = lock; for (int i = 0; i < getChildCount(); i++) { getChildAt(i).setLocked(lock); } }
Assert.assertNull("New components should not have a parent", parent.getParent()); Assert.assertNull("New components should not have a parent", child1.getParent()); setActiveContext(uic); Assert.assertNull("New components should not have a parent", child2.getParent()); resetContext(); parent.add(child1); Assert.assertEquals("getChildCount() incorrect for 1 child", 1, parent.getChildCount()); setActiveContext(uic); Assert.assertEquals("getChildCount(uic) incorrect for 1 child", 1, parent.getChildCount()); resetContext(); Assert.assertEquals("getChildCount() incorrect for 0 children", 0, child1.getChildCount()); setActiveContext(uic); Assert. assertEquals("getChildCount(uic) incorrect for 0 children", 0, child1. getChildCount()); resetContext(); Assert.assertEquals("getChildAt(0) incorrect", child1, parent.getChildAt(0)); Assert.assertNull("getParent() incorrect for no parent", parent.getParent()); Assert.assertEquals("getParent() incorrect for child", parent, child1.getParent()); setActiveContext(uic); Assert.assertEquals("getParent(uic) incorrect for child", parent, child1.getParent()); resetContext(); Assert.assertEquals("Incorrect indexOfChild for child", 0, parent.getIndexOfChild(child1)); parent.add(child2); Assert.assertEquals("getChildCount() incorrect for 2 children", 2, parent.getChildCount()); setActiveContext(uic); Assert.
final int childCount = getChildCount(); List<WComponent> children = null; children = new ArrayList<>(getComponentModel().getChildren()); Container dynamicParent = getParent(); this.removeComponentModel(); uic.clearScratchMap(this); uic.clearRequestScratchMap(this); if (dynamicParent != null && getParent() != dynamicParent && getIndexOfChild( dynamicParent, this) != -1) { getOrCreateComponentModel().setParent(dynamicParent);
a.add(b); a.setLocked(true); a.add(d1); d1.add(d2); resetContext(); Assert.assertEquals("Incorrect number of static children", 1, a.getChildCount()); Assert.assertEquals("Incorrect parent for static child", a, b.getParent()); Assert.assertEquals("Incorrect child count for 'a'", 2, a.getChildCount()); Assert.assertEquals("Incorrect child count for 'd1'", 1, d1.getChildCount()); Assert.assertEquals("Incorrect parent for 'd1'", a, d1.getParent()); Assert.assertEquals("Incorrect parent for 'd2'", d1, d2.getParent()); Assert.assertEquals("Incorrect top component", a, WebUtilities.getTop(d2)); Assert.assertTrue("'b' should be in default state", b.isDefaultState()); Assert.assertFalse("'a' should not be in default state", a.isDefaultState()); Assert.assertFalse("'d1' should not be in default state", d1.isDefaultState()); Assert.assertFalse("'d2' should not be in default state", d2.isDefaultState()); a.reset(); Assert. assertTrue("'b' should be in default state after UIContext reset", b. isDefaultState()); Assert. assertTrue("'a' should be in default state after UIContext reset", a. isDefaultState()); Assert.assertTrue("'s1' should be in default state after UIContext reset", d1.
if (!isDefaultState()) { buf.append("<user model>"); buf.append(isVisible() ? "" : "<invisible>"); buf.append(!isHidden() ? "" : "<hidden>"); if (this instanceof Container && childStartIndex >= 0 && childEndIndex < getChildCount() && childStartIndex <= childEndIndex) { WComponent[] children = new WComponent[childEndIndex - childStartIndex + 1]; children[i - childStartIndex] = getChildAt(i); buf.append(childrenToString(children));
@Test public void testDynamicChildOverride() { AbstractWComponent parent = new MockContainer(); AbstractWComponent staticChild = new SimpleComponent(); AbstractWComponent dynamicChild = new SimpleComponent(); parent.add(staticChild); setActiveContext(createUIContext()); parent.removeAll(); parent.add(dynamicChild); Assert.assertEquals("Incorrect number of children", 1, parent.getChildCount()); Assert.assertSame("Incorrect child component", dynamicChild, parent.getChildAt(0)); }
/** * {@inheritDoc} */ @Override // For type safety only protected SuggestionsModel getOrCreateComponentModel() { return (SuggestionsModel) super.getOrCreateComponentModel(); }
AbstractWComponent root = new MockContainer(); AbstractWComponent comp = new SimpleComponent(); root.add(comp); root.setLocked(true); Assert.assertTrue("Component should be in default state by default", comp.isDefaultState()); comp.setAttribute("a1", "x"); comp.setAttribute("a2", "y"); comp.setAttribute("a3", "w"); Assert.assertFalse("Should not be default state if attributes are set in context", comp.isDefaultState()); "x", comp.getAttribute("a1")); Assert.assertEquals("Incorrect value for attribute \"a2\"", "y", comp.getAttribute("a2")); Assert.assertEquals("Incorrect value for attribute \"a3\"", "w", comp.getAttribute("a3")); comp.removeAttribute("a3"); Assert.assertNull("Attribute should have been removed", comp.getAttribute("a3")); root.getAttribute("a1")); Assert.assertNull("Parent should not see child's attributes", root.getAttribute("a2")); root.setAttribute("r1", "z"); Assert.assertEquals("Incorrect value for attribute \"r1\"",
@Test public void testDynamicAddAndReset() { AbstractWComponent parent = new MockContainer(); AbstractWComponent child = new SimpleComponent(); setActiveContext(createUIContext()); parent.add(child); child.reset(); Assert.assertEquals("Child component should have reference to parent", parent, child. getParent()); Assert.assertEquals("Parent component should have reference to child", 0, parent. getIndexOfChild(child)); }
/** * 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)); }
@Test public void testLock() { AbstractWComponent parent = new MockContainer(); AbstractWComponent child1 = new SimpleComponent(); AbstractWComponent child2 = new SimpleComponent(); parent.add(child1); parent.add(child2); child2.setVisible(false); Assert.assertFalse("Parent should not be locked", parent.isLocked()); Assert.assertFalse("Child 1 should not be locked", child1.isLocked()); Assert.assertFalse("Child 2 should not be locked", child2.isLocked()); parent.setLocked(true); Assert.assertTrue("Parent should be locked", parent.isLocked()); Assert.assertTrue("Child 1 should be locked", child1.isLocked()); Assert.assertTrue("Child 2 should be locked", child2.isLocked()); }
@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)); }
Map scratchMap = getScratchMap(); Container parent = getParent(); StringBuffer nameBuf = new StringBuffer(nameLen + 3); nameBuf.append(iid); nameBuf.append(getIndexOfChild(parent, this));
/** * This is where most of the painting work is normally done. If a layout has been supplied either directly or by * supplying a velocity template, then painting is delegated to the layout manager. If there is no layout, the * default behaviour is to paint the child components in sequence. * * @param renderContext the context to render to. */ protected void paintComponent(final RenderContext renderContext) { Renderer renderer = UIManager.getRenderer(this, renderContext); if (getTemplate() != null || getTemplateMarkUp() != null) { Renderer templateRenderer = UIManager.getTemplateRenderer(renderContext); templateRenderer.render(this, renderContext); } else if (renderer == null) { // Default is juxtaposition List<WComponent> children = getComponentModel().getChildren(); if (children != null) { final int size = children.size(); for (int i = 0; i < size; i++) { children.get(i).paint(renderContext); } } } else { renderer.render(this, renderContext); } }