/** Returns the {@link Treerow} that is associated with * this treechildren, or null if no such treerow. * In other words, it is {@link Treeitem#getTreerow} of * {@link #getParent}. * * @since 2.4.1 * @see Treerow#getLinkedTreechildren */ public Treerow getLinkedTreerow() { final Component parent = getParent(); return parent instanceof Treeitem ? ((Treeitem) parent).getTreerow() : null; }
/** Called by {@link Treechildren} when is added to a tree. */ /*package*/ void onTreechildrenAdded(Treechildren tchs) { if (tchs == null || tchs.getParent() == this) return; //already being processed by insertBefore //main the selected status for (Treeitem item : tchs.getItems()) fixNewChild(item); }
/*package*/ void addVisibleItemCount(int count) { if (count == 0) return; Component parent = getParent(); if (parent instanceof Treeitem) { if (((Treeitem) parent).isOpen()) ((Treeitem) parent).addVisibleItemCount(count); } else if (parent instanceof Tree) ((Tree) parent).addVisibleItemCount(count); _visibleItemCount += count; }
/** Called by {@link Treechildren} when is removed from a tree. */ /*package*/ void onTreechildrenRemoved(Treechildren tchs) { if (tchs == null || tchs.getParent() == this) return; //already being processed by onChildRemoved //main the selected status boolean fixSel = false; for (Treeitem item : tchs.getItems()) { if (item.isSelected()) { _selItems.remove(item); if (_sel == item) { if (!_multiple) { _sel = null; return; //done } fixSel = true; } } } if (fixSel) fixSelected(); }
/*package*/ boolean isRealVisible() { if (!isVisible()) return false; Component comp = getParent(); if (comp == null) return true; if (!(comp instanceof Treeitem)) return comp.isVisible(); Treeitem item = (Treeitem) comp; return item.isOpen() && item.isRealVisible(); }
@SuppressWarnings("unchecked") protected void smartUpdate(String name, Object value) { Component comp = getParent(); if (comp instanceof Treeitem) { Treerow tr = ((Treeitem) comp).getTreerow(); if (tr != null) tr.smartUpdate(name, value); } else if (comp instanceof Tree) { ((Tree) comp).smartUpdate(name, value); } else { // do it later for bug ZK-2206 Map<String, Object> attributes = (Map<String, Object>) getAttribute( "org.zkoss.zul.Treechildren_smartUpdate"); if (attributes == null) { attributes = new LinkedHashMap<String, Object>(3); setAttribute("org.zkoss.zul.Treechildren_smartUpdate", attributes); } attributes.put(name, value); } }
public void setParent(Component parent) { final Component oldp = getParent(); if (oldp == parent) return; //nothing changed final Tree oldtree = oldp != null ? getTree() : null; super.setParent(parent); //maintain the selected status if (oldtree != null) oldtree.onTreechildrenRemoved(this); if (parent != null) { final Tree tree = getTree(); if (tree != null) tree.onTreechildrenAdded(this); } }
public void render(Component comp, Writer out) throws IOException { final SmartWriter wh = new SmartWriter(out); final Treechildren self = (Treechildren) comp; if (self.getParent() instanceof Tree) { //top level wh.write("<tbody id=\"").write(self.getUuid()).write('"') .write(self.getOuterAttrs()).write( self.getInnerAttrs() ).writeln(">"); for (Iterator it = self.getVisibleChildrenIterator(); it.hasNext();) { final Component child = (Component) it.next(); child.redraw(out); } wh.writeln("</tbody>"); } else { for (Iterator it = self.getVisibleChildrenIterator(); it.hasNext();) { final Component child = (Component) it.next(); child.redraw(out); } } } }
public Set<? extends Component> getAvailableAtClient() { if (!isCropper()) return null; final Tree tree = getTree(); final Component parent = getParent(); final Execution exe = Executions.getCurrent(); final String attrnm = VISIBLE_ITEM + tree.getUuid(); Map<Treeitem, Boolean> map = cast((Map) exe.getAttribute(attrnm)); if (map == null) { //Test very simple case first since getVisibleItems costly if (parent instanceof Treeitem) { for (Treeitem ti = (Treeitem) parent;;) { if (!ti.isOpen()) return Collections.emptySet(); Component gp = ti.getParent().getParent(); if (!(gp instanceof Treeitem)) break; ti = (Treeitem) gp; } } map = tree.getVisibleItems(); Executions.getCurrent().setAttribute(attrnm, map); } return map.keySet(); //yes, we return all visible items, not just direct children //in other words, we consider the whole tree as a single scope //See also bug 2814504 } }