1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.dao.search;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  import com.liferay.portal.kernel.util.Validator;
19  
20  import javax.portlet.RenderResponse;
21  
22  /**
23   * <a href="RowChecker.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Brian Wing Shun Chan
26   */
27  public class RowChecker {
28  
29      public static final String ALIGN = "left";
30  
31      public static final String VALIGN = "middle";
32  
33      public static final int COLSPAN = 1;
34  
35      public static final String FORM_NAME = "fm";
36  
37      public static final String ALL_ROW_IDS = "allRowIds";
38  
39      public static final String ROW_IDS = "rowIds";
40  
41      public RowChecker(RenderResponse renderResponse) {
42          this(
43              renderResponse, ALIGN, VALIGN, COLSPAN, FORM_NAME, ALL_ROW_IDS,
44              ROW_IDS);
45      }
46  
47      public RowChecker(
48          RenderResponse renderResponse, String align, String valign,
49          String formName, String allRowsId, String rowId) {
50  
51          this(
52              renderResponse, align, valign, COLSPAN, formName, allRowsId, rowId);
53      }
54  
55      public RowChecker(
56          RenderResponse renderResponse, String align, String valign, int colspan,
57          String formName, String allRowsId, String rowId) {
58  
59          _align = align;
60          _valign = valign;
61          _colspan = colspan;
62          _formName = renderResponse.getNamespace() + formName;
63  
64          if (Validator.isNotNull(allRowsId)) {
65              _allRowsId = renderResponse.getNamespace() + allRowsId;
66          }
67  
68          _rowId = renderResponse.getNamespace() + rowId;
69      }
70  
71      public String getAlign() {
72          return _align;
73      }
74  
75      public String getValign() {
76          return _valign;
77      }
78  
79      public int getColspan() {
80          return _colspan;
81      }
82  
83      public String getFormName() {
84          return _formName;
85      }
86  
87      public String getAllRowsId() {
88          return _allRowsId;
89      }
90  
91      public String getRowId() {
92          return _rowId;
93      }
94  
95      public String getAllRowsCheckBox() {
96          if (Validator.isNull(_allRowsId)) {
97              return StringPool.BLANK;
98          }
99          else {
100             StringBuilder sb = new StringBuilder();
101 
102             sb.append("<input name=\"");
103             sb.append(_allRowsId);
104             sb.append("\" type=\"checkbox\" ");
105             sb.append("onClick=\"Liferay.Util.checkAll(");
106             sb.append("AUI().one(this).ancestor('");
107             sb.append("table.taglib-search-iterator'), '");
108             sb.append(_rowId);
109             sb.append("', this");
110             sb.append(");\">");
111 
112             return sb.toString();
113         }
114     }
115 
116     public String getRowCheckBox(boolean checked, String primaryKey) {
117         StringBuilder sb = new StringBuilder();
118 
119         sb.append("<input ");
120 
121         if (checked) {
122             sb.append("checked ");
123         }
124 
125         sb.append("name=\"");
126         sb.append(_rowId);
127         sb.append("\" type=\"checkbox\" value=\"");
128         sb.append(primaryKey);
129         sb.append("\" ");
130 
131         if (Validator.isNotNull(_allRowsId)) {
132             sb.append("onClick=\"Liferay.Util.checkAllBox(");
133             sb.append("AUI().one(this).ancestor('");
134             sb.append("table.taglib-search-iterator'), '");
135             sb.append(_rowId);
136             sb.append("', ");
137             sb.append(_allRowsId);
138             sb.append(");\"");
139         }
140 
141         sb.append(">");
142 
143         return sb.toString();
144     }
145 
146     public boolean isChecked(Object obj) {
147         return false;
148     }
149 
150     private String _align;
151     private String _valign;
152     private int _colspan;
153     private String _formName;
154     private String _allRowsId;
155     private String _rowId;
156 
157 }