001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme.page;
023:
024: import org.jboss.portal.theme.Orientation;
025: import org.jboss.portal.theme.render.renderer.RegionRendererContext;
026:
027: import java.util.ArrayList;
028: import java.util.Collection;
029: import java.util.Collections;
030: import java.util.HashMap;
031: import java.util.List;
032: import java.util.Map;
033:
034: /**
035: * A region on a page. <p>A region wraps one or more portlets to allow them to act as one unit inside the layout of a
036: * page.</p>
037: *
038: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
039: * @version $Revision: 8784 $
040: */
041: public final class Region implements RegionRendererContext {
042:
043: /** . */
044: private final String name;
045:
046: /** . */
047: private final PageResult page;
048:
049: /** . */
050: final List windows;
051:
052: /** . */
053: private Map properties;
054:
055: /**
056: * Create a region with default orientation (how the portlet windows are arranged) and the region name as the css id
057: * selector
058: *
059: * @param name the name of the region to create
060: */
061: public Region(PageResult page, String name) {
062: this .page = page;
063: this .name = name;
064: this .windows = new ArrayList();
065: this .properties = new HashMap();
066: }
067:
068: public void setProperty(String name, String value) {
069: properties.put(name, value);
070: }
071:
072: /** @return if there are any portlet windows in this region */
073: public boolean isEmpty() {
074: return windows.isEmpty();
075: }
076:
077: /**
078: * Add a window to the region
079: *
080: * @param windowContext the context of the window signaling where the window should go in the region
081: */
082: void addWindowContext(WindowContext windowContext) {
083: windows.add(windowContext);
084: Collections.sort(windows);
085: }
086:
087: public String toString() {
088: return "Region[name" + name + "]";
089: }
090:
091: // RegionRenderContext implementation *******************************************************************************
092:
093: public String getId() {
094: return name;
095: }
096:
097: public String getProperty(String name) {
098: return (String) properties.get(name);
099: }
100:
101: public Map getProperties() {
102: return properties;
103: }
104:
105: public Collection getWindows() {
106: if (windows.isEmpty()) {
107: return Collections.EMPTY_LIST;
108: }
109: return Collections.unmodifiableList(windows);
110: }
111:
112: public Orientation getOrientation() {
113: return null;
114: }
115:
116: public String getCSSId() {
117: return null;
118: }
119: }
|