001: /**
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: TableRowTag.java 6385 2007-10-25 14:02:26Z wehrens $
004: */package org.gridsphere.provider.portletui.tags;
005:
006: import org.gridsphere.provider.portletui.beans.TableRowBean;
007:
008: import javax.servlet.jsp.JspException;
009: import javax.servlet.jsp.JspWriter;
010: import javax.servlet.jsp.tagext.Tag;
011:
012: /**
013: * The <code>TableRowTag</code> represents a table row element that is conatined within a <code>TableTag</code>
014: * and itself may contain <code>TableCellTag</code>s
015: */
016: public class TableRowTag extends BaseComponentTag {
017:
018: protected TableRowBean rowBean = null;
019: protected boolean isHeader = false;
020: protected String align = null;
021: protected String valign = null;
022: protected boolean isZebra = false;
023:
024: /**
025: * Sets the table row bean
026: *
027: * @param tableRowBean the table row bean
028: */
029: public void setTableRowBean(TableRowBean tableRowBean) {
030: rowBean = tableRowBean;
031: }
032:
033: /**
034: * Returns the table row bean
035: *
036: * @return the table row bean
037: */
038: public TableRowBean getTableRowBean() {
039: return rowBean;
040: }
041:
042: /**
043: * Indicates if this table row is a table header
044: *
045: * @param isHeader is true if this row is a table header
046: */
047: public void setHeader(boolean isHeader) {
048: this .isHeader = isHeader;
049: }
050:
051: /**
052: * Indicates if this table row is a table header
053: *
054: * @return true if this row is a table header, false otherwise
055: */
056: public boolean getHeader() {
057: return isHeader;
058: }
059:
060: /**
061: * Sets the table alignment e.g. "left", "center" or "right"
062: *
063: * @param align the table alignment
064: */
065: public void setAlign(String align) {
066: this .align = align;
067: }
068:
069: /**
070: * Returns the table alignment e.g. "left", "center" or "right"
071: *
072: * @return the table alignment
073: */
074: public String getAlign() {
075: return align;
076: }
077:
078: /**
079: * Sets the table vertical alignment e.g. "top", "middle", "bottom" or "baseline"
080: *
081: * @param valign the table vertical alignment
082: */
083: public void setValign(String valign) {
084: this .valign = valign;
085: }
086:
087: /**
088: * Returns the table vertical alignment e.g. "top", "middle", "bottom" or "baseline"
089: *
090: * @return the table vertical alignment
091: */
092: public String getValign() {
093: return valign;
094: }
095:
096: public void setZebra(boolean isZebra) {
097: this .isZebra = isZebra;
098: }
099:
100: public boolean getZebra() {
101: return isZebra;
102: }
103:
104: public void release() {
105: rowBean = null;
106: isHeader = false;
107: align = null;
108: valign = null;
109: isZebra = false;
110: super .release();
111: }
112:
113: public int doStartTag() throws JspException {
114:
115: Tag parent = this .getParent();
116: if (parent instanceof TableTag) {
117: TableTag tableTag = (TableTag) parent;
118: int maxrows = tableTag.getMaxrows();
119: boolean filter = tableTag.getFilter();
120: // logic to determine if alternate (darkened row) should be set
121: if (tableTag.getZebra()) {
122: if ((tableTag.getRowCount() % 2) == 0) {
123: isZebra = true;
124: } else {
125: isZebra = false;
126: }
127: }
128:
129: // logic to determine what rows to display if table is broken into pages
130: if (!isHeader) {
131: tableTag.incrementRowCount();
132: }
133:
134: // need to determine which rows to display
135: int currpage = tableTag.getCurrentPage();
136: if (!isHeader) {
137: if (maxrows > 0) {
138: if (!filter) {
139: if ((tableTag.getRowCount() <= maxrows
140: * currpage)
141: || (tableTag.getRowCount() > maxrows
142: * (currpage + 1))) {
143: return EVAL_PAGE;
144: }
145: }
146: }
147: }
148: }
149:
150: if (!beanId.equals("")) {
151: rowBean = (TableRowBean) getTagBean();
152: if (rowBean == null)
153: rowBean = new TableRowBean();
154: } else {
155: rowBean = new TableRowBean();
156: rowBean.setHeader(isHeader);
157: if (align != null)
158: rowBean.setAlign(align);
159: if (valign != null)
160: rowBean.setValign(valign);
161: if (cssStyle != null)
162: rowBean.setCssStyle(cssStyle);
163: if (cssClass != null)
164: rowBean.setCssClass(cssClass);
165: }
166:
167: rowBean.setZebra(isZebra);
168:
169: try {
170: JspWriter out = pageContext.getOut();
171: out.print(rowBean.toStartString());
172: } catch (Exception e) {
173: throw new JspException(e.getMessage());
174: }
175: return EVAL_BODY_INCLUDE;
176: }
177:
178: public int doEndTag() throws JspException {
179: try {
180: JspWriter out = pageContext.getOut();
181: out.print(rowBean.toEndString());
182: } catch (Exception e) {
183: throw new JspException(e.getMessage());
184: }
185: isZebra = false;
186: super.doEndTag();
187: return EVAL_PAGE;
188: }
189: }
|