001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.dao.search;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import javax.portlet.RenderResponse;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class RowChecker {
026    
027            public static final String ALIGN = "left";
028    
029            public static final String VALIGN = "middle";
030    
031            public static final int COLSPAN = 1;
032    
033            public static final String FORM_NAME = "fm";
034    
035            public static final String ALL_ROW_IDS = "allRowIds";
036    
037            public static final String ROW_IDS = "rowIds";
038    
039            public RowChecker(RenderResponse renderResponse) {
040                    this(
041                            renderResponse, ALIGN, VALIGN, COLSPAN, FORM_NAME, ALL_ROW_IDS,
042                            ROW_IDS);
043            }
044    
045            public RowChecker(
046                    RenderResponse renderResponse, String align, String valign,
047                    String formName, String allRowsId, String rowId) {
048    
049                    this(
050                            renderResponse, align, valign, COLSPAN, formName, allRowsId, rowId);
051            }
052    
053            public RowChecker(
054                    RenderResponse renderResponse, String align, String valign, int colspan,
055                    String formName, String allRowsId, String rowId) {
056    
057                    _align = align;
058                    _valign = valign;
059                    _colspan = colspan;
060                    _formName = renderResponse.getNamespace() + formName;
061    
062                    if (Validator.isNotNull(allRowsId)) {
063                            _allRowsId = renderResponse.getNamespace() + allRowsId;
064                    }
065    
066                    _rowId = renderResponse.getNamespace() + rowId;
067            }
068    
069            public String getAlign() {
070                    return _align;
071            }
072    
073            public String getValign() {
074                    return _valign;
075            }
076    
077            public int getColspan() {
078                    return _colspan;
079            }
080    
081            public String getFormName() {
082                    return _formName;
083            }
084    
085            public String getAllRowsId() {
086                    return _allRowsId;
087            }
088    
089            public String getRowId() {
090                    return _rowId;
091            }
092    
093            public String getAllRowsCheckBox() {
094                    if (Validator.isNull(_allRowsId)) {
095                            return StringPool.BLANK;
096                    }
097                    else {
098                            StringBuilder sb = new StringBuilder();
099    
100                            sb.append("<input name=\"");
101                            sb.append(_allRowsId);
102                            sb.append("\" type=\"checkbox\" ");
103                            sb.append("onClick=\"Liferay.Util.checkAll(");
104                            sb.append("AUI().one(this).ancestor('");
105                            sb.append("table.taglib-search-iterator'), '");
106                            sb.append(_rowId);
107                            sb.append("', this");
108                            sb.append(");\">");
109    
110                            return sb.toString();
111                    }
112            }
113    
114            public String getRowCheckBox(boolean checked, String primaryKey) {
115                    StringBuilder sb = new StringBuilder();
116    
117                    sb.append("<input ");
118    
119                    if (checked) {
120                            sb.append("checked ");
121                    }
122    
123                    sb.append("name=\"");
124                    sb.append(_rowId);
125                    sb.append("\" type=\"checkbox\" value=\"");
126                    sb.append(primaryKey);
127                    sb.append("\" ");
128    
129                    if (Validator.isNotNull(_allRowsId)) {
130                            sb.append("onClick=\"Liferay.Util.checkAllBox(");
131                            sb.append("AUI().one(this).ancestor('");
132                            sb.append("table.taglib-search-iterator'), '");
133                            sb.append(_rowId);
134                            sb.append("', ");
135                            sb.append(_allRowsId);
136                            sb.append(");\"");
137                    }
138    
139                    sb.append(">");
140    
141                    return sb.toString();
142            }
143    
144            public boolean isChecked(Object obj) {
145                    return false;
146            }
147    
148            private String _align;
149            private String _valign;
150            private int _colspan;
151            private String _formName;
152            private String _allRowsId;
153            private String _rowId;
154    
155    }