001: /* Treefooter.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Fri Jan 19 15:36:11 2007, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zul;
020:
021: import java.util.List;
022: import java.util.Iterator;
023:
024: import org.zkoss.xml.HTMLs;
025:
026: import org.zkoss.zk.ui.Component;
027: import org.zkoss.zk.ui.UiException;
028: import org.zkoss.zul.impl.LabelImageElement;
029:
030: /**
031: * A column of the footer of a tree ({@link Tree}).
032: * Its parent must be {@link Treefoot}.
033: *
034: * <p>Unlike {@link Treecol}, you could place any child in a tree footer.
035: * <p>Note: {@link Treecell} also accepts children.
036: *
037: * @author tomyeh
038: */
039: public class Treefooter extends LabelImageElement {
040: private int _span = 1;
041:
042: public Treefooter() {
043: }
044:
045: public Treefooter(String label) {
046: setLabel(label);
047: }
048:
049: public Treefooter(String label, String src) {
050: setLabel(label);
051: setImage(src);
052: }
053:
054: /** Returns the tree that this belongs to.
055: */
056: public Tree getTree() {
057: final Component comp = getParent();
058: return comp != null ? (Tree) comp.getParent() : null;
059: }
060:
061: /** Returns the set of footers that this belongs to.
062: * @deprecated As of release 2.4.1, due to confusion
063: */
064: public Treefoot getTreefoot() {
065: return (Treefoot) getParent();
066: }
067:
068: /** Returns the column index, starting from 0.
069: */
070: public int getColumnIndex() {
071: int j = 0;
072: for (Iterator it = getParent().getChildren().iterator(); it
073: .hasNext(); ++j)
074: if (it.next() == this )
075: break;
076: return j;
077: }
078:
079: /** Returns the tree header that is in the same column as
080: * this footer, or null if not available.
081: */
082: public Treecol getTreecol() {
083: final Tree tree = getTree();
084: if (tree != null) {
085: final Treecols cs = tree.getTreecols();
086: if (cs != null) {
087: final int j = getColumnIndex();
088: final List cschs = cs.getChildren();
089: if (j < cschs.size())
090: return (Treecol) cschs.get(j);
091: }
092: }
093: return null;
094: }
095:
096: /** Returns number of columns to span this footer.
097: * Default: 1.
098: */
099: public int getSpan() {
100: return _span;
101: }
102:
103: /** Sets the number of columns to span this footer.
104: * <p>It is the same as the colspan attribute of HTML TD tag.
105: */
106: public void setSpan(int span) {
107: if (_span != span) {
108: _span = span;
109: smartUpdate("colspan", Integer.toString(_span));
110: }
111: }
112:
113: //-- super --//
114: public String getOuterAttrs() {
115: final StringBuffer sb = new StringBuffer(80).append(super
116: .getOuterAttrs());
117:
118: final String clkattrs = getAllOnClickAttrs(false);
119: if (clkattrs != null)
120: sb.append(clkattrs);
121:
122: final Treecol col = getTreecol();
123: if (col != null)
124: sb.append(col.getColAttrs());
125:
126: if (_span != 1)
127: HTMLs.appendAttribute(sb, "colspan", _span);
128:
129: return sb.toString();
130: }
131:
132: //-- Component --//
133: public void setParent(Component parent) {
134: if (parent != null && !(parent instanceof Treefoot))
135: throw new UiException("Wrong parent: " + parent);
136: super.setParent(parent);
137: }
138: }
|