/** * 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; }
/** * 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); } }
/** * @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); } } }
/** * Recursively searches the menu for a match to a WComponent with the given name. * * @param node the current node in the menu being searched. * @param name the component class name to search for. * @param partial if true, perform a case-insensitive partial name search. * @return the class for the given name, or null if not found. */ private ExampleData getMatch(final WComponent node, final String name, final boolean partial) { if (node instanceof WMenuItem) { ExampleData data = (ExampleData) ((WMenuItem) node).getActionObject(); Class<? extends WComponent> clazz = data.getExampleClass(); if (clazz.getName().equals(name) || data.getExampleName().equals(name) || (partial && clazz.getSimpleName().toLowerCase().contains(name.toLowerCase())) || (partial && data.getExampleName().toLowerCase().contains(name.toLowerCase()))) { return data; } } else if (node instanceof Container) { for (int i = 0; i < ((Container) node).getChildCount(); i++) { ExampleData result = getMatch(((Container) node).getChildAt(i), name, partial); if (result != null) { return result; } } } return null; }
/** * 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; }
/** * 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); } } }
/** * 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); } }
final int childCount = container.getChildCount();
Container container = (Container) component; for (int i = 0; i < container.getChildCount(); i++) { WComponent child = container.getChildAt(i); String tag = child.getTag();
/** * 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); } } } }
/** * Finds all WComponents in the given WComponent hierarchy. * * @param comp the branch to traverse. * @param result the list to add found components to. */ private void findWComponents(final WComponent comp, final List<WComponent> result) { result.add(comp); if (comp instanceof Container) { for (int i = 0; i < ((Container) comp).getChildCount(); i++) { findWComponents(((Container) comp).getChildAt(i), result); } } }
/** * Apply the enable action against the target and its children. * * @param target the target of this action * @param enabled is the evaluated value */ private void applyEnableAction(final WComponent target, final boolean enabled) { // Found Disableable component if (target instanceof Disableable) { target.setValidate(enabled); ((Disableable) target).setDisabled(!enabled); } else if (target instanceof Container) { // Apply to any Disableable children Container cont = (Container) target; final int size = cont.getChildCount(); for (int i = 0; i < size; i++) { WComponent child = cont.getChildAt(i); applyEnableAction(child, enabled); } } }
/** * Updates the bean value with the current value of the component and all its bean-bound children. * * @param component the component whose contents need to be copied to the bean. * @param visibleOnly - whether to include visible components only. */ public static void updateBeanValue(final WComponent component, final boolean visibleOnly) { // Do not process if component is invisble and ignore visible is true. Will ignore entire branch from this point. if (!component.isVisible() && visibleOnly) { return; } if (component instanceof WBeanComponent) { ((WBeanComponent) component).updateBeanValue(); } // These components recursively update bean values themselves, // as they have special requirements due to repeating data. if (component instanceof WDataTable || component instanceof WTable || component instanceof WRepeater) { return; } if (component instanceof Container) { for (int i = ((Container) component).getChildCount() - 1; i >= 0; i--) { updateBeanValue(((Container) component).getChildAt(i), visibleOnly); } } }
final int childCount = container.getChildCount();
@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()); } }
@Test public void testAddTerm() { WDefinitionList list = new WDefinitionList(); String term1 = "WDefinitionList_Test.testAddTerm.term1"; String term2 = "WDefinitionList_Test.testAddTerm.term2"; WComponent term2data1 = new DefaultWComponent(); WComponent term2data2 = new DefaultWComponent(); WComponent term2data3 = new DefaultWComponent(); // Test addition of term with no component list.addTerm(term1); Container termContainer = (Container) list.getChildAt(0); Assert.assertEquals("Term1 should have been added", 1, termContainer.getChildCount()); Assert.assertEquals("Incorrect value for Term1", term1, termContainer.getChildAt(0).getTag()); // Test addition of term with multiple components list.addTerm(term2, term2data1, term2data2); list.addTerm(term2, term2data3); Assert.assertEquals("Incorrect term for component 1", term2, term2data1.getTag()); Assert.assertEquals("Incorrect term for component 2", term2, term2data2.getTag()); Assert.assertEquals("Incorrect term for component 3", term2, term2data3.getTag()); }
writeDebugInfo(((WCardManager) component).getVisible(), xml); } else if (component instanceof Container) { final int size = ((Container) component).getChildCount();
Container container = (Container) node; for (int i = 0; i < container.getChildCount(); i++) { clearScratchMaps(container.getChildAt(i));
Container container = (Container) node; for (int i = 0; i < container.getChildCount(); i++) { result = doTraverse(container.getChildAt(i), visibleOnly, visitor);