@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()); }
/** * Adds the given component as a child of this component. * * @param component the component to add. */ void add(final WComponent component) { assertAddSupported(component); assertNotReparenting(component); if (!(this instanceof Container)) { throw new UnsupportedOperationException("Components can only be added to a container"); } ComponentModel model = getOrCreateComponentModel(); if (model.getChildren() == null) { model.setChildren(new ArrayList<WComponent>(1)); } model.getChildren().add(component); if (isLocked()) { component.setLocked(true); } if (component instanceof AbstractWComponent) { ((AbstractWComponent) component).getOrCreateComponentModel().setParent((Container) this); ((AbstractWComponent) component).addNotify(); } }