KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > workflow > renderer > html > BPDefinitionRenderer


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
6 package org.exoplatform.portlets.workflow.renderer.html;
7
8 import org.exoplatform.faces.FacesConstants;
9 import org.exoplatform.faces.core.component.model.Parameter;
10 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
11 import org.exoplatform.portlets.workflow.component.UIBPDefinition;
12 import org.jbpm.model.definition.Definition;
13
14 import javax.faces.component.UIComponent;
15 import javax.faces.context.FacesContext;
16 import javax.faces.context.ResponseWriter;
17 import java.io.IOException JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.ResourceBundle JavaDoc;
21 import java.util.ArrayList JavaDoc;
22
23 /**
24  * Created y the eXo platform team
25  * User: Benjamin Mestrallet
26  * Date: 15 mai 2004
27  */

28 public class BPDefinitionRenderer extends HtmlBasicRenderer {
29
30   private static Parameter MANAGE_START = new Parameter(ACTION, UIBPDefinition.MANAGE_START);
31
32   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
33     UIBPDefinition uibpDefinition = (UIBPDefinition) component;
34
35     String JavaDoc baseURL = uibpDefinition.getBaseURL(context);
36
37     ResponseWriter w = context.getResponseWriter();
38     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext());
39
40     Collection JavaDoc bps = new ArrayList JavaDoc();
41     try {
42       bps = uibpDefinition.getAllDefinition();
43     } catch (Exception JavaDoc e) {
44       e.printStackTrace() ;
45     }
46     w.write("<div align='center'>");
47     w.write("<table class='UIBPDefinition'>");
48     w.write("<tr>");
49     w.write("<th>");
50     w.write(res.getString("UIBPDefinition.header.icon"));
51     w.write("</th>");
52     w.write("<th>");
53     w.write(res.getString("UIBPDefinition.header.id"));
54     w.write("</th>");
55     w.write("<th>");
56     w.write(res.getString("UIBPDefinition.header.name"));
57     w.write("</th>");
58     w.write("<th>");
59     w.write(res.getString("UIBPDefinition.header.description"));
60     w.write("</th>");
61     w.write("<th>");
62     w.write(res.getString("UIBPDefinition.header.version"));
63     w.write("</th>");
64     w.write("<th>");
65     w.write(res.getString("UIBPDefinition.header.start"));
66     w.write("</th>");
67     if (bps == null)
68       return;
69     int i = 0;
70     if (bps.isEmpty()) {
71       w.write("<tr>");
72       w. write("<td>");
73       w. write("<img SRC='/workflow/images/empty.gif' />");
74       w. write("</td>");
75       w. write("<td colspan='5'>");
76       w. write(res.getString("UIBPDefinition.empty.process.list"));
77       w. write("</td>");
78       w.write("</tr>");
79     } else {
80       Iterator JavaDoc dataIterator = bps.iterator();
81       while (dataIterator.hasNext()) {
82         Definition definition = (Definition) dataIterator.next();
83         String JavaDoc clazz = "odd";
84         if (i % 2 == 0)
85           clazz = "even";
86         Integer JavaDoc version = definition.getVersion();
87         if (version == null)
88           version = new Integer JavaDoc(-1);
89         w.write("<tr class='" + clazz + "'>");
90         w.write("<td>");
91         if (version.intValue() < 1) {
92           w.write("<img SRC='/workflow/images/no_version.gif' />");
93         } else if (version.intValue() == 1) {
94           w.write("<img SRC='/workflow/images/initial_version.gif' />");
95         }
96         if (version.intValue() > 1) {
97           w.write("<img SRC='/workflow/images/modified_version.gif' />");
98         }
99         w.write("</td>");
100         w.write("<td>");
101         w.write(definition.getId().toString());
102         w.write("</td>");
103         w.write("<td>");
104         w.write(definition.getName());
105         w.write("</td>");
106         String JavaDoc description = definition.getDescription();
107         if (description == null)
108           description = "N/A";
109         w.write("<td>");
110         w.write(description);
111         w.write("</td>");
112         w.write("<td>");
113         w.write(version.toString());
114         w.write("</td>");
115         w.write("<td>");
116         Parameter processId = new Parameter("process", definition.getId().toString());
117         Parameter[] startProcessParams = {MANAGE_START, processId};
118         appendLink(w, res.getString("UIBPDefinition.label.start"), baseURL, startProcessParams, null);
119         w.write("</td>");
120         w.write("</tr>");
121         i++;
122       }
123     }
124     w.write("</table>");
125     w.write("</div>");
126   }
127
128 }
129
Popular Tags