001: /*
002: * $Id$
003: * (c) Copyright 2004 - 2007 osbl development team.
004: *
005: * This file is part of the osbl (http://osbl.wilken.de).
006: *
007: * the osbl is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2.1
010: * of the License, or (at your option) any later version.
011: *
012: * Please see COPYING for the complete licence.
013: */
014: package org.osbl.client.wings.concern;
015:
016: import org.concern.*;
017: import org.osbl.client.action.ActionRegistry;
018: import org.osbl.client.wings.shell.Client;
019: import org.osbl.client.wings.action.NavigationAction;
020: import org.osbl.client.wings.XIcons;
021: import org.osbl.client.wings.XOptionPane;
022: import org.wings.*;
023: import org.wings.io.StringBuilderDevice;
024: import org.wings.plaf.css.Utils;
025: import org.wings.session.SessionManager;
026: import org.wingx.XDivision;
027:
028: import javax.swing.*;
029: import javax.swing.event.ListSelectionEvent;
030: import javax.swing.event.ListSelectionListener;
031: import java.awt.event.ActionEvent;
032: import java.io.IOException;
033: import java.util.*;
034:
035: /**
036: * @author hengels
037: * @version $Revision: 1.2 $
038: */
039: public class Overview extends SPanel {
040: private ListSelectionListener subjectListener = new ListSelectionListener() {
041: public void valueChanged(ListSelectionEvent event) {
042: Subject subject = (Subject) subjectsList.getSelectedValue();
043: if (subject == null)
044: return;
045:
046: Controller controller = ControllerLookup.getInstance()
047: .getController(subject.getProcess());
048: if (controller == null) {
049: XOptionPane
050: .showMessageDialog(
051: Overview.this ,
052: Client
053: .getInstance()
054: .getResourceProvider()
055: .getMessage(
056: "org.concern.model.Process.messages.notDeployed",
057: subject.getProcess()));
058: return;
059: }
060:
061: try {
062: Set options = new TreeSet(controller.getOptions(subject
063: .getSubjectId()));
064: subject.setOptions(options);
065: } catch (UnknownSubjectException e) {
066: e.printStackTrace();
067: }
068: subjectAction.navigate(subject);
069: subjectsList.clearSelection();
070: }
071: };
072:
073: private ListSelectionListener taskListener = new ListSelectionListener() {
074: public void valueChanged(ListSelectionEvent e) {
075: Work task = (Work) tasksList.getSelectedValue();
076: if (task == null)
077: return;
078:
079: Controller controller = ControllerLookup.getInstance()
080: .getController(task.getProcess());
081: if (controller == null) {
082: XOptionPane
083: .showMessageDialog(
084: Overview.this ,
085: Client
086: .getInstance()
087: .getResourceProvider()
088: .getMessage(
089: "org.concern.model.Process.messages.notDeployed",
090: task.getProcess()));
091: return;
092: }
093:
094: taskAction.navigate(task);
095: tasksList.clearSelection();
096: }
097: };
098: private StringBuilderDevice device = new StringBuilderDevice();
099: private XDivision subjectsDivision = new XDivision(
100: new SGridLayout());
101: private XDivision tasksDivision = new XDivision(new SGridLayout());
102: private SList subjectsList = new SList();
103: private SList tasksList = new SList();
104: private SButton tasksButton;
105: private SButton subjectsButton;
106: private NavigationAction subjectAction = (NavigationAction) ActionRegistry
107: .getAction("org.concern.actions.ownSubjects");
108: private NavigationAction taskAction = (NavigationAction) ActionRegistry
109: .getAction("org.concern.actions.tasks");
110:
111: public Overview() {
112: super (new SGridLayout(1, 1, 8, 8));
113: setAttribute("overflow", "hidden");
114: setPreferredSize(SDimension.FULLWIDTH);
115:
116: subjectsList.setShowAsFormComponent(false);
117: subjectsList.setHorizontalAlignment(SConstants.LEFT_ALIGN);
118: subjectsList.setModel(new SubjectListModel());
119: subjectsList.addListSelectionListener(subjectListener);
120: subjectsList.setCellRenderer(new SDefaultListCellRenderer() {
121: public SComponent getListCellRendererComponent(
122: SComponent list, Object value, boolean selected,
123: int row) {
124: value = formatSubject((Subject) value);
125: return super .getListCellRendererComponent(list, value,
126: selected, row);
127: }
128: });
129: subjectsDivision.setTitle(Client.getInstance()
130: .getResourceProvider().getMessage(
131: "org.concern.titles.mySubjects"));
132: subjectsDivision.setPreferredSize(SDimension.FULLWIDTH);
133: subjectsDivision.add(subjectsList);
134: add(subjectsDivision);
135: subjectsButton = new SButton("...");
136: subjectsButton.setStyle("borderless");
137: subjectsButton.setHorizontalAlignment(SConstants.LEFT_ALIGN);
138: subjectsButton.addActionListener(subjectAction);
139: subjectsDivision.add(subjectsButton);
140: subjectsDivision.add(new SLabel("<html> "));
141:
142: tasksList.setShowAsFormComponent(false);
143: tasksList.setHorizontalAlignment(SConstants.LEFT_ALIGN);
144: tasksList.setModel(new TaskListModel());
145: tasksList.addListSelectionListener(taskListener);
146: tasksList.setCellRenderer(new SDefaultListCellRenderer() {
147: public SComponent getListCellRendererComponent(
148: SComponent list, Object value, boolean selected,
149: int row) {
150: value = formatTask((Work) value);
151: return super .getListCellRendererComponent(list, value,
152: selected, row);
153: }
154: });
155: tasksDivision.setTitle(Client.getInstance()
156: .getResourceProvider().getMessage(
157: "org.concern.titles.myTasks"));
158: tasksDivision.setPreferredSize(SDimension.FULLWIDTH);
159: tasksDivision.add(tasksList);
160: add(tasksDivision);
161: tasksButton = new SButton("...");
162: tasksButton.setStyle("borderless");
163: tasksButton.setHorizontalAlignment(SConstants.LEFT_ALIGN);
164: tasksButton.addActionListener(taskAction);
165: tasksDivision.add(tasksButton);
166: tasksDivision.add(new SLabel("<html> "));
167:
168: add(new SLabel("<html> "));
169: SButton button = new SButton(new RefreshAction());
170: button.setStyle("borderless");
171: add(button);
172:
173: refresh();
174: }
175:
176: public void refresh() {
177: SubjectListModel subjectListModel = (SubjectListModel) subjectsList
178: .getModel();
179: subjectListModel.refresh();
180: subjectsButton.setText(subjectListModel.getSize() == 0 ? Client
181: .getInstance().getResourceProvider().getMessage(
182: "org.concern.Subject.messages.noOpenSubjects")
183: : "...");
184:
185: TaskListModel taskListModel = (TaskListModel) tasksList
186: .getModel();
187: taskListModel.refresh();
188: tasksButton.setText(taskListModel.getSize() == 0 ? Client
189: .getInstance().getResourceProvider().getMessage(
190: "org.concern.Work.messages.noOpenTasks")
191: : "...");
192: }
193:
194: private String formatSubject(Subject subject) {
195: try {
196: device.reset();
197: device.print("<html><b style=\"color: #333333\">");
198: Utils.writeQuoted(device, Client.getInstance()
199: .getResourceProvider().getMessage(
200: "process." + subject.getProcess()), true);
201: device.print("</b><br/>");
202: device.print(subject.getSubjectLine());
203: return device.toString();
204: } catch (IOException e) {
205: throw new RuntimeException(e);
206: }
207: }
208:
209: private String formatTask(Work work) {
210: try {
211: device.reset();
212: device.print("<html><b style=\"color: #333333\">");
213: Utils.writeQuoted(device, Client.getInstance()
214: .getResourceProvider().getMessage(
215: "process." + work.getProcess() + "."
216: + work.getActivity()), true);
217: device.print("</b><br/>");
218: device.print(work.getSubjectLine());
219: return device.toString();
220: } catch (IOException e) {
221: throw new RuntimeException(e);
222: }
223: }
224:
225: class SubjectListModel extends SDefaultListModel {
226: public void refresh() {
227: String user = SessionManager.getSession()
228: .getServletRequest().getUserPrincipal().getName();
229: Locale locale = SessionManager.getSession().getLocale();
230: String language = locale.toString();
231: Worklist worklist = ControllerLookup.getInstance()
232: .getWorklist();
233:
234: data.clear();
235: List subjects = worklist.listSubjects(null, null, null,
236: new String[] { user }, 0,
237: new String[] { "-subject.created" }, language, 5);
238: if (subjects.size() > 5)
239: subjects = subjects.subList(0, 5);
240: data.addAll(subjects);
241:
242: fireContentsChanged(this , 0, subjects.size());
243: }
244: }
245:
246: class TaskListModel extends SDefaultListModel {
247: public void refresh() {
248: String user = SessionManager.getSession()
249: .getServletRequest().getUserPrincipal().getName();
250: Locale locale = SessionManager.getSession().getLocale();
251: String language = locale.toString();
252: Worklist worklist = ControllerLookup.getInstance()
253: .getWorklist();
254:
255: data.clear();
256: List tasks = worklist.listWork(new String[] { user }, null,
257: null, null, new String[] { "-enlistment.timeout" },
258: language, 5);
259: if (tasks.size() > 5)
260: tasks = tasks.subList(0, 5);
261: data.addAll(tasks);
262:
263: fireContentsChanged(this , 0, tasks.size());
264: }
265: }
266:
267: private class RefreshAction extends AbstractAction {
268: public RefreshAction() {
269: putValue(Action.SHORT_DESCRIPTION, "Refresh");
270: putValue(Action.SMALL_ICON, XIcons.REFRESH);
271: }
272:
273: public void actionPerformed(ActionEvent e) {
274: refresh();
275: }
276: }
277: }
|