001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.kernel.dao.search;
022:
023: import com.liferay.portal.kernel.util.StringMaker;
024: import com.liferay.portal.kernel.util.StringPool;
025: import com.liferay.portal.kernel.util.Validator;
026:
027: import javax.portlet.RenderResponse;
028:
029: /**
030: * <a href="RowChecker.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class RowChecker {
036:
037: public static final String ALIGN = "left";
038:
039: public static final String VALIGN = "middle";
040:
041: public static final int COLSPAN = 1;
042:
043: public static final String FORM_NAME = "fm";
044:
045: public static final String ALL_ROW_IDS = "allRowIds";
046:
047: public static final String ROW_IDS = "rowIds";
048:
049: public RowChecker(RenderResponse res) {
050: this (res, ALIGN, VALIGN, COLSPAN, FORM_NAME, ALL_ROW_IDS,
051: ROW_IDS);
052: }
053:
054: public RowChecker(RenderResponse res, String align, String valign,
055: String formName, String allRowsId, String rowId) {
056:
057: this (res, align, valign, COLSPAN, formName, allRowsId, rowId);
058: }
059:
060: public RowChecker(RenderResponse res, String align, String valign,
061: int colspan, String formName, String allRowsId, String rowId) {
062:
063: _align = align;
064: _valign = valign;
065: _colspan = colspan;
066: _formName = res.getNamespace() + formName;
067:
068: if (Validator.isNotNull(allRowsId)) {
069: _allRowsId = res.getNamespace() + allRowsId;
070: }
071:
072: _rowId = res.getNamespace() + rowId;
073: }
074:
075: public String getAlign() {
076: return _align;
077: }
078:
079: public String getValign() {
080: return _valign;
081: }
082:
083: public int getColspan() {
084: return _colspan;
085: }
086:
087: public String getFormName() {
088: return _formName;
089: }
090:
091: public String getAllRowsId() {
092: return _allRowsId;
093: }
094:
095: public String getRowId() {
096: return _rowId;
097: }
098:
099: public String getAllRowsCheckBox() {
100: if (Validator.isNull(_allRowsId)) {
101: return StringPool.BLANK;
102: } else {
103: StringMaker sm = new StringMaker();
104:
105: sm.append("<input name=\"");
106: sm.append(_allRowsId);
107: sm.append("\" type=\"checkbox\" ");
108: sm.append("onClick=\"Liferay.Util.checkAll(");
109: sm.append(_formName);
110: sm.append(", '");
111: sm.append(_rowId);
112: sm.append("', this");
113: sm.append(");\">");
114:
115: return sm.toString();
116: }
117: }
118:
119: public String getRowCheckBox(boolean checked, String primaryKey) {
120: StringMaker sm = new StringMaker();
121:
122: sm.append("<input ");
123:
124: if (checked) {
125: sm.append("checked ");
126: }
127:
128: sm.append("name=\"");
129: sm.append(_rowId);
130: sm.append("\" type=\"checkbox\" value=\"");
131: sm.append(primaryKey);
132: sm.append("\" ");
133:
134: if (Validator.isNotNull(_allRowsId)) {
135: sm.append("onClick=\"Liferay.Util.checkAllBox(");
136: sm.append(_formName);
137: sm.append(", '");
138: sm.append(_rowId);
139: sm.append("', ");
140: sm.append(_allRowsId);
141: sm.append(");\"");
142: }
143:
144: sm.append(">");
145:
146: return sm.toString();
147: }
148:
149: public boolean isChecked(Object obj) {
150: return false;
151: }
152:
153: private String _align;
154: private String _valign;
155: private int _colspan;
156: private String _formName;
157: private String _allRowsId;
158: private String _rowId;
159:
160: }
|