/** Returns whether any component in coll is an ancestor of comp. * @param includingEquals whether to return true if a equals B */ private boolean isAncestor(Collection<Component> coll, Component comp, boolean includingEquals) { for (Iterator<Component> it = coll.iterator(); it.hasNext();) { final Component c = it.next(); if ((includingEquals || c != comp) && Components.isAncestor(c, comp)) return true; } return false; }
public void onPageAttached(Page newpage, Page oldpage) { super.onPageAttached(newpage, oldpage); Component rootParent = ComponentsCtrl.getRootParent(); final Radiogroup rg = getRadiogroup(); // ZK-3818: update selected index in the callback if (!_explictGroup) { _group = this.getRadiogroup(); } if (rg != null && rootParent instanceof ComponentCtrl && (!Components.isAncestor(rootParent, rg) || rootParent == rg)) { ((ComponentCtrl) rootParent).addCallback(AFTER_CHILD_ADDED, new Callback<Component>() { public void call(Component rootParent) { rg.fixOnAdd(Radio.this, false); } }); } } }
@Override public void onPageDetached(Page page) { super.onPageDetached(page); //B65-ZK-1768 remove the radio from the radiogroup in case it is an external radio final Radiogroup rg = getRadiogroup(); if (rg != null) { rg.removeExternal(this); } // ZK-3818: update selected index in the callback if (!_explictGroup) { _group = null; } Component rootParent = ComponentsCtrl.getRootParent(); if (rg != null && rootParent instanceof ComponentCtrl && (!Components.isAncestor(rootParent, rg) || rootParent == rg)) { ((ComponentCtrl) rootParent).addCallback(AFTER_CHILD_REMOVED, new Callback<Component>() { public void call(Component rootParent) { rg.fixOnRemove(Radio.this); } }); } }
/** * Checks the parent-child relation. * Notice it will create parent._chdinf * @param parent the parent (will-be). It may be null. * @param child the child (will-be). It cannot be null. */ private static void checkParentChild(Component parent, Component child) throws UiException { if (child == null) throw new UiException("Child cannot be null"); if (parent != null) { final AbstractComponent acp = (AbstractComponent) parent; if (acp.initChildInfo().inAdding(child)) return; //check only once if (Components.isAncestor(child, parent)) throw new UiException("A child cannot be a parent of its ancestor: " + child); if (!acp.isChildable()) throw new UiException("Child not allowed in " + parent.getClass().getName()); final Page parentpg = parent.getPage(), childpg = child.getPage(); if (parentpg != null && childpg != null && parentpg.getDesktop() != childpg.getDesktop()) throw new UiException("The parent and child must be in the same desktop: " + parent); final Component oldparent = child.getParent(); if (spaceOwnerNoVirtual(parent) != (oldparent != null ? spaceOwnerNoVirtual(oldparent) : childpg)) checkIdSpacesDown(child, parent); } else { final Page childpg = child.getPage(); if (childpg != null) checkDetach(childpg); } }