/** * Paints the children of the given component. * * @param container the component whose children will be painted. * @param renderContext the context for rendering. */ protected final void paintChildren(final Container container, final WebXmlRenderContext renderContext) { final int size = container.getChildCount(); for (int i = 0; i < size; i++) { WComponent child = container.getChildAt(i); child.paint(renderContext); } }
iid = parent.getInternalId(); final int nameLen = iid.length(); StringBuffer nameBuf = new StringBuffer(nameLen + 3);
/** * Implement readResolve so that on deserialization, the WComponent that is referred to by this WComponentRef is * returned. The WComponent * * @return the WComponent instance that is registered with the registry. * @throws ObjectStreamException never, but Serializable requires this method signature to declare it. * @see java.io.Serializable */ private Object readResolve() throws ObjectStreamException { if (repositoryKey == null || nodeLocation == null) { // Should not happen throw new IllegalStateException( "Unable to resolve component in repository '" + repositoryKey + '\''); } WComponent comp = UIRegistry.getInstance().getUI(repositoryKey); for (int i = 0; comp != null && i < nodeLocation.length; i++) { comp = ((Container) comp).getChildAt(nodeLocation[i]); } // Component not found - BAD! if (comp == null) { throw new IllegalStateException("Unable to resolve component: " + toString()); } return comp; }
@Test public void testRemoveTerm() { WDefinitionList list = new WDefinitionList(); String term1 = "WDefinitionList_Test.testRemoveTerm.term1"; String term2 = "WDefinitionList_Test.testRemoveTerm.term2"; WComponent term2data1 = new DefaultWComponent(); WComponent term2data2 = new DefaultWComponent(); list.addTerm(term1); list.addTerm(term2, term2data1, term2data2); Container termContainer = (Container) list.getChildAt(0); Assert.assertEquals("Incorrect term data", 3, termContainer.getChildren().size()); list.removeTerm(term2); Assert.assertEquals("Incorrect term data", 1, termContainer.getChildCount()); Assert.assertEquals("Incorrect value for Term1", term1, termContainer.getChildAt(0).getTag()); } }
/** * Retrieves the component that is currently being displayed by the example picker. * * @return the current example. */ public Container getCurrentComponent() { Container currentComponent = null; if (((Container) (container.getChildAt(0))).getChildCount() > 0) { currentComponent = (Container) container.getChildAt(0); } return currentComponent; }
/** * Indicates whether the tab at the given index is visible. * * @param idx the index of the WTab to test. * @return true if the tab at the given index is visible, false if it is invisible. */ public boolean isTabVisible(final int idx) { WTab tab = getTab(idx); Container tabParent = tab.getParent(); if (tabParent instanceof WTabGroup) { return tab.isVisible() && tabParent.isVisible(); } else { return tab.isVisible(); } }
private void makeAllInputsMandatory(final WComponent component) { if (component instanceof Mandatable) { ((Mandatable) component).setMandatory(true); } if (component instanceof Container) { for (WComponent child : ((Container) component).getChildren()) { makeAllInputsMandatory(child); } } } }
@Test public void testDuplicator() { // Launch the web browser to the LDE WebDriver driver = getDriver(); // Enter some text and use the duplicate button String inputFieldName = ((Container) getUi()).getChildAt(1).getId(); driver.findElement(By.name(inputFieldName)).sendKeys("dummy"); driver.findElement(By.xpath("//button[text()='Duplicate']")).click(); Assert.assertEquals("Incorrect text field text after duplicate", "dummydummy", driver.findElement(By.xpath("//input[@type='text']")).getAttribute("value")); // Clear the text driver.findElement(By.xpath("//button[text()='Clear']")).click(); Assert.assertEquals("Incorrect text field text after clear", "", driver.findElement(By.xpath("//input[@type='text']")).getAttribute("value")); } }
/** * Internal utility method to find the index of a child within a container. This method makes use of the additional * methods offered by the AbstractWComponent implementation (if available), otherwise it falls back the methods * declared in the {@link WComponent} interface. * * @param parent the container to search for the child in * @param childComponent the component to search for. * @return the index of the <code>childComponent</code> in <code>parent</code>, or -1 if <code>childComponent</code> * is not a child of <code>parent</code>. */ private static int getIndexOfChild(final Container parent, final WComponent childComponent) { if (parent instanceof AbstractWComponent) { return ((AbstractWComponent) parent).getIndexOfChild(childComponent); } else { // We have to do this the hard way... for (int i = 0; i < parent.getChildCount(); i++) { if (childComponent == parent.getChildAt(i)) { return i; } } } return -1; }
/** * Update the expandable row renderer. * * @param rowRenderer the table row renderer * @param rowContext the row context * @param expandRenderer the renderer for the expandable row. */ private void updateBeanValueForRowRenderer(final WTableRowRenderer rowRenderer, final UIContext rowContext, final Class<? extends WComponent> expandRenderer) { Container expandWrapper = (Container) rowRenderer. getExpandedTreeNodeRenderer(expandRenderer); if (expandWrapper == null) { return; } // The actual component is wrapped in a renderer wrapper, so we have to fetch it from that WComponent expandInstance = expandWrapper.getChildAt(0); UIContextHolder.pushContext(rowContext); try { // Will apply updates to the "bean" returned by the model for this expanded renderer (ie // getValueAt(rowIndex, -1)) WebUtilities.updateBeanValue(expandInstance); } finally { UIContextHolder.popContext(); } }
final int childCount = container.getChildCount(); WComponent theField = findComponentForLabel(container.getChildAt(i));
/** * Tests the duplicator. */ @Test public void testDuplicator() { // Launch the web browser to the LDE WebDriver driver = getDriver(); // Enter some text and use the duplicate button String inputFieldName = ((Container) getUi()).getChildAt(1).getId(); driver.findElement(By.name(inputFieldName)).sendKeys("dummy"); driver.findElement(By.xpath("//button[text()='Duplicate']")).click(); Assert.assertEquals("Incorrect text field text after duplicate", "dummydummy", driver.findElement(By.xpath("//input[@type='text']")).getAttribute("value")); // Clear the text driver.findElement(By.xpath("//button[text()='Clear']")).click(); Assert.assertEquals("Incorrect text field text after clear", "", driver.findElement(By.xpath("//input[@type='text']")).getAttribute("value")); } }
/** * Recursively adds statistics for a component and its children to the stats map. * * @param statsMap the stats map to add to. * @param comp the component to analyse. */ private void addStats(final Map<WComponent, Stat> statsMap, final WComponent comp) { Stat stat = createStat(comp); statsMap.put(comp, stat); if (comp instanceof Container) { Container container = (Container) comp; int childCount = container.getChildCount(); for (int i = 0; i < childCount; i++) { WComponent child = container.getChildAt(i); addStats(statsMap, child); } } }
final List<Integer> rowIndex, final int col, final TableModel model) { WComponent renderer = ((Container) rowRenderer.getRenderer(col)).getChildAt(0);
/** * Collates all the visible components in this branch of the WComponent tree. WComponents are added to the * <code>list</code> in depth-first order, as this list is traversed in order during the request handling phase. * * @param component the current branch to collate visible items in. * @param list the list to add the visible components to. */ private static void collateVisible(final WComponent component, final List<WComponent> list) { if (component.isVisible()) { if (component instanceof Container) { final int size = ((Container) component).getChildCount(); for (int i = 0; i < size; i++) { collateVisible(((Container) component).getChildAt(i), list); } } list.add(component); } }
if (model.isCellEditable(row, col)) { WComponent renderer = ((Container) rowRenderer.getRenderer(col)).getChildAt(0);
/** * Apply the mandatory action against the target and its children. * * @param target the target of this action * @param mandatory is the evaluated value */ private void applyMandatoryAction(final WComponent target, final boolean mandatory) { if (target instanceof Mandatable) { ((Mandatable) target).setMandatory(mandatory); } else if (target instanceof Container) { // Apply to the Mandatable children Container cont = (Container) target; final int size = cont.getChildCount(); for (int i = 0; i < size; i++) { WComponent child = cont.getChildAt(i); applyMandatoryAction(child, mandatory); } } } }
@Test public void testDuplicator() { // Launch the web browser to the LDE SeleniumWComponentsWebDriver driver = getDriver(); // Enter some text and use the duplicate button driver.findWTextField(byWComponent(((Container) getUi()).getChildAt(1))).sendKeys("dummy"); driver.findElement(By.xpath("//button[text()='Duplicate']")).click(); Assert.assertEquals("Incorrect text field text after duplicate", "dummydummy", driver.findElement(By.xpath("//input[@type='text']")).getAttribute("value")); // Clear the text driver.findElement(By.xpath("//button[text()='Clear']")).click(); Assert.assertEquals("Incorrect text field text after clear", "", driver.findElement(By.xpath("//input[@type='text']")).getAttribute("value")); } }
/** * @param component the component * @param map the group data * @param compDataOverall the overall group data * @param out the buffer */ private void tally(final WComponent component, final Map<String, GroupData> map, final GroupData compDataOverall, final StringBuffer out) { String classKey = component.getClass().getName(); GroupData dataForClass = map.get(classKey); if (dataForClass == null) { dataForClass = new GroupData(); map.put(classKey, dataForClass); } dataForClass.total++; compDataOverall.total++; if (component instanceof Container) { int count = ((Container) component).getChildCount(); for (int i = 0; i < count; i++) { WComponent child = ((Container) component).getChildAt(i); tally(child, map, compDataOverall, out); } } }