KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsTwoListsDialog.java,v $
3  * Date : $Date: 2006/03/27 14:52:28 $
4  * Version: $Revision: 1.3 $
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
36 import javax.servlet.ServletException JavaDoc;
37 import javax.servlet.jsp.JspException JavaDoc;
38 import javax.servlet.jsp.JspWriter JavaDoc;
39
40 /**
41  * Helper class for managing two lists on the same dialog.<p>
42  *
43  * @author Michael Moossen
44  *
45  * @version $Revision: 1.3 $
46  *
47  * @since 6.0.0
48  */

49 public class CmsTwoListsDialog {
50
51     /** the workplace instance for the active list. */
52     private A_CmsListDialog m_activeWp;
53
54     /** the workplace instance for the first list. */
55     private A_CmsListDialog m_firstWp;
56
57     /** the workplace instance for the passive list. */
58     private A_CmsListDialog m_passiveWp;
59
60     /** the workplace instance for the second list. */
61     private A_CmsListDialog m_secondWp;
62
63     /**
64      * Default constructor.<p>
65      *
66      * @param wp1 the workplace instance for the first list
67      * @param wp2 the workplace instance for the second list
68      */

69     public CmsTwoListsDialog(A_CmsListDialog wp1, A_CmsListDialog wp2) {
70
71         m_activeWp = (wp1.isActive() ? wp1 : wp2);
72         m_passiveWp = (!wp1.isActive() ? wp1 : wp2);
73         m_firstWp = wp1;
74         m_secondWp = wp2;
75     }
76
77     /**
78      * Generates the dialog starting html code.<p>
79      *
80      * @return html code
81      */

82     protected String JavaDoc defaultActionHtml() {
83
84         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
85         result.append(defaultActionHtmlStart());
86         result.append(defaultActionHtmlContent());
87         result.append(defaultActionHtmlEnd());
88         return result.toString();
89     }
90
91     /**
92      * Returns the html code for the default action content.<p>
93      *
94      * @return html code
95      */

96     protected String JavaDoc defaultActionHtmlContent() {
97
98         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
99         result.append("<table id='twolists' cellpadding='0' cellspacing='0' align='center' width='100%'>\n");
100         result.append("\t<tr>\n");
101         result.append("\t\t<td width='50%' valign='top'>\n");
102         result.append("\t\t\t").append(m_firstWp.defaultActionHtmlContent()).append("\n");
103         result.append("\t\t</td>\n");
104         result.append("\t\t<td width='20'>&nbsp;</td>");
105         result.append("\t\t<td width='50%' valign='top'>\n");
106         result.append("\t\t\t").append(m_secondWp.defaultActionHtmlContent()).append("\n");
107         result.append("\t\t</td>\n");
108         result.append("\t</tr>\n");
109         result.append("</table>\n");
110         return result.toString();
111     }
112
113     /**
114      * Generates the dialog ending html code.<p>
115      *
116      * @return html code
117      */

118     protected String JavaDoc defaultActionHtmlEnd() {
119
120         return m_activeWp.defaultActionHtmlEnd();
121     }
122
123     /**
124      * Generates the dialog starting html code.<p>
125      *
126      * @return html code
127      */

128     protected String JavaDoc defaultActionHtmlStart() {
129
130         return m_activeWp.defaultActionHtmlStart();
131     }
132
133     /**
134      * Display method for two list dialogs.<p>
135      *
136      * @throws JspException if dialog actions fail
137      * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
138      * @throws ServletException in case of errros forwarding to the required result page
139      */

140     public void displayDialog() throws JspException JavaDoc, IOException JavaDoc, ServletException JavaDoc {
141
142         displayDialog(false);
143     }
144
145     
146     /**
147      * Writes the dialog html code, only if the <code>{@link org.opencms.workplace.CmsDialog#ACTION_DEFAULT}</code> is set.<p>
148      *
149      * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
150      */

151     public void writeDialog() throws IOException JavaDoc {
152
153         if (m_activeWp.isForwarded() || m_passiveWp.isForwarded()) {
154             return;
155         }
156
157         JspWriter JavaDoc out = m_activeWp.getJsp().getJspContext().getOut();
158         out.print(defaultActionHtml());
159     }
160     
161     /**
162      * Display method for two list dialogs, executes actions, but only displays if needed.<p>
163      *
164      * @param writeLater if <code>true</code> no output is written,
165      * you have to call manually the <code>{@link #defaultActionHtml()}</code> method.
166      *
167      * @throws JspException if dialog actions fail
168      * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
169      * @throws ServletException in case of errros forwarding to the required result page
170      */

171     public void displayDialog(boolean writeLater) throws JspException JavaDoc, IOException JavaDoc, ServletException JavaDoc {
172
173         // perform the active list actions
174
m_activeWp.actionDialog();
175         if (m_activeWp.isForwarded()) {
176             return;
177         }
178
179         m_activeWp.refreshList();
180         m_passiveWp.refreshList();
181
182         if (writeLater) {
183             return;
184         }
185         JspWriter JavaDoc out = m_activeWp.getJsp().getJspContext().getOut();
186         out.print(defaultActionHtml());
187     }
188
189     /**
190      * Returns the workplace instance of the active list.<p>
191      *
192      * @return the workplace instance of the active list
193      */

194     public A_CmsListDialog getActiveWp() {
195
196         return m_activeWp;
197     }
198
199     /**
200      * Returns the workplace instance of the first list.<p>
201      *
202      * @return the workplace instance of the first list
203      */

204     public A_CmsListDialog getFirstWp() {
205
206         return m_firstWp;
207     }
208
209     /**
210      * Returns the workplace instance of the passive list.<p>
211      *
212      * @return the workplace instance of the passive list
213      */

214     public A_CmsListDialog getPassiveWp() {
215
216         return m_passiveWp;
217     }
218
219     /**
220      * Returns the workplace instance of the second list.<p>
221      *
222      * @return the workplace instance of the second list
223      */

224     public A_CmsListDialog getSecondWp() {
225
226         return m_secondWp;
227     }
228 }
229
Popular Tags