KickJava   Java API By Example, From Geeks To Geeks.

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


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.UITaskList;
12 import org.exoplatform.portlets.workflow.component.UIWorkflowPortlet;
13 import org.jbpm.model.definition.Definition;
14 import org.jbpm.model.execution.Token;
15
16 import javax.faces.component.UIComponent;
17 import javax.faces.context.FacesContext;
18 import javax.faces.context.ResponseWriter;
19 import java.io.IOException JavaDoc;
20 import java.text.SimpleDateFormat JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24
25 /**
26  * Created y the eXo platform team
27  * User: Benjamin Mestrallet
28  * Date: 16 mai 2004
29  */

30 public class TaskListRenderer extends HtmlBasicRenderer {
31
32   private static Parameter MANAGE_STATE = new Parameter(FacesConstants.ACTION, "manageState");
33
34   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
35     UITaskList uiTaskList = (UITaskList) component;
36     String JavaDoc baseURL = uiTaskList.getBaseURL(context);
37     ResponseWriter w = context.getResponseWriter();
38     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext());
39     String JavaDoc remoteUser = context.getExternalContext().getRemoteUser();
40     if (remoteUser == null)
41       remoteUser = UIWorkflowPortlet.ANONYMOUS_USER;
42     Collection JavaDoc bps = uiTaskList.getTaskList(remoteUser);
43     w.write("<div align='center'>");
44     w.write("<table class='UITaskList'>");
45     w.write("<tr>");
46     w.write("<th>");
47     w.write(res.getString("UITaskList.header.icon"));
48     w.write("</th>");
49     w.write("<th>");
50     w.write(res.getString("UITaskList.header.id"));
51     w.write("</th>");
52     w.write("<th>");
53     w.write(res.getString("UITaskList.header.name"));
54     w.write("</th>");
55     w.write("<th>");
56     w.write(res.getString("UITaskList.header.description"));
57     w.write("</th>");
58     w.write("<th>");
59     w.write(res.getString("UITaskList.header.definition"));
60     w.write("</th>");
61     w.write("<th>");
62     w.write(res.getString("UITaskList.header.started"));
63     w.write("</th>");
64     w.write("<th>");
65     w.write(res.getString("UITaskList.header.manage"));
66     w.write("</th>");
67     if (bps == null)
68       return;
69     if (bps.isEmpty()) {
70       w.write("<tr>");
71       w.write("<td>");
72       w.write("<img SRC='/workflow/images/empty.gif' />");
73       w.write("</td>");
74       w.write("<td colspan='6'>");
75       w.write(res.getString("UITaskList.empty.task.list"));
76       w.write("</td>");
77       w.write("</tr>");
78     } else {
79       Iterator JavaDoc dataIterator = bps.iterator();
80       int i = 0;
81       while (dataIterator.hasNext()) {
82         Token token = (Token) dataIterator.next();
83         Definition def = token.getState().getDefinition();
84         String JavaDoc clazz = "odd";
85         if (i % 2 == 0)
86           clazz = "even";
87         w.write("<tr class='" + clazz + "'>");
88         w.write("<td>");
89         w.write("<img SRC='/workflow/images/activity.gif' />");
90         w.write("</td>");
91         w.write("<td>");
92         w.write(token.getId().toString());
93         w.write("</td>");
94         w.write("<td>");
95         w.write(token.getState().getName());
96         w.write("</td>");
97         String JavaDoc description = token.getState().getDescription();
98         if (description == null)
99           description = "N/A";
100         w.write("<td>");
101         w.write(description);
102         w.write("</td>");
103         w.write("<td>");
104         w.write(def.getName() + " (" + def.getId() + ")");
105         w.write("</td>");
106         w.write("<td>");
107         w.write(new SimpleDateFormat JavaDoc().format(token.getStart()));
108         w.write("</td>");
109         w.write("<td>");
110         Parameter processId = new Parameter("token", token.getId().toString());
111         Parameter[] resolveProcessParams = {MANAGE_STATE, processId};
112         appendLink(w, res.getString("UITaskList.label.manage"), baseURL, resolveProcessParams, null);
113         w.write("</td>");
114         w.write("</tr>");
115         i++;
116       }
117     }
118     w.write("</table>");
119     w.write("</div>");
120   }
121
122 }
Popular Tags