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 javax.portlet.ActionRequest;
023:
024: /**
025: * Specifies l&f of a portal column.
026: *
027: * @author Padmanabh Dabke
028: * (c) 2001, 2003 Nabh Information Systems, Inc. All Rights Reserved.
029: */
030: public class ColumnLayout {
031:
032: /**
033: * Portlets in this column
034: */
035: public PortletWindow[] portletInfo = new PortletWindow[0];
036:
037: /**
038: * Add a portlet at the end.
039: */
040: protected void addPortlet(Renderable pi) {
041:
042: int origLen = portletInfo.length;
043: PortletWindow[] newPortlets = new PortletWindow[origLen + 1];
044:
045: for (int i = 0; i < origLen; i++) {
046: newPortlets[i] = portletInfo[i];
047:
048: }
049:
050: newPortlets[origLen] = (PortletWindow) pi;
051: portletInfo = newPortlets;
052:
053: }
054:
055: /**
056: * Delete a portlet at the specified index.
057: */
058: protected Renderable deletePortlet(int portletIndex) {
059:
060: if (portletIndex < 0 || portletIndex >= portletInfo.length) {
061: // ignore invalid indices
062: //warn("Attempt to delete a portlet with invalid portlet index.");
063: return null;
064: }
065:
066: PortletWindow deletedPortlet = portletInfo[portletIndex];
067: PortletWindow[] newPortlets = new PortletWindow[portletInfo.length - 1];
068: //PortletConfig[] newConfigs = new PortletConfig[ps.length - 1];
069:
070: for (int i = 0; i < portletIndex; i++) {
071: newPortlets[i] = portletInfo[i];
072: //newConfigs[i] = configs[i];
073: }
074:
075: int newLen = newPortlets.length;
076:
077: for (int i = portletIndex; i < newLen; i++) {
078: newPortlets[i] = portletInfo[i + 1];
079: //newConfigs[i] = configs[i + 1];
080: }
081:
082: portletInfo = newPortlets;
083: //cpColumns[colIndex].configs = newConfigs;
084: return deletedPortlet;
085: }
086:
087: /**
088: * Get a portlet at the given index.
089: */
090: protected Renderable getPortletWindow(int portletIndex) {
091:
092: if (portletIndex < 0 || portletIndex >= portletInfo.length) {
093: // ignore invalid indices
094: //warn("Attempt to delete a portlet with invalid portlet index.");
095: return null;
096: } else {
097: return portletInfo[portletIndex];
098: }
099:
100: }
101:
102: public boolean removePortletWindow(PortletWindow pWindow) {
103: for (int i = 0; i < portletInfo.length; i++) {
104: if (portletInfo[i] == pWindow) {
105: deletePortlet(i);
106: return true;
107: }
108: }
109: return false;
110: }
111:
112: public void create(ActionRequest req) {
113: // TODO Auto-generated method stub
114:
115: }
116:
117: public void setRowIndex(int rowIndex) {
118: // No use for this method
119:
120: }
121:
122: public String getLayoutType() {
123: return "column";
124: }
125:
126: public void addPortletWindow(PortletWindow newWindow, int index) {
127:
128: PortletWindow[] newInfo = new PortletWindow[this .portletInfo.length + 1];
129:
130: for (int i = 0; i < index; i++) {
131: newInfo[i] = portletInfo[i];
132: }
133:
134: newInfo[index] = newWindow;
135: int newLen = newInfo.length;
136:
137: for (int i = index + 1; i < newLen; i++) {
138: newInfo[i] = portletInfo[i - 1];
139: }
140:
141: portletInfo = newInfo;
142:
143: }
144:
145: }
|