/** 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); }
/** @param parent either a Tree or Treeitem instance. */ private static Treechildren treechildrenOf(Component parent) { Treechildren tc = (parent instanceof Tree) ? ((Tree) parent).getTreechildren() : ((Treeitem) parent).getTreechildren(); if (tc == null) { tc = new Treechildren(); tc.setParent(parent); } return tc; }
private void onTreeDataRemoved(Component parent, Object node, int index) { final Treechildren tc = treechildrenOf(parent); final List<? extends Component> items = tc.getChildren(); if (items.size() > index) { ((Treeitem) items.get(index)).detach(); } else if (!(parent instanceof Treeitem) || ((Treeitem) parent).isLoaded()) { tc.detach(); } }
/** Returns the number of child {@link Treeitem} * including all descendants. The same as {@link #getItems}.size(). * <p>Note: the performance is no good. */ public int getItemCount() { int sz = 0; for (Iterator it = getChildren().iterator(); it.hasNext(); ++sz) { final Treeitem item = (Treeitem) it.next(); final Treechildren tchs = item.getTreechildren(); if (tchs != null) sz += tchs.getItemCount(); } return sz; }
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); } } } }
@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); } }
/** Note: it doesn't call render doCatch/doFinally */ private void renderItem0(Renderer renderer, Treeitem item, Object node) throws Throwable { if (item.isLoaded()) //all direct children are loaded return; /* * After modified the node in tree model, if node is leaf, * its treechildren is needed to be dropped. */ Treechildren tc = item.getTreechildren(); if (_model.isLeaf(node)) { if (tc != null) tc.detach(); //just in case //no children to render //Note item already rendered, so no need: //renderer.render(item, node); } else { if (tc != null) tc.getChildren().clear(); //just in case else { tc = new Treechildren(); tc.setParent(item); } renderChildren(renderer, tc, node); } Object v = item.getAttribute(Attributes.MODEL_RENDERAS); if (v != null) //a new item is created to replace the existent one (item = (Treeitem) v).setOpen(false); item.setLoaded(true); }
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); } }
private void renderChangedItem(Treeitem item, Object node) { /* * After modified the node in tree model, if node is leaf, * its treechildren is needed to be dropped. */ if (_model != null) { Treechildren tc = item.getTreechildren(); if (_model.isLeaf(node)) { if (tc != null) tc.detach(); //just in case } else { if (tc == null) { tc = new Treechildren(); tc.setParent(item); } } final Renderer renderer = new Renderer(); try { renderer.renderChangedItem(item, node, item.getIndex()); //re-render } catch (Throwable ex) { renderer.doCatch(ex); } finally { renderer.doFinally(); } } }
private void renderTree() { if (_treechildren == null) { Treechildren children = new Treechildren(); children.setParent(this); } else { _treechildren.getChildren().clear(); } if (_model instanceof TreeSelectableModel) this.setMultiple(((TreeSelectableModel) _model).isMultiple()); Object node = _model.getRoot(); final Renderer renderer = new Renderer(); try { renderChildren(renderer, _treechildren, node); } catch (Throwable ex) { renderer.doCatch(ex); } finally { renderer.doFinally(); } Events.postEvent(ZulEvents.ON_AFTER_RENDER, this, null); // notify the tree when items have been rendered. }
/** Returns whether this element contains no child elements. */ public boolean isEmpty() { return _treechildren == null || _treechildren.getChildren().isEmpty(); }
/** 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; }
private void onTreeDataInsert(Component parent, Object node, int index) { /* * Find the sibling to insertBefore; if there is no sibling or new item * is inserted at end. */ Treeitem newTi = newUnloadedItem(); Treechildren tc = treechildrenOf(parent); //B50-ZK-721 if (!(parent instanceof Treeitem) || ((Treeitem) parent).isLoaded()) { List<? extends Component> siblings = tc.getChildren(); // if there is no sibling or new item is inserted at end. tc.insertBefore(newTi, // Note: we don't use index >= size(); reason: it detects bug siblings.isEmpty() || index == siblings.size() ? null : (Treeitem) siblings.get(index)); renderChangedItem(newTi, _model.getChild(node, index)); } }
if (_treechildren != null && _treechildren.getChildren().size() >= 5) invalidate(); addVisibleItemCount(_treechildren.getVisibleItemCount()); else { addVisibleItemCount(-_treechildren.getVisibleItemCount());
/** * adds the number of the visible item to the count of its parent. * @param count * @param force if true, ignores {@link #isVisible()} * @since 3.0.7 */ void addVisibleItemCount(int count) { Treechildren tc = (Treechildren) getParent(); if (tc != null && super.isVisible()) tc.addVisibleItemCount(count); }
public int size() { return getItemCount(); }
/** Returns a readonly list of all descending {@link Treeitem} * (children's children and so on). * * <p>Note: the performance of the size method of returned collection * is no good. */ public Collection<Treeitem> getItems() { if (_treechildren != null) return _treechildren.getItems(); return Collections.emptyList(); }
protected void redrawChildren(Writer out) throws IOException { if (getAttribute(Attributes.SHALL_RENDER_ITEM) == null) { for (Iterator it = new VisibleChildrenIterator(); it.hasNext();) ((ComponentCtrl) it.next()).redraw(out); } }