KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > task > View


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

25
26 package net.killingar.forum.actions.task;
27
28 import it.unimi.dsi.fastutil.longs.LongArrayList;
29 import net.killingar.forum.internal.Task;
30
31 import java.sql.Timestamp JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35
36 public class View extends ActionTaskSupport
37 {
38     // Private --------------------------------------------------------
39

40     // Attributes -----------------------------------------------------
41
long time = -1;
42     List myTasks = new ArrayList();
43     List freeTasks = new ArrayList();
44     List tasksInProgress = new ArrayList();
45
46     public List getMyTasks() { return myTasks; }
47     public List getFreeTasks() { return freeTasks; }
48     public List getTasksInProgress() { return tasksInProgress; }
49
50   public void setTime(long inTime) { time = inTime; }
51
52     // Types ----------------------------------------------------------
53
class TaskInfo extends Task
54     {
55         TaskInfo(Task inTask, boolean inUnread)
56         {
57             super(inTask);
58             unread = inUnread;
59         }
60
61         public boolean getUnread() { return unread; }
62
63         boolean unread;
64     }
65
66     class TaskInProgress extends TaskInfo
67     {
68         TaskInProgress(Task inTask, boolean inUnread, LongArrayList inVolunteers)
69         {
70             super(inTask, inUnread);
71             volunteers = inVolunteers;
72         }
73
74         LongArrayList volunteers;
75
76         public LongArrayList getVolunteers() { return volunteers; }
77     }
78
79     // Setters --------------------------------------------------------
80

81     // Getters --------------------------------------------------------
82

83     // Implementation -------------------------------------------------
84
protected String JavaDoc doExecute()
85     {
86         try
87         {
88             Timestamp JavaDoc time = this.time != -1? new Timestamp JavaDoc(this.time): taskMgr.getTime();
89
90             for (Iterator JavaDoc it = taskMgr.getTasks().iterator(); it.hasNext();)
91             {
92                 Task i = (Task)it.next();
93
94                 LongArrayList volunteers = taskMgr.getVolunteers(i.getId());
95                 if (volunteers.size() == 0)
96                     freeTasks.add(new TaskInfo(i, i.lastChanged.after(time)));
97                 else if (volunteers.getLong(0) == manager.getUserID())
98                     myTasks.add(new TaskInfo(i, i.lastChanged.after(time)));
99                 else
100                     tasksInProgress.add(new TaskInProgress(i, i.lastChanged.after(time), volunteers));
101             }
102
103             taskMgr.setRead();
104         }
105         catch (Exception JavaDoc e)
106         {
107             e.printStackTrace();
108             addErrorMessage("executing "+getClass().toString()+" action failed, exception thrown: "+e.toString());
109             return ERROR;
110         }
111
112         return SUCCESS;
113     }
114 }
115
Popular Tags