KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > workplace > CmsSynchronizeSettingsDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/CmsSynchronizeSettingsDialog.java,v $
3  * Date : $Date: 2005/06/27 23:22:23 $
4  * Version: $Revision: 1.10 $
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.tools.workplace;
33
34 import org.opencms.db.CmsUserSettings;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.synchronize.CmsSynchronizeSettings;
37 import org.opencms.widgets.CmsCheckboxWidget;
38 import org.opencms.widgets.CmsInputWidget;
39 import org.opencms.widgets.CmsVfsFileWidget;
40 import org.opencms.workplace.CmsWidgetDialog;
41 import org.opencms.workplace.CmsWidgetDialogParameter;
42 import org.opencms.workplace.CmsWorkplaceSettings;
43
44 import java.util.ArrayList JavaDoc;
45 import java.util.List JavaDoc;
46
47 import javax.servlet.http.HttpServletRequest JavaDoc;
48 import javax.servlet.http.HttpServletResponse JavaDoc;
49 import javax.servlet.jsp.PageContext JavaDoc;
50
51 /**
52  * Dialog to edit the synchronize settings of the OpenCms Workplace.<p>
53  *
54  * @author Jan Baudisch
55  *
56  * @version $Revision: 1.10 $
57  *
58  * @since 6.0.0
59  */

60 public class CmsSynchronizeSettingsDialog extends CmsWidgetDialog {
61
62     /** Defines which pages are valid for this dialog. */
63     public static final String JavaDoc[] PAGES = {"page1"};
64
65     /** localized messages Keys prefix. */
66     public static final String JavaDoc KEY_PREFIX = "sync";
67     
68     /** The synchronize settings which are edited on this dialog. */
69     private CmsSynchronizeSettings m_synchronizeSettings;
70
71     /**
72      * Public constructor with JSP action element.<p>
73      *
74      * @param jsp an initialized JSP action element
75      */

76     public CmsSynchronizeSettingsDialog(CmsJspActionElement jsp) {
77
78         super(jsp);
79     }
80
81     /**
82      * Public constructor with JSP variables.<p>
83      *
84      * @param context the JSP page context
85      * @param req the JSP request
86      * @param res the JSP response
87      */

88     public CmsSynchronizeSettingsDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
89
90         this(new CmsJspActionElement(context, req, res));
91     }
92
93     /**
94      * Commits the edited synchronize settings to the user settings.<p>
95      */

96     public void actionCommit() {
97
98         List JavaDoc errors = new ArrayList JavaDoc();
99
100         try {
101             // set the synchronize settings
102
CmsUserSettings userSettings = new CmsUserSettings(getCms());
103             m_synchronizeSettings.checkValues(getCms());
104             userSettings.setSynchronizeSettings(m_synchronizeSettings);
105             userSettings.save(getCms());
106             setDialogObject(null);
107         } catch (Throwable JavaDoc t) {
108             errors.add(t);
109         }
110
111         // set the list of errors to display when saving failed
112
setCommitErrors(errors);
113     }
114
115     /**
116      * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
117      *
118      * This overwrites the method from the super class to create a layout variation for the widgets.<p>
119      *
120      * @param dialog the dialog (page) to get the HTML for
121      * @return the dialog HTML for all defined widgets of the named dialog (page)
122      */

123     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
124
125         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
126
127         // create widget table
128
result.append(createWidgetTableStart());
129
130         // show error header once if there were validation errors
131
result.append(createWidgetErrorHeader());
132
133         // create the widgets for the first dialog page
134
result.append(dialogBlockStart(key(Messages.GUI_EDITOR_LABEL_ACTIVATE_SYNC_BLOCK_0)));
135         result.append(createWidgetTableStart());
136         result.append(createDialogRowsHtml(0, 0));
137         result.append(createWidgetTableEnd());
138         result.append(dialogBlockEnd());
139         result.append(dialogBlockStart(key(Messages.GUI_EDITOR_LABEL_SOURCE_LIST_VFS_BLOCK_0)));
140         result.append(createWidgetTableStart());
141         result.append(createDialogRowsHtml(1, 1));
142         result.append(createWidgetTableEnd());
143         result.append(dialogBlockEnd());
144         result.append(dialogBlockStart(key(Messages.GUI_EDITOR_LABEL_DESTINATION_RFS_BLOCK_0)));
145         result.append(createWidgetTableStart());
146         result.append(createDialogRowsHtml(2, 2));
147         result.append(createWidgetTableEnd());
148         result.append(dialogBlockEnd());
149
150         // close widget table
151
result.append(createWidgetTableEnd());
152
153         return result.toString();
154     }
155
156     /**
157      * Creates the list of widgets for this dialog.<p>
158      */

159     protected void defineWidgets() {
160
161         // initialize the object to use for the dialog
162
initSynchronizeSettingsObject();
163         setKeyPrefix(KEY_PREFIX);
164         addWidget(new CmsWidgetDialogParameter(m_synchronizeSettings, "enabled", PAGES[0], new CmsCheckboxWidget()));
165         addWidget(new CmsWidgetDialogParameter(
166             m_synchronizeSettings,
167             "destinationPathInRfs",
168             PAGES[0],
169             new CmsInputWidget()));
170         addWidget(new CmsWidgetDialogParameter(
171             m_synchronizeSettings,
172             "sourceListInVfs",
173             "/",
174             PAGES[0],
175             new CmsVfsFileWidget(false, ""),
176             1,
177             CmsWidgetDialogParameter.MAX_OCCURENCES));
178
179     }
180
181     /**
182      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
183      */

184     protected String JavaDoc[] getPageArray() {
185
186         return PAGES;
187     }
188
189     /**
190      * @see org.opencms.workplace.CmsWorkplace#initMessages()
191      */

192     protected void initMessages() {
193
194         // add specific dialog resource bundle
195
addMessages(Messages.get().getBundleName());
196         // add default resource bundles
197
super.initMessages();
198     }
199
200     /**
201      * Initializes the synchronize settings object for this dialog.<p>
202      */

203     protected void initSynchronizeSettingsObject() {
204
205         Object JavaDoc o = getDialogObject();
206
207         if ((o == null) || !(o instanceof CmsSynchronizeSettings)) {
208             CmsUserSettings userSettings = new CmsUserSettings(getCms());
209             o = userSettings.getSynchronizeSettings();
210         }
211
212         if (o != null) {
213             m_synchronizeSettings = (CmsSynchronizeSettings)o;
214         } else {
215             m_synchronizeSettings = new CmsSynchronizeSettings();
216         }
217     }
218
219     /**
220      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
221      */

222     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
223
224         // initialize parameters and dialog actions in super implementation
225
super.initWorkplaceRequestValues(settings, request);
226
227         // save the current synchronize settings (may be changed because of the widget values)
228
setDialogObject(m_synchronizeSettings);
229     }
230
231 }
Popular Tags