001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/presentation/tool/src/java/org/theospi/portfolio/presentation/control/ListLayoutController.java $
003: * $Id: ListLayoutController.java 18076 2006-11-09 20:05:47Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 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.presentation.control;
021:
022: import java.util.ArrayList;
023: import java.util.HashSet;
024: import java.util.Hashtable;
025: import java.util.List;
026: import java.util.Map;
027: import java.util.Set;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.metaobj.shared.model.Agent;
032: import org.sakaiproject.metaobj.utils.mvc.intf.ListScroll;
033: import org.sakaiproject.metaobj.utils.mvc.intf.ListScrollIndexer;
034: import org.sakaiproject.tool.cover.ToolManager;
035: import org.springframework.validation.Errors;
036: import org.springframework.web.servlet.ModelAndView;
037: import org.theospi.portfolio.presentation.PresentationLayoutHelper;
038: import org.theospi.portfolio.presentation.model.PresentationLayout;
039:
040: public class ListLayoutController extends
041: AbstractPresentationController {
042:
043: protected final Log logger = LogFactory.getLog(getClass());
044: private ListScrollIndexer listScrollIndexer;
045:
046: public ModelAndView handleRequest(Object requestModel, Map request,
047: Map session, Map application, Errors errors) {
048:
049: boolean global = getPresentationManager().isGlobal();
050: Hashtable model = new Hashtable();
051: Agent agent = getAuthManager().getAgent();
052: String selectable = (String) session
053: .get(PresentationLayoutHelper.LAYOUT_SELECTABLE);
054:
055: Set layoutSet = new HashSet(getPresentationManager()
056: .findLayoutsByOwner(agent,
057: ToolManager.getCurrentPlacement().getContext()));
058: layoutSet.addAll(getPresentationManager().findPublishedLayouts(
059: ToolManager.getCurrentPlacement().getContext()));
060:
061: if (selectable != null) {
062: model.put("selectableLayout", selectable);
063: layoutSet.addAll(getPresentationManager()
064: .findMyGlobalLayouts());
065: } else if (global) {
066: layoutSet.addAll(getPresentationManager()
067: .findAllGlobalLayouts());
068: }
069:
070: List layouts = new ArrayList(layoutSet);
071:
072: model.put("layoutCount", String.valueOf(layouts.size()));
073:
074: if (request.get("newPresentationLayoutId") != null) {
075: request.put(ListScroll.ENSURE_VISIBLE_TAG, ""
076: + getPresentationIndex(layouts, (String) request
077: .get("newPresentationLayoutId")));
078: }
079:
080: layouts = getListScrollIndexer().indexList(request, model,
081: layouts);
082: model.put("layouts", layouts);
083:
084: model.put("osp_agent", agent);
085: String worksiteId = getWorksiteManager().getCurrentWorksiteId()
086: .getValue();
087: model.put("worksite", getWorksiteManager().getSite(worksiteId));
088: model.put("tool", getWorksiteManager().getTool(
089: ToolManager.getCurrentPlacement().getId()));
090: model.put("isMaintainer", isMaintainer());
091:
092: if (session.get(PresentationLayoutHelper.CURRENT_LAYOUT_ID) != null)
093: model.put("selectedLayout", session
094: .get(PresentationLayoutHelper.CURRENT_LAYOUT_ID));
095:
096: model.put("isGlobal", new Boolean(global));
097:
098: return new ModelAndView("success", model);
099: }
100:
101: protected int getPresentationIndex(List layouts, String layoutId) {
102: if (layoutId == null) {
103: return 0;
104: }
105:
106: for (int i = 0; i < layouts.size(); i++) {
107: PresentationLayout current = (PresentationLayout) layouts
108: .get(i);
109: if (current.getId().getValue().equals(layoutId)) {
110: return i;
111: }
112: }
113: return 0;
114: }
115:
116: public ListScrollIndexer getListScrollIndexer() {
117: return listScrollIndexer;
118: }
119:
120: public void setListScrollIndexer(ListScrollIndexer listScrollIndexer) {
121: this.listScrollIndexer = listScrollIndexer;
122: }
123:
124: }
|