001: package com.sun.portal.app.sharedevents.faces;
002:
003: import com.sun.comclient.calendar.RecurrencePattern;
004: import com.sun.portal.app.sharedevents.models.EventModel;
005: import com.sun.portal.app.sharedevents.util.AppUtils;
006: import com.sun.web.ui.component.Checkbox;
007: import com.sun.web.ui.model.Option;
008: import com.sun.portal.app.sharedevents.util.SharedConstants;
009: import com.sun.portal.log.common.PortalLogger;
010: import java.util.ArrayList;
011: import java.util.ResourceBundle;
012: import java.util.logging.Level;
013: import java.util.logging.Logger;
014:
015: /**
016: * This class provides functionality for table actions.
017: */
018: public class EventsTableActions {
019: private String actionBottom = null; // Action (bottom).
020: private String actionTop = null; // Action (top).
021: private EventsTableContainer tableContainer = null; // Model tableContainer.
022:
023: private String CLASS_NAME = "EventsTableActions";
024: private boolean deleteFailed = false;
025: private boolean disabled = false;
026:
027: private ResourceBundle bundle = null;
028:
029: /** Action menu items. */
030:
031: protected static final Option[] actionOptions = null;
032:
033: private static Logger logger = PortalLogger
034: .getLogger(EventsTableActions.class);
035:
036: /** Default constructor. */
037: public EventsTableActions(EventsTableContainer tableContainer) {
038: logger.entering(CLASS_NAME, "EventsTableActions()");
039: this .tableContainer = tableContainer;
040: bundle = getResourceBundle();
041: logger.exiting(CLASS_NAME, "EventsTableActions()");
042: }
043:
044: public boolean getDropDownDisabled() {
045: /*
046: if (tableContainer.isSearchInvoked()) {
047: disabled = true;
048: }
049: */
050: String ctx = (String) AppUtils
051: .getSessionAttribute(SharedConstants.SESSION_CURR_VIEW_CTX);
052:
053: if (ctx != null
054: && ctx
055: .equalsIgnoreCase(SharedConstants.VIEW_CTX_SEARCH)) {
056: disabled = true;
057: }
058: return disabled;
059: }
060:
061: // Action button methods
062:
063: /**
064: * Deletes the selected events from the calendar.
065: * The selected checkbox value is a combination of event UID & RID (if recurring) and this
066: * is returned as ArrayList.
067: * This ArayList is used for deletion.
068: * An error should be reported if any of the selected events could not be deleted.
069: * However, the processing is not stopped until all the selected events are attempted to
070: * deletion.
071: *
072: */
073: public void DeleteAction() {
074: logger.entering(CLASS_NAME, "DeleteAction()");
075: ArrayList selectedIds = null;
076: String uid = null;
077:
078: //tableContainer.setActionsInvoked(true);
079: AppUtils.setAttributeInSession(
080: SharedConstants.SESSION_REFRESH_DATA, "true");
081: selectedIds = Checkbox.getSelected("selectGroup");
082:
083: deleteFailed = false;
084:
085: if (selectedIds != null) {
086:
087: deleteEventsList(selectedIds);
088:
089: } else {
090:
091: }
092:
093: tableContainer.setShowAlert(true);
094:
095: if (deleteFailed) {
096:
097: tableContainer
098: .setAlertType(SharedConstants.SHOW_ALERT_TYPE_ERROR);
099: tableContainer.setAlertMessage(bundle
100: .getString("eventsDeleteFailedError"));
101:
102: } else {
103: tableContainer
104: .setAlertType(SharedConstants.SHOW_ALERT_TYPE_INFO);
105: tableContainer.setAlertMessage(bundle
106: .getString("eventsDeleteSuccessMsg"));
107: }
108:
109: resetActionMenus();
110: logger.exiting(CLASS_NAME, "DeleteAction()");
111:
112: }
113:
114: /** Action 2 event. */
115: public void NewEventAction() {
116: logger.entering(CLASS_NAME, "NewEventAction()");
117:
118: resetActionMenus();
119: logger.exiting(CLASS_NAME, "NewEventAction()");
120: }
121:
122: // Action menu methods
123:
124: /** Action menu event (bottom). */
125: public void actionBottom() {
126: logger.entering(CLASS_NAME, "actionBottom()");
127:
128: /*
129: tableContainer.setActionsInvoked(true);
130:
131: if (actionBottom != null && actionBottom.length() > 0) {
132: tableContainer.setViewContext(actionBottom);
133: }
134:
135: // Ask the container to compute the new start & end dates based on this action.
136: // This needs to be done here because that information is required by other
137: // elements (ex: Table title, navigation) _before_ the container fetches the
138: // data based on new dates.
139: tableContainer.constructContextStartAndEndDates();
140: */
141: if (logger.isLoggable(Level.FINE)) {
142: logger.fine("Setting the new View Context in Session: "
143: + actionBottom);
144: logger.fine("Setting refresh data to true in Session");
145: }
146:
147: AppUtils.setAttributeInSession(
148: SharedConstants.SESSION_CURR_VIEW_CTX, actionBottom);
149: AppUtils.setAttributeInSession(
150: SharedConstants.SESSION_REFRESH_DATA, "true");
151:
152: // If Day view context is selected, remove the context start and end date from the
153: // session because we need to show the current day events and not the day belonging
154: // to the previous view context
155: if (actionBottom != null
156: && actionBottom
157: .equalsIgnoreCase(SharedConstants.VIEW_CTX_DAY)) {
158: AppUtils
159: .removeAttributeFromSession(SharedConstants.SESSION_CURR_VIEW_CTX_START);
160: AppUtils
161: .removeAttributeFromSession(SharedConstants.SESSION_CURR_VIEW_CTX_END);
162:
163: }
164:
165: actionTop = actionBottom; // Set selected property for both menus.
166: logger.exiting(CLASS_NAME, "actionBottom()");
167: }
168:
169: /** Action menu event (top). */
170: public void actionTop() {
171: logger.entering(CLASS_NAME, "actionTop()");
172:
173: /*
174: tableContainer.setActionsInvoked(true);
175:
176: if (actionTop != null && actionTop.length() > 0) {
177: tableContainer.setViewContext(actionTop);
178: }
179:
180: // Ask the container to compute the new start & end dates based on this action.
181: // This needs to be done here because that information is required by other
182: // elements (ex: Table title, navigation) _before_ the container fetches the
183: // data based on new dates.
184: tableContainer.constructContextStartAndEndDates();
185: */
186:
187: if (logger.isLoggable(Level.FINE)) {
188: logger.fine("Setting the new View Context in Session: "
189: + actionTop);
190: logger.fine("Setting refresh data to true in Session");
191: }
192:
193: AppUtils.setAttributeInSession(
194: SharedConstants.SESSION_CURR_VIEW_CTX, actionTop);
195: AppUtils.setAttributeInSession(
196: SharedConstants.SESSION_REFRESH_DATA, "true");
197:
198: // If Day view context is selected, remove the context start and end date from the
199: // session because we need to show the current day events and not the day belonging
200: // to the previous view context
201: if (actionTop != null
202: && actionTop
203: .equalsIgnoreCase(SharedConstants.VIEW_CTX_DAY)) {
204: AppUtils
205: .removeAttributeFromSession(SharedConstants.SESSION_CURR_VIEW_CTX_START);
206: AppUtils
207: .removeAttributeFromSession(SharedConstants.SESSION_CURR_VIEW_CTX_END);
208:
209: }
210:
211: actionBottom = actionTop; // Set selected property for both menus.
212: logger.exiting(CLASS_NAME, "actionTop()");
213: }
214:
215: /** Get action menu options. */
216: public Option[] getActionOptions() {
217: Option[] actionOptions = {
218: //new Option(SharedConstants.VIEW_CTX_DAY, "Events for Day"),
219: new Option(SharedConstants.VIEW_CTX_DAY, bundle
220: .getString("dayView")),
221: new Option(SharedConstants.VIEW_CTX_WEEK, bundle
222: .getString("weekView")),
223: new Option(SharedConstants.VIEW_CTX_MONTH, bundle
224: .getString("monthView")), };
225: return actionOptions;
226: }
227:
228: /** Get action (bottom). */
229: public String getActionBottom() {
230: return actionBottom;
231: }
232:
233: /** Set action (bottom). */
234: public void setActionBottom(String value) {
235: actionBottom = value;
236:
237: }
238:
239: /** Get action (top). */
240: public String getActionTop() {
241: return actionTop;
242: }
243:
244: /** Set action (top). */
245: public void setActionTop(String value) {
246: actionTop = value;
247:
248: }
249:
250: /** Helper method to reset action menus. */
251: protected void resetActionMenus() {
252: actionBottom = actionTop = null;
253:
254: }
255:
256: /** Set disabled value for table actions. */
257: public boolean getDisabled() {
258: // If there is at least one checkbox selection, actions are enabled.
259: return (Checkbox.getSelected("selectGroup") == null);
260: }
261:
262: private void deleteEventsList(ArrayList uidRidList) {
263: if (uidRidList == null) {
264: return;
265: }
266:
267: String uid = null;
268: String rid = null;
269: String uidRid = null;
270: String[] uidAndRid = null;
271:
272: EventModel evtModelObj = getEventModel();
273:
274: // We'll use the evtModelObj for all the delete operations. So, make sure to clear up the
275: // previously set data
276:
277: for (int i = 0; i < uidRidList.size(); i++) {
278:
279: //Clear any previously set data
280: evtModelObj.setEventUID(null);
281: evtModelObj.setEventRID(null);
282: evtModelObj.setRecurrenceModifier(null);
283:
284: uid = null;
285: rid = null;
286: uidAndRid = null;
287:
288: uidRid = (String) uidRidList.get(i);
289:
290: if (uidRid.indexOf(SharedConstants.UID_RID_SEPERATOR) != -1) {
291: uidAndRid = uidRid
292: .split(SharedConstants.UID_RID_SEPERATOR);
293: if (uidAndRid.length >= 2) {
294: uid = uidAndRid[0];
295: rid = uidAndRid[1];
296: } else {
297: uid = uidAndRid[0];
298: }
299:
300: } else {
301: uid = uidRid;
302: }
303:
304: evtModelObj.setEventUID(uid);
305: evtModelObj.setEventRID(rid);
306: evtModelObj
307: .setRecurrenceModifier(RecurrencePattern.THIS_INSTANCE);
308:
309: try {
310: evtModelObj
311: .insert(SharedConstants.DELETE_EVENT_CONTEXT);
312: } catch (Exception e1) {
313: logger.log(Level.SEVERE,
314: "Failed to Delete Event: UID: " + uid
315: + " RID: " + rid + e1.getMessage());
316: deleteFailed = true;
317: }
318:
319: }
320:
321: }
322:
323: private EventModel getEventModel() {
324: return new EventModel("EventTableActions");
325: }
326:
327: private ResourceBundle getResourceBundle() {
328: return AppUtils.getResourceBundle();
329: }
330:
331: }
|