001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.tag;
020
021import javax.servlet.jsp.tagext.Tag;
022
023import lucee.commons.color.ColorCaster;
024import lucee.commons.lang.StringUtil;
025import lucee.runtime.exp.ExpressionException;
026import lucee.runtime.exp.PageException;
027import lucee.runtime.exp.TagNotSupported;
028import lucee.runtime.ext.tag.TagImpl;
029import lucee.runtime.type.util.ListUtil;
030
031/**
032* Used with cfgrid in a cfform, you use cfgridcolumn to specify column data in a cfgrid control. Font and alignment 
033*   attributes used in cfgridcolumn override any global font or alignment settings defined in cfgrid.
034*
035*
036*
037**/
038public final class GridColumn extends TagImpl {
039
040        private GridColumnBean column=new GridColumnBean();
041        
042        public GridColumn() throws TagNotSupported {
043                throw new TagNotSupported("GridColumn");
044        }
045
046        private String valuesdelimiter=",";
047        private String valuesdisplay;
048        private String values;
049        
050        @Override
051        public void release()   {
052                column=new GridColumnBean();
053                valuesdelimiter=",";
054                valuesdisplay=null;
055                values=null;
056        }
057
058        /**
059         * @param mask the mask to set
060         */
061        public void setMask(String mask) {
062                column.setMask(mask);
063        }
064        
065        /** set the value display
066        *  Yes or No. Use to hide columns. Default is Yes to display the column.
067        * @param display value to set
068        **/
069        public void setDisplay(boolean display) {
070                column.setDisplay(display);
071        }
072
073        /** set the value width
074        *  The width of the column, in pixels. Default is the width of the column head text.
075        * @param width value to set
076        **/
077        public void setWidth(double width)      {
078                column.setWidth((int) width);
079        }
080
081        /** set the value headerfontsize
082        *  Font size to use for the column header, in pixels. Default is as specified by the 
083        *               orresponding attribute of cfgrid.
084        * @param headerfontsize value to set
085        **/
086        public void setHeaderfontsize(double headerfontsize)    {
087                column.setHeaderFontSize((int)headerfontsize);
088        }
089
090        /** set the value hrefkey
091        *  The name of a query column when the grid uses a query. The column specified becomes the Key 
092        *               regardless of the select mode for the grid.
093        * @param hrefkey value to set
094        **/
095        public void setHrefkey(String hrefkey)  {
096                column.setHrefKey(hrefkey);
097        }
098
099        /** set the value target
100        *  The name of the frame in which to open the link specified in href.
101        * @param target value to set
102        **/
103        public void setTarget(String target)    {
104                column.setTarget(target);
105        }
106
107        /** set the value values
108        *  Formats cells in the column as drop down list boxes. lets end users select an item in a drop 
109        *               down list. Use the values attribute to specify the items you want to appear in the drop down list.
110        * @param values value to set
111        **/
112        public void setValues(String values)    {
113                this.values=values;
114        }
115
116        /** set the value headerfont
117        *  Font to use for the column header. Default is as specified by the corresponding attribute of 
118        *               cfgrid.
119        * @param headerfont value to set
120        **/
121        public void setHeaderfont(String headerfont)    {
122                column.setHeaderFont(headerfont);
123        }
124
125        /** set the value font
126        *  Font name to use for data in the column. Defaults is the font specified by cfgrid.
127        * @param font value to set
128        **/
129        public void setFont(String font)        {
130                column.setFont(font);
131        }
132
133        /** set the value italic
134        *  Yes or No. Yes displays all grid control text in italic. Default is as specified by the 
135        *               corresponding attribute of cfgrid.
136        * @param italic value to set
137        **/
138        public void setItalic(boolean italic)   {
139                column.setItalic(italic);
140        }
141
142        /** set the value bgcolor
143        *  Color value for the background of the grid column, or an expression you can use to manipulate grid 
144        *               column background color. Valid color entries are: black, magenta, cyan, orange, darkgray, pink, gray, 
145        *               white (default), lightgray, yellow.
146        * @param bgcolor value to set
147         * @throws ExpressionException 
148        **/
149        public void setBgcolor(String bgcolor) throws ExpressionException       {
150                column.setBgColor(ColorCaster.toColor(bgcolor));
151        }
152
153        /** set the value valuesdisplay
154        *  Used to map elements specified in the values attribute to a string of your choice to display 
155        *               in the drop down list. Enter comma separated strings and/or numeric range(s).
156        * @param valuesdisplay value to set
157        **/
158        public void setValuesdisplay(String valuesdisplay)      {
159                this.valuesdisplay=valuesdisplay;
160        }
161
162        /** set the value headeritalic
163        *  Yes or No. Yes displays column header text in italic. Default is as specified by the 
164        *               corresponding attribute of cfgrid.
165        * @param headeritalic value to set
166        **/
167        public void setHeaderitalic(boolean headeritalic)       {
168                column.setHeaderItalic(headeritalic);
169        }
170
171        /** set the value name
172        *  A name for the grid column element. If the grid uses a query, the column name must specify the 
173        *               name of a query column.
174        * @param name value to set
175        **/
176        public void setName(String name)        {
177                column.setName(name);
178        }
179
180        /** set the value href
181        *  URL to associate with the grid item. You can specify a URL that is relative to the current page
182        * @param href value to set
183        **/
184        public void setHref(String href)        {
185                column.setHref(href);
186        }
187
188        /** set the value type
189        *  
190        * @param type value to set
191        **/
192        public void setType(String type)        {
193                column.setType(type);
194        }
195
196        /** set the value valuesdelimiter
197        *  Character to use as a delimiter in the values and valuesDisplay attributes. Default 
198        *               is "," (comma).
199        * @param valuesdelimiter value to set
200        **/
201        public void setValuesdelimiter(String valuesdelimiter)  {
202                this.valuesdelimiter=valuesdelimiter;
203        }
204
205        /** set the value numberformat
206        *  The format for displaying numeric data in the grid. For information about mask characters, 
207        *               see "numberFormat mask characters".
208        * @param numberformat value to set
209        **/
210        public void setNumberformat(String numberformat)        {
211                column.setNumberFormat(numberformat);
212        }
213
214        /** set the value header
215        *  Text for the column header. The value of header is used only when the cfgrid colHeaders 
216        *               attribute is Yes (or omitted, since it defaults to Yes).
217        * @param header value to set
218        **/
219        public void setHeader(String header)    {
220                column.setHeader(header);
221        }
222
223        /** set the value textcolor
224        *  Color value for grid element text in the grid column, or an expression you can use to manipulate text 
225        *               color in grid column elements. Valid color entries are: black (default), magenta, cyan, orange, 
226        *               arkgray, pink, gray, white, lightgray, yellow
227        * @param textcolor value to set
228         * @throws ExpressionException 
229        **/
230        public void setTextcolor(String textcolor) throws ExpressionException   {
231                column.setTextColor(ColorCaster.toColor(textcolor));
232        }
233
234        /** set the value select
235        *  Yes or No. Yes lets end users select a column in a grid control. When No, the column cannot 
236        *               be edited, even if the cfgrid insert or delete attributes are enabled. The value of the select 
237        *               attribute is ignored if the cfgrid selectMode attribute is set to Row or Browse.
238        * @param select value to set
239        **/
240        public void setSelect(boolean select)   {
241                column.setSelect(select);
242        }
243
244        /** set the value headeralign
245        *  Alignment for the column header text. Default is as specified by cfgrid.
246        * @param headeralign value to set
247        **/
248        public void setHeaderalign(String headeralign)  {
249                column.setHeaderAlign(headeralign);
250        }
251
252        /** set the value dataalign
253        *  Alignment for column data. Entries are: left, center, or right. Default is as specified 
254        *               by cfgrid.
255        * @param dataalign value to set
256        **/
257        public void setDataalign(String dataalign)      {
258                column.setDataAlign(dataalign);
259        }
260
261        /** set the value bold
262        *  Yes or No. Yes displays all grid control text in boldface. Default is as specified by the 
263        *               corresponding attribute of cfgrid.
264        * @param bold value to set
265        **/
266        public void setBold(boolean bold)       {
267                column.setBold(bold);
268        }
269
270        /** set the value headerbold
271        *  Yes or No. Yes displays header text in boldface. Default is as specified by the 
272        *               corresponding attribute of cfgrid.
273        * @param headerbold value to set
274        **/
275        public void setHeaderbold(boolean headerbold)   {
276                column.setHeaderBold(headerbold);
277        }
278
279        /** set the value colheadertextcolor
280        *  Color value for the grid control column header text. Entries are: black (default), magenta, 
281        *               cyan, orange, darkgray, pink, gray, white, lightgray, yellow.
282        * @param headertextcolor value to set
283         * @throws ExpressionException 
284        **/
285        public void setHeadertextcolor(String headertextcolor) throws ExpressionException       {
286                column.setHeaderTextColor(ColorCaster.toColor(headertextcolor));
287        }
288
289        /** set the value fontsize
290        *  Font size for text in the column. Default is the font specified by cfgrid.
291        * @param fontsize value to set
292        **/
293        public void setFontsize(double fontsize)        {
294                column.setFontSize((int)fontsize);
295        }
296
297
298        @Override
299        public int doStartTag() throws PageException    {
300                
301                if(!StringUtil.isEmpty(values))
302                        column.setValues(ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(values, valuesdelimiter)));
303                if(!StringUtil.isEmpty(valuesdisplay))
304                        column.setValuesDisplay(ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(valuesdisplay, valuesdelimiter)));
305
306                // provide to parent
307                Tag parent=this;
308                do{
309                        parent = parent.getParent();
310                        if(parent instanceof Grid) {
311                                ((Grid)parent).addColumn(column);
312                                break;
313                        }
314                }
315                while(parent!=null);
316                
317                return SKIP_BODY;
318        }
319
320        @Override
321        public int doEndTag()   {
322                return EVAL_PAGE;
323        }
324
325
326}