KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > backup > renderer > html > ImportDataRenderer


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.portlets.backup.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.ResourceBundle JavaDoc;
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import org.exoplatform.faces.FacesConstants;
14 import org.exoplatform.faces.core.component.model.Parameter;
15 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
16 import org.exoplatform.portlets.backup.component.UIImportData;
17 import org.exoplatform.portlets.backup.component.model.ImportData;
18 /**
19  * May 31, 2004
20  * @author: Tuan Nguyen
21  * @email: tuan08@users.sourceforge.net
22  * @version: $ID$
23  **/

24 public class ImportDataRenderer extends HtmlBasicRenderer {
25   final public static String JavaDoc IMPORT_ICON = "<img class='import-icon' SRC='/skin/blank.gif'/>";
26   final public static String JavaDoc REFRESH_ICON = "<img class='refresh-icon' SRC='/skin/blank.gif'/>";
27   final public static String JavaDoc VIEW_ICON = "<img class='view-icon' SRC='/skin/blank.gif'/>";
28   private static Parameter IMPORT_DATA = new Parameter(FacesConstants.ACTION , "importData") ;
29   private static Parameter VIEW_DATA = new Parameter(FacesConstants.ACTION , "viewData") ;
30   private static Parameter[] refreshParams = {new Parameter(FacesConstants.ACTION , "refresh") };
31   private static Parameter[] importAllParams = {new Parameter(FacesConstants.ACTION , "importAll") };
32
33      public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
34     UIImportData uiImportData = (UIImportData) component;
35     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
36     String JavaDoc importDataButton = res.getString("UIImportData.button.import-data") ;
37     String JavaDoc importAllButton = res.getString("UIImportData.button.import-all") ;
38     String JavaDoc viewDataButton = res.getString("UIImportData.button.view-data") ;
39     String JavaDoc refreshButton = res.getString("UIImportData.button.refresh") ;
40     ResponseWriter w = context.getResponseWriter() ;
41     List JavaDoc list = uiImportData.getImportDatas() ;
42     Parameter nameParam = new Parameter("dataName" , "");
43     Parameter[] importDataParams = { IMPORT_DATA , nameParam} ;
44     Parameter[] viewDataParams = { VIEW_DATA , nameParam} ;
45     w.write("<table class='UIImportData'>") ;
46     w. write("<tr>") ;
47     w. write("<th>"); w.write(res.getString("UIImportData.header.data-name")) ;w.write("</th>") ;
48     w. write("<th>"); w.write(res.getString("UIImportData.header.created-date")); w.write("</th>") ;
49     w. write("<th>"); w.write(res.getString("UIImportData.header.modified-date")); w.write("</th>") ;
50     w. write("<th>"); w.write(res.getString("UIImportData.header.action")); w.write("</th>") ;
51     w. write("</tr>") ;
52     for(int i = 0; i < list.size(); i++) {
53         ImportData data = (ImportData) list.get(i) ;
54         nameParam.setValue(data.getName()) ;
55       String JavaDoc clazz = "odd";
56       if (i % 2 == 0) clazz = "even";
57       w.write("<tr class='" + clazz + "'>") ;
58       w. write("<td>"); w.write(data.getName()) ;w.write("</td>") ;
59       w. write("<td>"); w.write(data.getCreatedDate().toString()); w.write("</td>") ;
60       w. write("<td>"); w.write(data.getModifiedDate().toString()); w.write("</td>") ;
61       w. write("<td class='action'>");
62       if(uiImportData.hasAdminRole()) {
63         linkRenderer_.render(w, uiImportData,IMPORT_ICON + importDataButton, importDataParams) ;
64         linkRenderer_.render(w, uiImportData,VIEW_ICON + viewDataButton, viewDataParams) ;
65       } else {
66         w.write('-');
67       }
68       w. write("</td>") ;
69       w.write("</tr>") ;
70     }
71     w. write("<tr class='footer'>") ;
72     w. write("<td colspan='4' style='text-align: center'>");
73     linkRenderer_.render(w,uiImportData, refreshButton, refreshParams) ;
74     linkRenderer_.render(w,uiImportData, importAllButton, importAllParams) ;
75     w. write("</td>");
76     w. write("</tr>") ;
77     w.write("</table>") ;
78      }
79 }
Popular Tags