KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > projects > CmsProjectSettingsDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/projects/CmsProjectSettingsDialog.java,v $
3  * Date : $Date: 2006/03/28 12:22:36 $
4  * Version: $Revision: 1.13 $
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.projects;
33
34 import org.opencms.db.CmsProjectResourcesDisplayMode;
35 import org.opencms.db.CmsUserProjectSettings;
36 import org.opencms.db.CmsUserSettings;
37 import org.opencms.i18n.CmsMessages;
38 import org.opencms.jsp.CmsJspActionElement;
39 import org.opencms.util.CmsStringUtil;
40 import org.opencms.widgets.CmsCheckboxWidget;
41 import org.opencms.widgets.CmsSelectWidget;
42 import org.opencms.widgets.CmsSelectWidgetOption;
43 import org.opencms.workplace.CmsDialog;
44 import org.opencms.workplace.CmsWidgetDialogParameter;
45 import org.opencms.workplace.CmsWorkplaceSettings;
46
47 import java.util.ArrayList JavaDoc;
48 import java.util.List JavaDoc;
49
50 import javax.servlet.http.HttpServletRequest JavaDoc;
51 import javax.servlet.http.HttpServletResponse JavaDoc;
52 import javax.servlet.jsp.PageContext JavaDoc;
53
54 /**
55  * Dialog for editing the users project specific settings.<p>
56  *
57  * @author Michael Moossen
58  *
59  * @version $Revision: 1.13 $
60  *
61  * @since 6.0.0
62  */

63 public class CmsProjectSettingsDialog extends A_CmsProjectDialog {
64
65     /** localized messages Keys prefix. */
66     public static final String JavaDoc KEY_PREFIX = "settings";
67
68     /** aux property for mapping the projectFilesMode property of an user project settings object. */
69     private String JavaDoc m_mode;
70
71     /** bean for edition of the project settings. */
72     private CmsUserProjectSettings m_prjSettings;
73
74     /**
75      * Public constructor with JSP action element.<p>
76      *
77      * @param jsp an initialized JSP action element
78      */

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

91     public CmsProjectSettingsDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
92
93         this(new CmsJspActionElement(context, req, res));
94     }
95
96     /**
97      * Commits the edited project to the db.<p>
98      */

99     public void actionCommit() {
100
101         List JavaDoc errors = new ArrayList JavaDoc();
102         try {
103             m_prjSettings.setManagerGroup(getCms().readGroup(getManagerGroup()).getId());
104             m_prjSettings.setUserGroup(getCms().readGroup(getUserGroup()).getId());
105             m_prjSettings.setProjectFilesMode(CmsProjectResourcesDisplayMode.valueOf(getMode()));
106             CmsUserSettings settings = new CmsUserSettings(getCms());
107             settings.setProjectSettings(m_prjSettings);
108             settings.save(getCms());
109         } catch (Throwable JavaDoc t) {
110             errors.add(t);
111         }
112         // set the list of errors to display when saving failed
113
setCommitErrors(errors);
114     }
115
116     /**
117      * Returns the project files mode.<p>
118      *
119      * @return the mode
120      */

121     public String JavaDoc getMode() {
122
123         return m_mode;
124     }
125
126     /**
127      * Sets the project files mode.<p>
128      *
129      * @param mode the mode to set
130      */

131     public void setMode(String JavaDoc mode) {
132
133         CmsProjectResourcesDisplayMode.valueOf(mode);
134         m_mode = mode;
135     }
136
137     /**
138      * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
139      */

140     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
141
142         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
143
144         result.append(createWidgetTableStart());
145         // show error header once if there were validation errors
146
result.append(createWidgetErrorHeader());
147
148         if (dialog.equals(PAGES[0])) {
149             // create the widgets for the first dialog page
150
result.append(dialogBlockStart(key(Messages.GUI_SETTINGS_EDITOR_LABEL_NEWPROJECT_BLOCK_0)));
151             result.append(createWidgetTableStart());
152             result.append(createDialogRowsHtml(0, 2));
153             result.append(createWidgetTableEnd());
154             result.append(dialogBlockEnd());
155             result.append(dialogBlockStart(key(Messages.GUI_SETTINGS_EDITOR_LABEL_PROJECTFILES_BLOCK_0)));
156             result.append(createWidgetTableStart());
157             result.append(createDialogRowsHtml(3, 3));
158             result.append(createWidgetTableEnd());
159             result.append(dialogBlockEnd());
160         }
161
162         result.append(createWidgetTableEnd());
163         return result.toString();
164     }
165
166     /**
167      * Creates the list of widgets for this dialog.<p>
168      */

169     protected void defineWidgets() {
170
171         // initialize the project object to use for the dialog
172
initSettingsObject();
173
174         setKeyPrefix(KEY_PREFIX);
175
176         // widgets to display
177
addWidget(new CmsWidgetDialogParameter(this, "managerGroup", PAGES[0], new CmsSelectWidget(
178             getSelectGroups(true))));
179         addWidget(new CmsWidgetDialogParameter(this, "userGroup", PAGES[0], new CmsSelectWidget(getSelectGroups(false))));
180         addWidget(new CmsWidgetDialogParameter(
181             m_prjSettings,
182             "deleteAfterPublishing",
183             PAGES[0],
184             new CmsCheckboxWidget()));
185         addWidget(new CmsWidgetDialogParameter(this, "mode", PAGES[0], new CmsSelectWidget(getSelectModes())));
186     }
187
188     /**
189      * Initializes the project settings object to work with depending on the dialog state and request parameters.<p>
190      *
191      * Two initializations of the settings object on first dialog call are possible:
192      * <ul>
193      * <li>edit existing settings</li>
194      * <li>create new settings</li>
195      * </ul>
196      */

197     protected void initSettingsObject() {
198
199         Object JavaDoc o = null;
200
201         try {
202             if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
203                 // edit an existing settings, get the setting object from db
204
CmsUserSettings settings = new CmsUserSettings(getCms());
205                 m_prjSettings = settings.getProjectSettings();
206             } else {
207                 // this is not the initial call, get the setting object from session
208
o = getDialogObject();
209                 m_prjSettings = (CmsUserProjectSettings)o;
210             }
211             // test
212
m_prjSettings.getProjectFilesMode();
213         } catch (Exception JavaDoc e) {
214             // create a new settings object
215
m_prjSettings = new CmsUserProjectSettings();
216         }
217         try {
218             setManagerGroup(getCms().readGroup(m_prjSettings.getManagerGroup()).getName());
219         } catch (Exception JavaDoc e) {
220             // ignore
221
}
222         try {
223             setUserGroup(getCms().readGroup(m_prjSettings.getUserGroup()).getName());
224         } catch (Exception JavaDoc e) {
225             // ignore
226
}
227         try {
228             setMode(m_prjSettings.getProjectFilesMode().toString());
229         } catch (Exception JavaDoc e) {
230             // ignore
231
}
232     }
233
234     /**
235      * Overridden to set a custom online help mapping.<p>
236      *
237      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement)
238      */

239     protected void initWorkplaceMembers(CmsJspActionElement jsp) {
240
241         super.initWorkplaceMembers(jsp);
242         setOnlineHelpUriCustom("/projects/project_settings.jsp");
243     }
244
245     /**
246      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
247      */

248     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
249
250         // initialize parameters and dialog actions in super implementation
251
super.initWorkplaceRequestValues(settings, request);
252
253         // save the current state of the settings (may be changed because of the widget values)
254
setDialogObject(m_prjSettings);
255     }
256
257     /**
258      * Returns all diferent project file selection modes.<p>
259      *
260      * @return a list of modes
261      */

262     private List JavaDoc getSelectModes() {
263
264         List JavaDoc retVal = new ArrayList JavaDoc();
265         CmsMessages messages = Messages.get().getBundle(getLocale());
266         retVal.add(new CmsSelectWidgetOption(
267             CmsProjectResourcesDisplayMode.ALL_CHANGES.getMode(),
268             true,
269             messages.key(Messages.GUI_PROJECT_MODE_ALLCHANGES_0)));
270         retVal.add(new CmsSelectWidgetOption(
271             CmsProjectResourcesDisplayMode.NEW_FILES.getMode(),
272             false,
273             messages.key(Messages.GUI_PROJECT_MODE_NEWFILES_0)));
274         retVal.add(new CmsSelectWidgetOption(
275             CmsProjectResourcesDisplayMode.MODIFIED_FILES.getMode(),
276             false,
277             messages.key(Messages.GUI_PROJECT_MODE_MODFILES_0)));
278         retVal.add(new CmsSelectWidgetOption(
279             CmsProjectResourcesDisplayMode.DELETED_FILES.getMode(),
280             false,
281             messages.key(Messages.GUI_PROJECT_MODE_DELFILES_0)));
282         return retVal;
283     }
284 }
285
Popular Tags