KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > component > model > Cell


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.faces.core.component.model;
6
7 import java.util.* ;
8 import java.io.IOException JavaDoc ;
9 import javax.faces.context.ResponseWriter ;
10 import org.exoplatform.faces.core.component.UIGrid;
11 import org.exoplatform.commons.utils.ExpressionUtil ;
12 /**
13  * Wed, Dec 22, 2003 @ 23:14
14  * @author: Tuan Nguyen
15  * @email: tuan08@users.sourceforge.net
16  * @version: $Id: Cell.java,v 1.3 2004/06/30 19:52:01 tuan08 Exp $
17  */

18 public class Cell {
19   protected List attributes_ ;
20   protected String JavaDoc value_ ;
21   
22   public Cell() {
23     
24   }
25   
26   public Cell (String JavaDoc value) {
27     value_ = value ;
28   }
29   
30   public Cell(int value) {
31     value_ = Integer.toString(value) ;
32   }
33
34   public Cell(long value) {
35     value_ = Long.toString(value) ;
36   }
37
38   public Cell(float value) {
39     value_ = Float.toString(value) ;
40   }
41
42   public Cell(double value) {
43     value_ = Double.toString(value) ;
44   }
45
46   public Cell(Date value) {
47     value_ = value.toString() ;
48   }
49
50   public Cell setValue(String JavaDoc value) {
51     if(value == null) value_ ="" ;
52     else value_ = value ;
53     return this ;
54   }
55   
56   public Cell setValue(Date value) {
57     if(value == null) value_ = "" ;
58     else value_ = value.toString() ;
59     return this ;
60   }
61
62   public Cell addAttribute(String JavaDoc name, String JavaDoc value) {
63     if(attributes_ == null) attributes_ = new ArrayList(3) ;
64     attributes_.add(new Attribute(name, value)) ;
65     return this ;
66   }
67
68   public Cell addClazz(String JavaDoc clazz) {
69     addAttribute("class", clazz) ;
70     return this ;
71   }
72
73   public Cell addStyle(String JavaDoc style) {
74     addAttribute("style", style) ;
75     return this ;
76   }
77
78   public Cell addColspan(String JavaDoc s) {
79     addAttribute("colspan", s) ;
80     return this ;
81   }
82
83   public Cell addRowspan(String JavaDoc s) {
84     addAttribute("rowspan", s) ;
85     return this ;
86   }
87
88   public Cell addWidth(String JavaDoc w) {
89     addAttribute("width", w) ;
90     return this ;
91   }
92
93   public Cell addAlign(String JavaDoc s) {
94     addAttribute("align", s) ;
95     return this ;
96   }
97
98   public Cell addValign(String JavaDoc s) {
99     addAttribute("valign", s) ;
100     return this ;
101   }
102
103   public Cell addHeight(String JavaDoc h) {
104     addAttribute("height", h) ;
105     return this ;
106   }
107
108   public class Attribute {
109     String JavaDoc name_ ;
110     String JavaDoc value_ ;
111
112     public Attribute(String JavaDoc name, String JavaDoc value) {
113       name_ = name ;
114       value_ = value ;
115     }
116   }
117   
118   public void render(ResponseWriter w, ResourceBundle res, UIGrid uiGrid, String JavaDoc tag) throws IOException JavaDoc {
119     w.write('<'); w.write(tag) ;
120     if(attributes_ != null) {
121       int size = attributes_.size() ;
122       for(int i = 0; i < size ; i++) {
123         Cell.Attribute attr = (Cell.Attribute) attributes_.get(i) ;
124         w.write(" "); w.write(attr.name_); w.write("=\""); w.write(attr.value_); w.write('\"') ;
125       }
126     }
127     w.write('>') ;
128     w.write(ExpressionUtil.getExpressionValue(res,value_)) ;
129     w.write("</"); w.write(tag); w.write(">") ;
130   }
131 }
Popular Tags