001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portal.model;
021:
022: import java.util.Iterator;
023:
024: import javax.portlet.ActionRequest;
025: import javax.portlet.WindowState;
026: import javax.portlet.WindowStateException;
027: import javax.servlet.http.HttpServletRequest;
028: import javax.xml.bind.Unmarshaller;
029: import javax.xml.bind.annotation.XmlElement;
030: import javax.xml.bind.annotation.XmlRootElement;
031:
032: import com.nabhinc.portal.core.PortalConstants;
033: import com.nabhinc.portal.core.SessionCache;
034: import com.nabhinc.util.SingleValueIterator;
035:
036: /**
037: * A layout that displays a single portlet.
038: *
039: * @author Padmanabh Dabke
040: * (c) 2002 Nabh Information Systems, Inc. All Rights Reserved.
041: */
042: @XmlRootElement(name="solo")
043: public class SoloLayout extends BaseCompositeRenderable {
044:
045: /**
046: * Single portlet that is displayed by this layout.
047: */
048: @XmlElement(name="portlet-window")
049: public PortletWindow singlePortlet = null;
050:
051: /**
052: * Sets the layout file to single_layout.jsp
053: */
054: public SoloLayout() {
055: setTemplate("solo.jsp");
056: }
057:
058: public SoloLayout(PortalPage p) {
059: super (p);
060: setTemplate("solo.jsp");
061: }
062:
063: public void create(ActionRequest req) {
064: modify(req);
065: }
066:
067: /**
068: * Modify the contents of this layout based on the form data submitted
069: * via HttpServletRequest.
070: * @param req javax.servlet.http.HttpServletRequest
071: */
072: public void modify(ActionRequest req) {
073: super .modify(req);
074: String pName = req.getParameter("portletname");
075: singlePortlet = createPortletWindow(pName, req, "showborder",
076: "showtitle");
077: }
078:
079: public boolean removePortletWindow(PortletWindow pWindow) {
080: if (this .singlePortlet == pWindow) {
081: this .singlePortlet = null;
082: return true;
083: } else {
084: return false;
085: }
086: }
087:
088: public void setRowIndex(int rowIndex) {
089: // Nothing to be done
090: }
091:
092: public String getLayoutType() {
093: return "solo";
094: }
095:
096: public PortletWindow getDefaultPortletWindow() {
097: return this .singlePortlet;
098: }
099:
100: @SuppressWarnings("unchecked")
101: public Iterator<Renderable> getComponents() {
102: return new SingleValueIterator(this .singlePortlet);
103: }
104:
105: public void setRenderAttributes(HttpServletRequest request,
106: SessionCache sCache) {
107: request.setAttribute(PortalConstants.SOLO_LAYOUT_ID_ATTRIBUTE,
108: Integer.toString(this .getNumericId()));
109: if (this .singlePortlet != null) {
110: try {
111: sCache.renderRequest
112: .setPortalInterface(this .singlePortlet);
113: sCache.renderRequest
114: .setWindowState(WindowState.MAXIMIZED);
115: } catch (WindowStateException e) {
116: // Ignore
117:
118: }
119: request.setAttribute(
120: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE,
121: this .singlePortlet);
122: }
123: }
124:
125: public void addContent(Renderable r, String optionLabel) {
126: this .singlePortlet = (PortletWindow) r;
127: this .singlePortlet.setTemplate("solo_portlet.jsp");
128:
129: }
130:
131: public void afterUnmarshal(Unmarshaller um, Object parent) {
132: if (this .singlePortlet != null) {
133: this .singlePortlet.setTemplate("solo_portlet.jsp");
134: }
135: }
136:
137: public void addPortletWindow(PortletWindow pWindow) {
138: throw new RuntimeException(
139: "You cannot add a portlet window to solo layout.");
140:
141: }
142: }
|