001: /*
002: * EventsTableNavigation.java
003: *
004: * Created on May 16, 2005, 2:47 PM
005: *
006: *
007: */
008:
009: package com.sun.portal.app.sharedevents.faces;
010:
011: import com.sun.comclient.calendar.DateTime;
012: import com.sun.portal.app.sharedevents.util.AppUtils;
013: import com.sun.portal.app.sharedevents.util.CalUserHelper;
014: import com.sun.portal.app.sharedevents.util.SharedConstants;
015: import com.sun.portal.log.common.PortalLogger;
016: import java.text.DateFormat;
017: import java.util.ResourceBundle;
018: import java.util.TimeZone;
019: import java.util.logging.Level;
020: import java.util.logging.Logger;
021: import javax.faces.event.ActionEvent;
022:
023: /**
024: * This class provides functionality for Table Navigation
025: * (Traversing to previous and next view contexts (Day/Week/Month)
026: * @author SaiSatish Vedam
027: */
028: public class EventsTableNavigation {
029:
030: private EventsTableContainer tableContainer = null;
031: private String CLASS_NAME = "EventsTableNavigation";
032: private String displayViewContextDuration = null;
033: private String displayViewContext = null;
034: private String viewCtx = null;
035: private String viewCtxStart = null;
036: private DateTime startDt = null;
037: private DateTime endDt = null;
038: private ResourceBundle bundle = null;
039: private boolean rollViewContextToPrev = false;
040: private boolean rollViewContextToNext = false;
041:
042: //These are the request parameter names passed from the JSP
043: private String CURR_VIEW_CTX_PARAM = "currViewCtx";
044: private String VIEW_CTX_START_PARAM = "currViewCtxStart";
045:
046: private boolean renderUIElement = true;
047:
048: private static Logger logger = PortalLogger
049: .getLogger(EventsTableNavigation.class);
050:
051: /** Creates a new instance of EventsTableNavigation */
052: public EventsTableNavigation(EventsTableContainer container) {
053: logger.entering(CLASS_NAME, "EventsTablePreferences()");
054: tableContainer = container;
055: if (bundle == null) {
056: bundle = getResourceBundle();
057: }
058: logger.exiting(CLASS_NAME, "EventsTablePreferences()");
059:
060: }
061:
062: /*
063: * This method is invoked by the caller (EventsTableContainer) to the view context
064: * (Day/Week/Month) being displayed.
065: * This information will be used to show the displayable view context
066: */
067: public void setViewContext(String ctx) {
068: viewCtx = ctx;
069:
070: }
071:
072: /*
073: * This is used as value binding to set whether the UI element needs to be rendered
074: * or not. This could be the case when Search is invoked.
075: */
076:
077: public boolean getRenderComponent() {
078: /*
079: if (tableContainer.isSearchInvoked()) {
080: renderUIElement = false;
081: }
082: */
083: String viewCtx = (String) AppUtils
084: .getSessionAttribute(SharedConstants.SESSION_CURR_VIEW_CTX);
085:
086: if (viewCtx != null
087: && viewCtx
088: .equalsIgnoreCase(SharedConstants.VIEW_CTX_SEARCH)) {
089: renderUIElement = false;
090: } else {
091: renderUIElement = true;
092: }
093: return renderUIElement;
094: }
095:
096: /*
097: * This method is invoked by the caller (EventsTableContainer) to the view context
098: * Start date (in ISO format)(Day/Week/Month) being displayed.
099: * This information will be used for navigation
100:
101: public void setViewContextStart(String ctxSt) {
102: System.out.println(CLASS_NAME + "ENTERING: " + "setViewContextStart()");
103: viewCtxStart = ctxSt;
104: System.out.println(CLASS_NAME + "EXITING: " + "setViewContextStart()");
105:
106: }
107: */
108:
109: /*
110: * This method is invoked by the caller (EventsTableContainer) to set the view context
111: * Start date. This will be used to construct display view context duration
112: */
113: public void setViewContextStartDt(DateTime dt) {
114: startDt = dt;
115:
116: }
117:
118: /*
119: * This method is invoked by the caller (EventsTableContainer) to set the view context
120: * End date. This will be used to construct display view context duration
121: */
122: public void setViewContextEndDt(DateTime dt) {
123: endDt = dt;
124:
125: }
126:
127: /*
128: * This is the value binding for the view context parameter in the JSP
129: */
130:
131: public String getDisplayViewContext() {
132: //String viewCtx = null;
133: viewCtx = (String) AppUtils
134: .getSessionAttribute(SharedConstants.SESSION_CURR_VIEW_CTX);
135: if (viewCtx != null && viewCtx.length() > 0) {
136:
137: } else {
138: viewCtx = SharedConstants.VIEW_CTX_DAY;
139: }
140:
141: if (viewCtx.equalsIgnoreCase(SharedConstants.VIEW_CTX_DAY)) {
142: displayViewContext = bundle
143: .getString("displayViewContextDay");
144:
145: }
146: if (viewCtx.equalsIgnoreCase(SharedConstants.VIEW_CTX_WEEK)) {
147: displayViewContext = bundle
148: .getString("displayViewContextWeek");
149:
150: }
151: if (viewCtx.equalsIgnoreCase(SharedConstants.VIEW_CTX_MONTH)) {
152: displayViewContext = bundle
153: .getString("displayViewContextMonth");
154:
155: }
156:
157: return displayViewContext;
158:
159: }
160:
161: /*
162: * This is the value binding for context duration in JSP
163: */
164: public String getDisplayViewContextDuration() {
165:
166: viewCtx = (String) AppUtils
167: .getSessionAttribute(SharedConstants.SESSION_CURR_VIEW_CTX);
168: String isoStDt = (String) AppUtils
169: .getSessionAttribute(SharedConstants.SESSION_CURR_VIEW_CTX_START);
170: String isoEdDt = (String) AppUtils
171: .getSessionAttribute(SharedConstants.SESSION_CURR_VIEW_CTX_END);
172:
173: if (isoStDt != null && isoStDt.length() > 0) {
174: startDt = CalUserHelper.getDateTimeFromISOString(isoStDt);
175: } else {
176: startDt = CalUserHelper.getToday();
177: }
178:
179: if (isoEdDt != null && isoEdDt.length() > 0) {
180: endDt = CalUserHelper.getDateTimeFromISOString(isoEdDt);
181: } else {
182: endDt = CalUserHelper.getToday();
183: }
184:
185: displayViewContextDuration = null;
186: if (viewCtx.equalsIgnoreCase(SharedConstants.VIEW_CTX_DAY)) {
187: if (startDt != null) {
188: displayViewContextDuration = AppUtils
189: .getLocaleDatePerPattern(
190: startDt,
191: bundle
192: .getString("dayContextDurationPattern"),
193: DateFormat.FULL);
194: }
195:
196: }
197: if (viewCtx.equalsIgnoreCase(SharedConstants.VIEW_CTX_WEEK)) {
198: String start = null;
199: if (startDt != null) {
200: start = AppUtils
201: .getLocaleDatePerPattern(
202: startDt,
203: bundle
204: .getString("weekContextDurationPattern1"),
205: DateFormat.LONG);
206: }
207:
208: String end = null;
209:
210: if (endDt != null) {
211: end = AppUtils.getLocaleDatePerPattern(endDt, bundle
212: .getString("weekContextDurationPattern2"),
213: DateFormat.LONG);
214: }
215:
216: if (start != null && end != null) {
217: displayViewContextDuration = start + " - " + end;
218: }
219:
220: }
221: if (viewCtx.equalsIgnoreCase(SharedConstants.VIEW_CTX_MONTH)) {
222:
223: if (startDt != null) {
224: displayViewContextDuration = AppUtils
225: .getLocaleDatePerPattern(
226: startDt,
227: bundle
228: .getString("monthContextDurationPattern"),
229: DateFormat.LONG);
230: }
231: }
232:
233: return displayViewContextDuration;
234:
235: }
236:
237: /**
238: * Action Listener for handling Navigation icons on the table
239: */
240: public void handlePrevContext(ActionEvent e) {
241: logger.entering(CLASS_NAME, "handlePrevContext()");
242: String currViewCtx = null;
243: String viewCtxStart = null;
244:
245: // As the Table Container to fetch new data based on the view context information
246: /*
247: tableContainer.setNavigationInvoked(true);
248: tableContainer.rollViewContextToPrev(true);
249: tableContainer.constructContextStartAndEndDates();
250: */
251: rollViewContextToPrev = true;
252: setContextStartAndEndDates();
253: AppUtils.setAttributeInSession(
254: SharedConstants.SESSION_REFRESH_DATA, "true");
255:
256: logger.exiting(CLASS_NAME, "handlePrevContext()");
257:
258: }
259:
260: /**
261: * Action Listener for handling Navigation icons on the table
262: */
263: public void handleNextContext(ActionEvent e) {
264: logger.entering(CLASS_NAME, "handleNextContext()");
265: String currViewCtx = null;
266: String viewCtxStart = null;
267:
268: // As the Table Container to fetch new data based on the view context information
269: /*
270: tableContainer.setNavigationInvoked(true);
271: tableContainer.rollViewContextToNext(true);
272: tableContainer.constructContextStartAndEndDates();
273: */
274: rollViewContextToNext = true;
275: setContextStartAndEndDates();
276: AppUtils.setAttributeInSession(
277: SharedConstants.SESSION_REFRESH_DATA, "true");
278:
279: logger.exiting(CLASS_NAME, "handleNextContext()");
280: }
281:
282: private ResourceBundle getResourceBundle() {
283: return AppUtils.getResourceBundle();
284: }
285:
286: private void setContextStartAndEndDates() {
287:
288: logger.entering(CLASS_NAME, "setContextStartAndEndDates()");
289: String oldViewCtxStart = null;
290: oldViewCtxStart = (String) AppUtils
291: .getSessionAttribute(SharedConstants.SESSION_CURR_VIEW_CTX_START);
292:
293: DateTime startDate = null;
294: if (oldViewCtxStart != null && oldViewCtxStart.length() > 0) {
295: if (logger.isLoggable(Level.FINE)) {
296: logger.log(Level.FINE, "oldViewCtxStart: "
297: + oldViewCtxStart);
298: }
299: startDate = CalUserHelper
300: .getDateTimeFromISOString(oldViewCtxStart);
301: } else {
302: if (logger.isLoggable(Level.FINE)) {
303: logger.log(Level.FINE, "oldViewCtxStart: "
304: + oldViewCtxStart);
305: }
306: startDate = CalUserHelper.getToday();
307:
308: }
309:
310: String viewContext = null;
311: viewContext = (String) AppUtils
312: .getSessionAttribute(SharedConstants.SESSION_CURR_VIEW_CTX);
313:
314: if (viewContext != null && viewContext.length() > 0) {
315:
316: } else {
317: viewContext = SharedConstants.VIEW_CTX_DAY;
318: }
319:
320: if (rollViewContextToPrev) {
321: if (logger.isLoggable(Level.FINE)) {
322: logger.log(Level.FINE,
323: "Rolling Start Date to Previous Context");
324: }
325: if (viewContext
326: .equalsIgnoreCase(SharedConstants.VIEW_CTX_DAY)) {
327: startDate.add(DateTime.DAY_OF_MONTH, -1);
328: } else if (viewContext
329: .equalsIgnoreCase(SharedConstants.VIEW_CTX_WEEK)) {
330: startDate.add(DateTime.WEEK_OF_MONTH, -1);
331:
332: } else if (viewContext
333: .equalsIgnoreCase(SharedConstants.VIEW_CTX_MONTH)) {
334: startDate.add(DateTime.MONTH, -1);
335: }
336:
337: rollViewContextToPrev = false;
338: }
339:
340: if (rollViewContextToNext) {
341: if (logger.isLoggable(Level.FINE)) {
342: logger.log(Level.FINE,
343: "Rolling Start Date to Next Context");
344: }
345: if (viewContext
346: .equalsIgnoreCase(SharedConstants.VIEW_CTX_DAY)) {
347: startDate.add(DateTime.DAY_OF_MONTH, +1);
348: } else if (viewContext
349: .equalsIgnoreCase(SharedConstants.VIEW_CTX_WEEK)) {
350: startDate.add(DateTime.WEEK_OF_MONTH, +1);
351:
352: } else if (viewContext
353: .equalsIgnoreCase(SharedConstants.VIEW_CTX_MONTH)) {
354: startDate.add(DateTime.MONTH, +1);
355: }
356:
357: rollViewContextToNext = false;
358: }
359:
360: String viewContextStart = null;
361: viewContextStart = startDate.toISOString();
362:
363: DateTime endDate = null;
364: if (logger.isLoggable(Level.FINE)) {
365: logger.log(Level.FINE, "viewContextStart: "
366: + viewContextStart);
367: }
368: endDate = AppUtils.getContextEnd(startDate, viewContext);
369: String viewContextEnd = null;
370: if (endDate != null) {
371: viewContextEnd = endDate.toISOString();
372: if (logger.isLoggable(Level.FINE)) {
373: logger.log(Level.FINE, "viewContextEnd: "
374: + endDate.toISOString());
375: }
376:
377: }
378:
379: // Set the computed context start and end dates in session
380: AppUtils.setAttributeInSession(
381: SharedConstants.SESSION_CURR_VIEW_CTX_START,
382: viewContextStart);
383: AppUtils.setAttributeInSession(
384: SharedConstants.SESSION_CURR_VIEW_CTX_END,
385: viewContextEnd);
386:
387: }
388:
389: }
|