01: package com.sun.portal.app.sharedevents.faces;
02:
03: import com.sun.portal.log.common.PortalLogger;
04: import java.util.logging.Level;
05: import java.util.logging.Logger;
06: import com.sun.portal.app.sharedevents.util.AppUtils;
07: import com.sun.portal.app.sharedevents.util.SharedConstants;
08:
09: /**
10: * This class provides functionality for table preferences.
11: */
12: public class EventsTablePreferences {
13: private String preference = null; // Rows preference.
14: private EventsTableContainer data = null; // Table data.
15: private int rows = 5; // Rows per page.
16: private String CLASS_NAME = "EventsTablePreferences";
17:
18: private static Logger logger = PortalLogger
19: .getLogger(EventsTablePreferences.class);
20:
21: /** Default constructor. */
22: public EventsTablePreferences(EventsTableContainer data) {
23: logger.entering(CLASS_NAME, "EventsTablePreferences()");
24: this .data = data;
25: logger.exiting(CLASS_NAME, "EventsTablePreferences()");
26: this .findRowsFromSession();
27:
28: }
29:
30: /** Table preferences event. */
31: public void applyPreferences() {
32: logger.entering(CLASS_NAME, "applyPreferences(), rows=" + rows);
33:
34: try {
35: int rows = Integer.parseInt(preference);
36: if (rows > 0) {
37: this .rows = rows;
38: this .setRowsInSession(rows);
39: }
40: } catch (NumberFormatException e) {
41: logger.log(Level.WARNING,
42: "Failed to parse Preferred Row Count: "
43: + e.getMessage());
44: rows = 5;
45: }
46: logger.exiting(CLASS_NAME, "applyPreferences(), rows=" + rows);
47: }
48:
49: /** Get rows per page. */
50: public int getRows() {
51: logger.fine(CLASS_NAME + "getRows().rows=" + rows);
52: return rows;
53: }
54:
55: /** Get preference. */
56: public String getPreference() {
57: if (preference != null) {
58: return preference;
59: } else {
60: //return "5";
61: return Integer.toString(rows);
62: }
63: }
64:
65: /** Set preference. */
66: public void setPreference(String value) {
67: preference = value;
68:
69: }
70:
71: private void setRowsInSession(int count) {
72: AppUtils.setAttributeInSession(
73: SharedConstants.SESSION_EVENTS_LIST_DISPLAY_ROWS,
74: String.valueOf(count));
75: }
76:
77: private void findRowsFromSession() {
78: String value = (String) AppUtils
79: .getSessionAttribute(SharedConstants.SESSION_EVENTS_LIST_DISPLAY_ROWS);
80: if (value != null) {
81: try {
82: int rows = Integer.parseInt(value);
83: if (rows > 0) {
84: this .rows = rows;
85: }
86: } catch (NumberFormatException e) {
87: logger.log(Level.WARNING,
88: "Failed to parse Preferred Row Count: "
89: + e.getMessage());
90: rows = 5;
91: }
92: }
93: }
94: }
|