KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > list > CmsMultiListDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsMultiListDialog.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.list;
33
34 import java.io.IOException JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37
38 import javax.servlet.ServletException JavaDoc;
39 import javax.servlet.jsp.JspException JavaDoc;
40 import javax.servlet.jsp.JspWriter JavaDoc;
41
42 /**
43  * Helper class for managing three lists on the same dialog.<p>
44  *
45  * @author Jan Baudisch
46  *
47  * @version $Revision: 1.2 $
48  *
49  * @since 6.0.0
50  */

51 public class CmsMultiListDialog {
52
53     /** the workplace instance for the active list. */
54     private A_CmsListDialog m_activeWp;
55
56     /** the workplace instances for the lists. */
57     private List JavaDoc m_wps;
58
59     /**
60      * Default constructor.<p>
61      *
62      * @param wps the lists to be displayed
63      */

64     public CmsMultiListDialog(List JavaDoc wps) {
65
66         m_wps = wps;
67         Iterator JavaDoc i = m_wps.iterator();
68         while (i.hasNext()) {
69             A_CmsListDialog wp = (A_CmsListDialog)i.next();
70             if (wp.isActive()) {
71                 m_activeWp = wp;
72             }
73         }
74         if (m_activeWp == null) {
75             m_activeWp = (A_CmsListDialog)m_wps.get(0);
76         }
77     }
78
79     /**
80      * Display method for two list dialogs.<p>
81      *
82      * @throws JspException if dialog actions fail
83      * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
84      * @throws ServletException in case of errros forwarding to the required result page
85      */

86     public void displayDialog() throws JspException JavaDoc, IOException JavaDoc, ServletException JavaDoc {
87
88         displayDialog(false);
89     }
90
91     /**
92      * Display method for two list dialogs, executes actions, but only displays if needed.<p>
93      *
94      * @param writeLater if <code>true</code> no output is written,
95      * you have to call manually the <code>{@link #defaultActionHtml()}</code> method.
96      *
97      * @throws JspException if dialog actions fail
98      * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
99      * @throws ServletException in case of errros forwarding to the required result page
100      */

101     public void displayDialog(boolean writeLater) throws JspException JavaDoc, IOException JavaDoc, ServletException JavaDoc {
102
103         // perform the active list actions
104
m_activeWp.actionDialog();
105         if (m_activeWp.isForwarded()) {
106             return;
107         }
108
109         Iterator JavaDoc i = m_wps.iterator();
110         while (i.hasNext()) {
111             A_CmsListDialog wp = (A_CmsListDialog)i.next();
112             wp.refreshList();
113         }
114
115         if (writeLater) {
116             return;
117         }
118         writeDialog();
119     }
120
121     /**
122      * Returns the activeWp.<p>
123      *
124      * @return the activeWp
125      */

126     public A_CmsListDialog getActiveWp() {
127
128         return m_activeWp;
129     }
130
131     /**
132      * Returns <code>true</code> if one of the lists has been forwarded.<p>
133      *
134      * @return <code>true</code> if one of the lists has been forwarded
135      */

136     public boolean isForwarded() {
137
138         Iterator JavaDoc i = m_wps.iterator();
139         while (i.hasNext()) {
140             A_CmsListDialog wp = (A_CmsListDialog)i.next();
141             if (wp.isForwarded()) {
142                 return true;
143             }
144         }
145         return false;
146     }
147
148     /**
149      * Writes the dialog html code, only if the <code>{@link org.opencms.workplace.CmsDialog#ACTION_DEFAULT}</code> is set.<p>
150      *
151      * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
152      */

153     public void writeDialog() throws IOException JavaDoc {
154
155         JspWriter JavaDoc out = m_activeWp.getJsp().getJspContext().getOut();
156         out.print(defaultActionHtml());
157     }
158
159     /**
160      * Generates the dialog starting html code.<p>
161      *
162      * @return html code
163      */

164     protected String JavaDoc defaultActionHtml() {
165
166         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
167         result.append(defaultActionHtmlStart());
168         result.append(defaultActionHtmlContent());
169         result.append(defaultActionHtmlEnd());
170         return result.toString();
171     }
172
173     /**
174      * Returns the html code for the default action content.<p>
175      *
176      * @return html code
177      */

178     protected String JavaDoc defaultActionHtmlContent() {
179
180         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
181         result.append("<table id='twolists' cellpadding='0' cellspacing='0' align='center' width='100%'>\n");
182         Iterator JavaDoc i = m_wps.iterator();
183         while (i.hasNext()) {
184             A_CmsListDialog wp = (A_CmsListDialog)i.next();
185             result.append("\t<tr>\n");
186             result.append("\t\t<td valign='top'>\n");
187             result.append("\t\t\t").append(wp.defaultActionHtmlContent()).append("\n");
188             result.append("\t\t</td>\n");
189             result.append("\t</tr>\n");
190             result.append("\t<tr><td height='20'/></tr>\n");
191         }
192         result.append("</table>\n");
193         return result.toString();
194     }
195
196     /**
197      * Generates the dialog ending html code.<p>
198      *
199      * @return html code
200      */

201     protected String JavaDoc defaultActionHtmlEnd() {
202
203         return m_activeWp.defaultActionHtmlEnd() + m_activeWp.dialogContentEnd();
204     }
205
206     /**
207      * Generates the dialog starting html code.<p>
208      *
209      * @return html code
210      */

211     protected String JavaDoc defaultActionHtmlStart() {
212
213         return m_activeWp.getList().listJs(getActiveWp().getLocale())
214             + m_activeWp.dialogContentStart(getActiveWp().getParamTitle());
215     }
216 }
217
Popular Tags