001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/matrix/tool/src/java/org/theospi/portfolio/matrix/control/WizardPageController.java $
003: * $Id:WizardPageController.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006, 2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.matrix.control;
021:
022: import java.util.ArrayList;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.sakaiproject.metaobj.shared.model.Agent;
027: import org.sakaiproject.metaobj.shared.model.Id;
028: import org.sakaiproject.metaobj.shared.control.ToolFinishedView;
029: import org.sakaiproject.tool.api.ToolSession;
030: import org.springframework.validation.Errors;
031: import org.springframework.web.servlet.ModelAndView;
032: import org.theospi.portfolio.matrix.WizardPageHelper;
033: import org.theospi.portfolio.matrix.model.Cell;
034: import org.theospi.portfolio.matrix.model.ScaffoldingCell;
035: import org.theospi.portfolio.matrix.model.WizardPage;
036: import org.theospi.portfolio.matrix.model.WizardPageDefinition;
037: import org.theospi.portfolio.style.model.Style;
038: import org.theospi.portfolio.wizard.mgt.WizardManager;
039: import org.theospi.portfolio.wizard.model.CompletedWizard;
040: import org.theospi.portfolio.wizard.model.Wizard;
041: import org.theospi.portfolio.wizard.model.WizardPageSequence;
042:
043: /**
044: * openEvaluationPageHierRedirect will put the user here
045: *
046: * Created by IntelliJ IDEA. User: John Ellis Date: Jan 24, 2006 Time: 3:46:49
047: * PM To change this template use File | Settings | File Templates.
048: */
049: public class WizardPageController extends CellController {
050:
051: private WizardManager wizardManager;
052:
053: /*
054: * (non-Javadoc)
055: *
056: * @see org.theospi.utils.mvc.intf.FormController#referenceData(java.util.Map,
057: * java.lang.Object, org.springframework.validation.Errors)
058: */
059: public Map referenceData(Map request, Object command, Errors errors) {
060: ToolSession session = getSessionManager()
061: .getCurrentToolSession();
062:
063: Map model = super .referenceData(request, command, errors);
064: Boolean wizardPreview = Boolean.valueOf((String) request
065: .get("wizardPreview"));
066:
067: Agent owner = (Agent) request
068: .get(WizardPageHelper.WIZARD_OWNER);
069:
070: if (owner == null)
071: owner = (Agent) session
072: .getAttribute(WizardPageHelper.WIZARD_OWNER);
073:
074: session.setAttribute(WizardPageHelper.WIZARD_OWNER, owner);
075:
076: model.put("readOnlyMatrix", super .isReadOnly(owner, null));
077: model.put("pageTitleKey", "view_wizardPage");
078: model.put("helperPage", "true");
079: model.put("isWizard", "true");
080: model.put("isMatrix", "false");
081: model.put("categoryTitle", request.get("categoryTitle"));
082: model.put("wizardTitle", request.get("wizardTitle"));
083: model
084: .put("wizardDescription", request
085: .get("wizardDescription"));
086: return model;
087: }
088:
089: /**
090: * {@inheritDoc}
091: */
092: protected Style getDefaultStyle(Id pageId) {
093: // Get the wizard default style
094: CompletedWizard cw = getWizardManager()
095: .getCompletedWizardByPage(pageId);
096: return cw.getWizard().getStyle();
097: }
098:
099: /**
100: * {@inheritDoc}
101: */
102: protected String[] getObjectMetadata(String pageId, Map request) {
103: String[] objectMetadata = new String[3];
104:
105: WizardPage page = getMatrixManager().getWizardPage(
106: getIdManager().getId(pageId));
107: WizardPageSequence seq = wizardManager
108: .getWizardPageSeqByDef(page.getPageDefinition().getId());
109: Wizard wizard = seq.getCategory().getWizard();
110:
111: objectMetadata[METADATA_ID_INDEX] = wizard.getId().getValue();
112: objectMetadata[METADATA_TITLE_INDEX] = wizard.getName();
113: objectMetadata[METADATA_DESC_INDEX] = wizard.getDescription();
114: return objectMetadata;
115: }
116:
117: /**
118: * If there is a page in the session we want to display that. Otherwise look
119: * in the request for "page_id" If you are getting the wrong page displayed
120: * then you should make sure that the appropriate session/request variables
121: * are set.
122: *
123: * @param incomingModel
124: * @param request
125: * @param session
126: * @param application
127: * @throws Exception
128: */
129: public Object fillBackingObject(Object incomingModel, Map request,
130: Map session, Map application) throws Exception {
131: WizardPage page = (WizardPage) session
132: .get(WizardPageHelper.WIZARD_PAGE);
133: Id pageId = null;
134: if (page != null)
135: pageId = page.getId();
136: else
137: pageId = getIdManager().getId(
138: (String) request.get("page_id"));
139: page = getMatrixManager().getWizardPage(pageId);
140: session.put(WizardPageHelper.WIZARD_PAGE, page);
141: session.remove(WizardPageHelper.CANCELED);
142:
143: Agent owner = (Agent) session
144: .get(WizardPageHelper.WIZARD_OWNER);
145: request.put(WizardPageHelper.WIZARD_OWNER, owner);
146:
147: WizardPageSequence seq = wizardManager
148: .getWizardPageSeqByDef(page.getPageDefinition().getId());
149: if (seq.getCategory().getParentCategory() != null)
150: request.put("categoryTitle", seq.getCategory().getTitle());
151: else
152: request.put("categoryTitle", "");
153:
154: request.put("wizardPreview", Boolean.toString(seq.getCategory()
155: .getWizard().isPreview()));
156: request.put("wizardTitle", seq.getCategory().getWizard()
157: .getName());
158: request.put("wizardDescription", seq.getCategory().getWizard()
159: .getDescription());
160:
161: Cell cell = createCellWrapper(page);
162:
163: CellFormBean cellBean = (CellFormBean) incomingModel;
164: cellBean.setCell(cell);
165: List nodeList = new ArrayList(getMatrixManager()
166: .getPageContents(page));
167: cellBean.setNodes(nodeList);
168:
169: return cellBean;
170: }
171:
172: public ModelAndView handleRequest(Object requestModel, Map request,
173: Map session, Map application, Errors errors) {
174:
175: String submitWizardAction = (String) request
176: .get("submitWizard");
177:
178: if (submitWizardAction != null) {
179: session.put(ToolFinishedView.ALTERNATE_DONE_URL,
180: "submitWizard");
181: return new ModelAndView("confirmWizard", "", "");
182: }
183:
184: return super .handleRequest(requestModel, request, session,
185: application, errors);
186: }
187:
188: public static Cell createCellWrapper(WizardPage page) {
189: Cell cell = new Cell();
190: cell.setWizardPage(page);
191: if (page.getId() == null) {
192: cell.setId(page.getNewId());
193: } else {
194: cell.setId(page.getId());
195: }
196:
197: WizardPageDefinition pageDef = page.getPageDefinition();
198:
199: ScaffoldingCell cellDef = new ScaffoldingCell();
200: cellDef.setWizardPageDefinition(pageDef);
201: if (pageDef.getId() == null) {
202: cellDef.setId(pageDef.getNewId());
203: } else {
204: cellDef.setId(pageDef.getId());
205: }
206:
207: cell.setScaffoldingCell(cellDef);
208: return cell;
209: }
210:
211: public WizardManager getWizardManager() {
212: return wizardManager;
213: }
214:
215: public void setWizardManager(WizardManager wizardManager) {
216: this.wizardManager = wizardManager;
217: }
218: }
|