001: package com.sun.portal.app.sharedtasks.faces.beans;
002:
003: import com.sun.portal.app.sharedtasks.faces.models.TaskListModel;
004: import com.sun.portal.app.sharedtasks.util.CalTaskListItem;
005: import com.sun.portal.app.sharedtasks.util.SharedTaskException;
006: import com.sun.portal.app.sharedtasks.util.SharedConstants;
007: import com.sun.portal.app.sharedtasks.util.TaskBeanFactory;
008:
009: import com.sun.data.provider.impl.ObjectArrayDataProvider;
010: import com.sun.web.ui.model.Option;
011:
012: import com.sun.comclient.calendar.DateTime;
013:
014: import javax.faces.context.FacesContext;
015:
016: import java.util.Map;
017: import java.util.Calendar;
018: import java.util.ResourceBundle;
019: import java.util.Locale;
020: import java.text.SimpleDateFormat;
021:
022: import com.sun.portal.log.common.PortalLogger;
023: import java.util.logging.Logger;
024: import java.util.logging.Level;
025:
026: /**
027: * Container class for the task list table.
028: *
029: * @author ashwin.mathew@sun.com
030: */
031: public class TaskTableContainer {
032:
033: private TaskListModel model;
034:
035: private TaskTableActions actions;
036:
037: private TaskTableSelect select;
038:
039: private String message;
040:
041: private TaskListSessionBackingBean listSession;
042: private TaskUserSessionBackingBean userSession;
043:
044: private TaskListBackingBean parent;
045:
046: private static Logger logger = PortalLogger
047: .getLogger(TaskTableContainer.class);
048:
049: private static final String VIEW_CONTEXT_DATE_HYPHEN = " - ";
050: private static final String VIEW_CONTEXT_DATE_COMMA = ", ";
051:
052: public TaskTableContainer(TaskListBackingBean parent) {
053: this .parent = parent;
054:
055: listSession = (TaskListSessionBackingBean) TaskBeanFactory
056: .getBean(TaskListSessionBackingBean.BEAN_NAME);
057:
058: userSession = (TaskUserSessionBackingBean) TaskBeanFactory
059: .getBean(TaskUserSessionBackingBean.BEAN_NAME);
060:
061: model = new TaskListModel(listSession, userSession);
062: actions = new TaskTableActions(userSession, this );
063: select = new TaskTableSelect(this );
064: }
065:
066: public TaskListBackingBean getParent() {
067: return parent;
068: }
069:
070: public String getMessage() {
071: return message;
072: }
073:
074: public void setMessage(String message) {
075: this .message = message;
076: }
077:
078: public void setRefreshData() {
079: listSession.setDataProvider(null);
080: }
081:
082: public TaskListModel getModel() {
083: return model;
084: }
085:
086: public void setModel(TaskListModel model) {
087: this .model = model;
088: }
089:
090: public TaskTableActions getActions() {
091: return actions;
092: }
093:
094: public ObjectArrayDataProvider getDataProvider() {
095: if (logger.isLoggable(Level.FINEST)) {
096: logger.finest("Entered getDataProvider()");
097: }
098:
099: if (listSession.getDataProvider() == null) {
100: if (logger.isLoggable(Level.FINEST)) {
101: logger.finest("Retrieving tasks");
102: }
103:
104: try {
105: CalTaskListItem[] tasks = model.retrieve();
106:
107: listSession
108: .setDataProvider(new ObjectArrayDataProvider(
109: tasks));
110: } catch (SharedTaskException se) {
111: logger.log(Level.SEVERE, "Error retrieving tasks", se);
112: parent.setException(se);
113: }
114: }
115:
116: return listSession.getDataProvider();
117: }
118:
119: public TaskTableSelect getSelect() {
120: return select;
121: }
122:
123: public String getViewContextDate() {
124: StringBuffer viewContextDate = new StringBuffer();
125:
126: ResourceBundle bundle = userSession.getResourceBundle();
127: Locale cLocale = userSession.getLocale();
128:
129: if (listSession.getViewContext().equals(
130: SharedConstants.VIEW_CTX_DAY)) {
131: String DayFormat = bundle
132: .getString(SharedConstants.KEY_DAY_FORMAT);
133: viewContextDate.append(bundle
134: .getString(SharedConstants.KEY_VIEW_DAY));
135: SimpleDateFormat formatter = new SimpleDateFormat(
136: DayFormat, cLocale);
137: viewContextDate.append(formatter.format(listSession
138: .getViewDateTime().getTime()));
139: } else if (listSession.getViewContext().equals(
140: SharedConstants.VIEW_CTX_WEEK)) {
141: String WeekFormat = bundle
142: .getString(SharedConstants.KEY_WEEK_FORMAT);
143: viewContextDate.append(bundle
144: .getString(SharedConstants.KEY_VIEW_WEEK));
145:
146: SimpleDateFormat formatter = new SimpleDateFormat(
147: WeekFormat, cLocale);
148:
149: DateTime contextStartDate = listSession
150: .getContextStartDateTime();
151:
152: viewContextDate.append(formatter.format(contextStartDate
153: .getTime()));
154: viewContextDate.append(VIEW_CONTEXT_DATE_HYPHEN);
155:
156: DateTime contextEndDate = listSession
157: .getContextEndDateTime();
158:
159: viewContextDate.append(formatter.format(contextEndDate
160: .getTime()));
161: viewContextDate.append(VIEW_CONTEXT_DATE_COMMA).append(
162: listSession.getViewDateTime().getYear());
163: } else if (listSession.getViewContext().equals(
164: SharedConstants.VIEW_CTX_MONTH)) {
165: String MonthFormat = bundle
166: .getString(SharedConstants.KEY_MONTH_FORMAT);
167: viewContextDate.append(bundle
168: .getString(SharedConstants.KEY_VIEW_MONTH));
169: SimpleDateFormat formatter = new SimpleDateFormat(
170: MonthFormat, cLocale);
171: viewContextDate.append(formatter.format(listSession
172: .getViewDateTime().getTime()));
173: }
174:
175: return viewContextDate.toString();
176: }
177:
178: public void goNextViewContext() {
179: setRefreshData();
180:
181: if (listSession.getViewContext().equals(
182: SharedConstants.VIEW_CTX_DAY)) {
183: listSession.getViewDateTime().add(Calendar.DAY_OF_MONTH, 1);
184: } else if (listSession.getViewContext().equals(
185: SharedConstants.VIEW_CTX_WEEK)) {
186: listSession.getViewDateTime().add(Calendar.WEEK_OF_YEAR, 1);
187: } else if (listSession.getViewContext().equals(
188: SharedConstants.VIEW_CTX_MONTH)) {
189: listSession.getViewDateTime().add(Calendar.MONTH, 1);
190: }
191: }
192:
193: public void goPreviousViewContext() {
194: setRefreshData();
195:
196: if (listSession.getViewContext().equals(
197: SharedConstants.VIEW_CTX_DAY)) {
198: listSession.getViewDateTime()
199: .add(Calendar.DAY_OF_MONTH, -1);
200: } else if (listSession.getViewContext().equals(
201: SharedConstants.VIEW_CTX_WEEK)) {
202: listSession.getViewDateTime()
203: .add(Calendar.WEEK_OF_YEAR, -1);
204: } else if (listSession.getViewContext().equals(
205: SharedConstants.VIEW_CTX_MONTH)) {
206: listSession.getViewDateTime().add(Calendar.MONTH, -1);
207: }
208: }
209:
210: public Option[] getFilterOptions() {
211: ResourceBundle bundle = userSession.getResourceBundle();
212:
213: Option[] filterOptions = {
214: new Option(
215: SharedConstants.FILTER_ALL_TASKS,
216: bundle
217: .getString(SharedConstants.KEY_FILTER_ALL_TASKS)),
218: new Option(
219: SharedConstants.FILTER_INCOMPLETE_TASKS,
220: bundle
221: .getString(SharedConstants.KEY_FILTER_INCOMPLETE_TASKS)),
222: new Option(
223: SharedConstants.FILTER_COMPLETED_TASKS,
224: bundle
225: .getString(SharedConstants.KEY_FILTER_COMPLETED_TASKS)) };
226:
227: return filterOptions;
228: }
229:
230: public String getFilterText() {
231: String filter = listSession.getStatusFilter();
232:
233: return filter;
234: }
235:
236: public TaskListSessionBackingBean getListSession() {
237: return listSession;
238: }
239:
240: public void applyFilter() {
241: setRefreshData();
242: }
243:
244: }
|