001: /* Auxheader.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Wed Oct 24 10:07:12 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 org.zkoss.xml.HTMLs;
022:
023: import org.zkoss.zk.ui.Component;
024: import org.zkoss.zk.ui.Execution;
025: import org.zkoss.zk.ui.Executions;
026: import org.zkoss.zk.ui.UiException;
027: import org.zkoss.zk.ui.WrongValueException;
028:
029: import org.zkoss.zul.impl.HeaderElement;
030:
031: /**
032: * An auxiliary header.
033: *
034: * @author tomyeh
035: * @since 3.0.0
036: */
037: public class Auxheader extends HeaderElement {
038: private int _colspan = 1, _rowspan = 1;
039:
040: public Auxheader() {
041: }
042:
043: public Auxheader(String label) {
044: setLabel(label);
045: }
046:
047: public Auxheader(String label, String src) {
048: setLabel(label);
049: setImage(src);
050: }
051:
052: /** Returns number of columns to span this header.
053: * Default: 1.
054: */
055: public int getColspan() {
056: return _colspan;
057: }
058:
059: /** Sets the number of columns to span this header.
060: * <p>It is the same as the colspan attribute of HTML TD tag.
061: */
062: public void setColspan(int colspan) throws WrongValueException {
063: if (colspan <= 0)
064: throw new WrongValueException("Positive only");
065: if (_colspan != colspan) {
066: _colspan = colspan;
067: final Execution exec = Executions.getCurrent();
068: if (exec != null && exec.isExplorer())
069: invalidate();
070: else
071: smartUpdate("colspan", Integer.toString(_colspan));
072: }
073: }
074:
075: /** Returns number of rows to span this header.
076: * Default: 1.
077: */
078: public int getRowspan() {
079: return _rowspan;
080: }
081:
082: /** Sets the number of rows to span this header.
083: * <p>It is the same as the rowspan attribute of HTML TD tag.
084: */
085: public void setRowspan(int rowspan) throws WrongValueException {
086: if (rowspan <= 0)
087: throw new WrongValueException("Positive only");
088: if (_rowspan != rowspan) {
089: _rowspan = rowspan;
090: final Execution exec = Executions.getCurrent();
091: if (exec != null && exec.isExplorer())
092: invalidate();
093: else
094: smartUpdate("rowspan", Integer.toString(_rowspan));
095: }
096: }
097:
098: //super//
099: public String getOuterAttrs() {
100: final String attrs = super .getOuterAttrs();
101: final String clkattrs = getAllOnClickAttrs(false);
102: if (clkattrs == null && _colspan == 1 && _rowspan == 1)
103: return attrs;
104:
105: final StringBuffer sb = new StringBuffer(80).append(attrs);
106: if (clkattrs != null)
107: sb.append(clkattrs);
108: if (_colspan != 1)
109: HTMLs.appendAttribute(sb, "colspan", _colspan);
110: if (_rowspan != 1)
111: HTMLs.appendAttribute(sb, "rowspan", _rowspan);
112: return sb.toString();
113: }
114:
115: protected void invalidateWhole() {
116: Component p = getParent();
117: if (p != null) {
118: p = p.getParent();
119: if (p != null)
120: p.invalidate();
121: }
122: }
123:
124: //Component//
125: public void setParent(Component parent) {
126: if (parent != null && !(parent instanceof Auxhead))
127: throw new UiException("Wrong parent: " + parent);
128: super.setParent(parent);
129: }
130: }
|