KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > workflow > inbox > Inbox


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.workflow.inbox;
14
15 import info.magnolia.cms.beans.config.MIMEMapping;
16 import info.magnolia.cms.gui.control.ContextMenu;
17 import info.magnolia.cms.gui.control.ContextMenuItem;
18 import info.magnolia.cms.gui.control.FunctionBar;
19 import info.magnolia.cms.gui.control.FunctionBarItem;
20 import info.magnolia.cms.gui.controlx.list.ListColumn;
21 import info.magnolia.cms.gui.controlx.list.ListControl;
22 import info.magnolia.cms.gui.controlx.list.ListModel;
23 import info.magnolia.cms.i18n.Messages;
24 import info.magnolia.cms.i18n.MessagesManager;
25 import info.magnolia.cms.util.AlertUtil;
26 import info.magnolia.cms.util.DateUtil;
27 import info.magnolia.cms.util.FreeMarkerUtil;
28 import info.magnolia.cms.util.NodeDataUtil;
29 import info.magnolia.context.MgnlContext;
30 import info.magnolia.module.admininterface.lists.AbstractList;
31 import info.magnolia.module.admininterface.lists.AdminListControlRenderer;
32 import info.magnolia.module.workflow.WorkflowConstants;
33 import info.magnolia.module.workflow.WorkflowUtil;
34
35 import java.text.ParseException JavaDoc;
36 import java.text.SimpleDateFormat JavaDoc;
37 import java.util.Date JavaDoc;
38
39 import javax.servlet.http.HttpServletRequest JavaDoc;
40 import javax.servlet.http.HttpServletResponse JavaDoc;
41
42 import org.apache.commons.lang.ObjectUtils;
43 import org.apache.commons.lang.StringUtils;
44
45
46 /**
47  * @author Philipp Bracher
48  * @version $Revision:3416 $ ($Author:philipp $)
49  */

50 public class Inbox extends AbstractList {
51
52     /**
53      * The id of the workitem on which we called the command
54      */

55     private String JavaDoc flowItemId;
56
57     /**
58      * The comment the user entered by proceeding or rejecting
59      */

60     private String JavaDoc comment;
61
62     /**
63      * Show all the values of the workitem if true
64      */

65     private boolean debug = false;
66
67     protected Messages msgs = MessagesManager.getMessages("info.magnolia.module.workflow.messages");
68
69     /**
70      * @param name
71      * @param request
72      * @param response
73      */

74     public Inbox(String JavaDoc name, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
75         super(name, request, response);
76     }
77
78     /**
79      * @see info.magnolia.module.admininterface.lists.AbstractList#getModel()
80      */

81     public ListModel getModel() {
82         return new InboxListModel(MgnlContext.getUser().getName());
83     }
84
85     /**
86      * Sets the select js code and defines the columns
87      */

88     public void configureList(ListControl list) {
89
90         // define the select action
91
list.setRenderer(new AdminListControlRenderer() {
92
93             public String JavaDoc onSelect(ListControl list, Integer JavaDoc index) {
94
95                 String JavaDoc customEditDialog = ObjectUtils.toString(list
96                     .getIteratorValue(WorkflowConstants.ATTRIBUTE_EDIT_DIALOG));
97
98                 String JavaDoc editDialog = StringUtils.defaultIfEmpty(customEditDialog, WorkflowConstants.DEFAULT_EDIT_DIALOG);
99                 String JavaDoc repository = ObjectUtils.toString(list.getIteratorValue("repository"));
100                 String JavaDoc path = ObjectUtils.toString(list.getIteratorValue("path"));
101
102                 StringBuffer JavaDoc js = new StringBuffer JavaDoc();
103                 js.append("mgnl.owfe.Inbox.current = {");
104                 js.append("id : '").append(list.getIteratorValue("id")).append("',");
105                 js.append("path : '").append(path).append("',");
106                 js.append("version : '").append(list.getIteratorValue("version")).append("',");
107                 js.append("repository : '").append(repository).append("',");
108                 js.append("workItemPath : '").append(list.getIteratorValue("workItemPath")).append("',");
109                 js.append("editDialog : '").append(editDialog).append("'");
110                 js.append("};");
111                 js.append("mgnl.owfe.Inbox.show = ").append(getShowJSFunction(repository, path)).append(";");
112                 js.append(super.onSelect(list, index));
113                 return js.toString();
114             }
115
116             public String JavaDoc onDblClick(ListControl list, Integer JavaDoc index) {
117                 return "mgnl.owfe.Inbox.edit();";
118             }
119         });
120
121         list.addSortableField("lastModified");
122         list.addGroupableField("repository");
123         list.addGroupableField("workflow");
124
125         list.addColumn(new ListColumn() {
126
127             {
128                 setName("icon");
129                 setLabel("");
130                 setWidth("25px");
131                 setSeparator(false);
132             }
133
134             public Object JavaDoc getValue() {
135                 String JavaDoc path = "" + this.getListControl().getIteratorValue("path");
136                 String JavaDoc repository = "" + this.getListControl().getIteratorValue("repository");
137                 return "<img SRC=\""
138                     + MgnlContext.getContextPath()
139                     + "/"
140                     + getIcon(repository, path)
141                     + "\" alt=\"\" border=\"0\" />";
142             }
143         });
144         list.addColumn(new ListColumn("name", msgs.get("inbox.item"), "100px", true));
145         list.addColumn(new ListColumn("repository", msgs.get("inbox.repository"), "100", true));
146         list.addColumn(new ListColumn("workflow", msgs.get("inbox.workflow"), "100", true));
147         list.addColumn(new ListColumn("comment", msgs.get("inbox.comment"), "200", true));
148         list.addColumn(new ListColumn() {
149
150             {
151                 setName("lastModified");
152                 setLabel(msgs.get("inbox.date"));
153                 setWidth("100");
154             }
155
156             public Object JavaDoc getValue() {
157                 String JavaDoc str = (String JavaDoc) super.getValue();
158                 Date JavaDoc date = null;
159                 try {
160                     date = new SimpleDateFormat JavaDoc("yyyy-MM-dd HH:mm:ssZ").parse(str);
161                     return DateUtil.formatDateTime(date);
162
163                 }
164                 catch (ParseException JavaDoc e) {
165                     return StringUtils.EMPTY;
166                 }
167             }
168         });
169
170     }
171
172     protected String JavaDoc getIcon(String JavaDoc repository, String JavaDoc path) {
173         if (StringUtils.equals(repository, "website")) {
174             return ".resources/icons/16/document_plain_earth.gif";
175         }
176         if (StringUtils.equals(repository, "dms")) {
177             String JavaDoc type = NodeDataUtil.getString(repository, path + "/type");
178             return MIMEMapping.getMIMETypeIcon(type);
179         }
180
181         return ".resources/icons/16/mail.gif";
182     }
183
184     protected String JavaDoc getShowJSFunction(String JavaDoc repository, String JavaDoc path) {
185         return "mgnl.owfe.Inbox.showFunctions." + repository;
186     }
187
188     /**
189      * @see info.magnolia.module.admininterface.lists.AbstractList#getContextMenu()
190      */

191     public void configureContextMenu(ContextMenu menu) {
192         ContextMenuItem edit = new ContextMenuItem("edit");
193         edit.setLabel(msgs.get("inbox.edit"));
194         edit.setOnclick("mgnl.owfe.Inbox.edit();");
195         edit.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/mail_write.gif");
196         edit.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}");
197
198         ContextMenuItem show = new ContextMenuItem("show");
199         show.setLabel(msgs.get("inbox.show"));
200         show.setOnclick("mgnl.owfe.Inbox.show();");
201         show.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/note_view.gif");
202         show.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}");
203
204         ContextMenuItem proceed = new ContextMenuItem("proceed");
205         proceed.setLabel(msgs.get("inbox.proceed"));
206         proceed.setOnclick("mgnl.owfe.Inbox.proceed();");
207         proceed.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/navigate_right2_green.gif");
208         proceed.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}");
209
210         ContextMenuItem reject = new ContextMenuItem("reject");
211         reject.setLabel(msgs.get("inbox.reject"));
212         reject.setOnclick("mgnl.owfe.Inbox.reject();");
213         reject.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/navigate_left2_red.gif");
214         reject.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}");
215
216         ContextMenuItem cancel = new ContextMenuItem("cancel");
217         cancel.setLabel(msgs.get("inbox.cancel"));
218         cancel.setOnclick("mgnl.owfe.Inbox.cancel();");
219         cancel.setIcon(MgnlContext.getContextPath() + "/.resources/icons/16/delete2.gif");
220         cancel.addJavascriptCondition("{test: function(){return mgnl.owfe.Inbox.current.id!=null}}");
221
222         menu.addMenuItem(edit);
223         menu.addMenuItem(null);
224         menu.addMenuItem(show);
225         menu.addMenuItem(null);
226         menu.addMenuItem(proceed);
227         menu.addMenuItem(reject);
228         menu.addMenuItem(null);
229         menu.addMenuItem(cancel);
230     }
231
232     /**
233      * Same as the context menu
234      */

235     public void configureFunctionBar(FunctionBar bar) {
236         ContextMenu menu = this.getContextMenu();
237         bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("edit")));
238         bar.addMenuItem(null);
239         bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("show")));
240         bar.addMenuItem(null);
241         bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("reject")));
242         bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("proceed")));
243         bar.addMenuItem(null);
244         bar.addMenuItem(new FunctionBarItem(menu.getMenuItemByName("cancel")));
245     }
246
247     /**
248      * Add some inbox specific stuff: mainly hidden fields.
249      */

250     public String JavaDoc onRender() {
251         return FreeMarkerUtil.process(this);
252     }
253
254     /**
255      * Proceed the item
256      */

257     public String JavaDoc proceed() {
258         try {
259             WorkflowUtil.proceed(this.getFlowItemId(), WorkflowConstants.ACTION_PROCEED);
260         }
261         catch (Exception JavaDoc e) {
262             AlertUtil.setMessage("can't proceed:", e);
263         }
264         return this.show();
265     }
266
267     /**
268      * Reject the item (adds a comment)
269      */

270     public String JavaDoc reject() {
271         try {
272             WorkflowUtil.proceed(this.getFlowItemId(), WorkflowConstants.ACTION_REJECT, this.getComment());
273         }
274         catch (Exception JavaDoc e) {
275             AlertUtil.setMessage("can't reject:", e);
276         }
277         return this.show();
278     }
279
280     /**
281      * Stop the workflow.
282      */

283     public String JavaDoc cancel() {
284         try {
285             WorkflowUtil.proceed(this.getFlowItemId(), WorkflowConstants.ACTION_CANCEL);
286         }
287         catch (Exception JavaDoc e) {
288             AlertUtil.setMessage("can't cancel:", e);
289         }
290         return this.show();
291     }
292
293     /**
294      * @return Returns the flowItemId.
295      */

296     public String JavaDoc getFlowItemId() {
297         return this.flowItemId;
298     }
299
300     /**
301      * @param flowItemId The flowItemId to set.
302      */

303     public void setFlowItemId(String JavaDoc flowItemId) {
304         this.flowItemId = flowItemId;
305     }
306
307     /**
308      * @return Returns the comment.
309      */

310     public String JavaDoc getComment() {
311         return this.comment;
312     }
313
314     /**
315      * @param comment The comment to set.
316      */

317     public void setComment(String JavaDoc comment) {
318         this.comment = comment;
319     }
320
321     /**
322      * @return Returns the debug.
323      */

324     public boolean isDebug() {
325         return this.debug;
326     }
327
328     /**
329      * @param debug The debug to set.
330      */

331     public void setDebug(boolean debug) {
332         this.debug = debug;
333     }
334
335 }
336
Popular Tags