/** Clears all child tree items ({@link Treeitem}. * <p>Note: after clear, {@link #getTreechildren} won't be null, but * it has no child */ public void clear() { if (_treechildren != null) _treechildren.getChildren().clear(); }
/** Returns whether this element contains no child elements. */ public boolean isEmpty() { return _treechildren == null || _treechildren.getChildren().isEmpty(); }
public boolean isEmpty() { return getChildren().isEmpty(); }
private static Treeitem getChildTreeitem(Treechildren tc, int i) { if (tc == null) return null; List<? extends Component> cs = tc.getChildren(); return i < 0 || i >= cs.size() ? null : (Treeitem) cs.get(i); }
/** Sorts the treechildren. * @since 5.0.6 */ @SuppressWarnings("unchecked") private static void sort0(Treechildren treechildren, Comparator cmpr) { if (treechildren == null) return; Components.sort(treechildren.getChildren(), cmpr); for (Iterator it = treechildren.getChildren().iterator(); it.hasNext();) { Treeitem item = (Treeitem) it.next(); sort0(item.getTreechildren(), cmpr); } }
/** 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; }
private void onTreeDataContentChange(Component parent, Object node, int index) { List<? extends Component> items = treechildrenOf(parent).getChildren(); /* * 2008/02/01 --- issue: [ 1884112 ] When Updating TreeModel, throws a IndexOutOfBoundsException * When I update a children node data of the TreeModel , and fire a * CONTENTS_CHANGED event, it will throw a IndexOutOfBoundsException , If a * node doesn't open yet or not load yet. * * if parent is loaded, change content. * else do nothing */ if (!items.isEmpty()) renderChangedItem((Treeitem) items.get(index), _model.getChild(node, index)); }
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(); } }
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)); } }
List<? extends Component> children = this.getTreechildren().getChildren(); children = ti.getTreechildren().getChildren(); } else { if (i != path.length - 1) {
/** * Unload the tree item * <p>To load the tree item, with * {@link Tree#renderItem(Treeitem)}, {@link Tree#renderItem(Treeitem, Object)}, or {@link Tree#renderItems(java.util.Set)} * * @since 3.0.4 */ public void unload() { if (isLoaded()) { //Clean its children if (getTreechildren() != null) getTreechildren().getChildren().clear(); //Set the load status to unloaded setLoaded(false); //Change the "+/-" sign icon setOpen(false); } }
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. }
/** 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); }
if (_treechildren != null && _treechildren.getChildren().size() >= 5) invalidate();