001: /*******************************************************************************
002: * Copyright (c) 2006 The Regents of the University of California
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: ******************************************************************************/package org.sakaiproject.tool.gradebook.ui;
016:
017: import org.sakaiproject.tool.gradebook.Spreadsheet;
018: import org.sakaiproject.tool.gradebook.jsf.FacesUtil;
019: import org.sakaiproject.service.gradebook.shared.StaleObjectModificationException;
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022:
023: import java.io.Serializable;
024:
025: /**
026: * User: louis
027: * Date: Jun 14, 2006
028: * Time: 11:12:51 AM
029: */
030: public class SpreadsheetRemoveBean extends GradebookDependentBean
031: implements Serializable {
032:
033: private static final Log logger = LogFactory
034: .getLog(SpreadsheetRemoveBean.class);
035:
036: private Long spreadsheetId;
037: private boolean removeConfirmed;
038: private Spreadsheet spreadsheet;
039: private String pageName;
040:
041: public void init() {
042:
043: if (logger.isDebugEnabled())
044: logger.debug("loading spreadsheetRemove().init()");
045: if (spreadsheetId != null) {
046: logger.debug("spreadsheet id is " + spreadsheetId);
047: spreadsheet = getGradebookManager().getSpreadsheet(
048: spreadsheetId);
049: if (spreadsheet == null) {
050: // The assignment might have been removed since this link was set up.
051: if (logger.isDebugEnabled())
052: logger.debug("No spreadsheetId=" + spreadsheetId
053: + " in gradebookUid " + getGradebookUid());
054: if (logger.isDebugEnabled())
055: logger.debug("spreadsheet is null");
056: }
057: }
058: }
059:
060: public Long getSpreadsheetId() {
061: return spreadsheetId;
062: }
063:
064: public void setSpreadsheetId(Long spreadsheetId) {
065: this .spreadsheetId = spreadsheetId;
066: }
067:
068: public boolean isRemoveConfirmed() {
069: return removeConfirmed;
070: }
071:
072: public void setRemoveConfirmed(boolean removeConfirmed) {
073: this .removeConfirmed = removeConfirmed;
074: }
075:
076: public Spreadsheet getSpreadsheet() {
077: return spreadsheet;
078: }
079:
080: public void setSpreadsheet(Spreadsheet spreadsheet) {
081: this .spreadsheet = spreadsheet;
082: }
083:
084: public String getPageName() {
085: return pageName;
086: }
087:
088: public void setPageName(String pageName) {
089: this .pageName = pageName;
090: }
091:
092: public String removeSpreadsheet() {
093:
094: if (removeConfirmed) {
095: try {
096: getGradebookManager().removeSpreadsheet(spreadsheetId);
097: } catch (StaleObjectModificationException e) {
098: FacesUtil
099: .addErrorMessage(getLocalizedString("remove_spreadsheet_locking_failure"));
100: return null;
101: }
102: FacesUtil.addRedirectSafeMessage(getLocalizedString(
103: "remove_spreadsheet_success",
104: new String[] { spreadsheet.getName() }));
105: return "spreadsheetListing";
106: } else {
107: FacesUtil
108: .addErrorMessage(getLocalizedString("remove_spreadsheet_confirmation_required"));
109: return null;
110: }
111:
112: }
113:
114: }
|