KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > widgets > CmsVfsFileWidget


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/widgets/CmsVfsFileWidget.java,v $
3  * Date : $Date: 2006/03/27 14:52:20 $
4  * Version: $Revision: 1.15 $
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.widgets;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.OpenCms;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.workplace.CmsWorkplace;
38
39 /**
40  * Provides a OpenCms VFS file selection widget, for use on a widget dialog.<p>
41  *
42  * @author Andreas Zahner
43  *
44  * @version $Revision: 1.15 $
45  *
46  * @since 6.0.0
47  */

48 public class CmsVfsFileWidget extends A_CmsWidget {
49
50     /** Configuration parameter to set the flag to show the site selector in popup resource tree. */
51     public static final String JavaDoc CONFIGURATION_HIDESITESELECTOR = "hidesiteselector";
52
53     /** Configuration parameter to set the flag to show the site selector in popup resource tree. */
54     public static final String JavaDoc CONFIGURATION_SHOWSITESELECTOR = "showsiteselector";
55
56     /** Configuration parameter to set start site of the popup resource tree. */
57     public static final String JavaDoc CONFIGURATION_STARTSITE = "startsite";
58
59     /** Flag to determine if the site selector should be shown in popup window. */
60     private boolean m_showSiteSelector;
61
62     /** The start site used in the popup window. */
63     private String JavaDoc m_startSite;
64
65     /**
66      * Creates a new vfs file widget.<p>
67      */

68     public CmsVfsFileWidget() {
69
70         // empty constructor is required for class registration
71
this("");
72     }
73
74     /**
75      * Createa a new vfs file widget with the parameters to configure the popup tree window behaviour.<p>
76      *
77      * @param showSiteSelector true if the site selector should be shown in the popup window
78      * @param startSite the start site root for the popup window
79      */

80     public CmsVfsFileWidget(boolean showSiteSelector, String JavaDoc startSite) {
81
82         m_showSiteSelector = showSiteSelector;
83         m_startSite = startSite;
84     }
85
86     /**
87      * Creates a new vfs file widget with the given configuration.<p>
88      *
89      * @param configuration the configuration to use
90      */

91     public CmsVfsFileWidget(String JavaDoc configuration) {
92
93         super(configuration);
94     }
95
96     /**
97      * @see org.opencms.widgets.A_CmsWidget#getConfiguration()
98      */

99     public String JavaDoc getConfiguration() {
100
101         StringBuffer JavaDoc result = new StringBuffer JavaDoc(8);
102
103         // append site selector flag to configuration
104
if (m_showSiteSelector) {
105             result.append(CONFIGURATION_SHOWSITESELECTOR);
106         } else {
107             result.append(CONFIGURATION_HIDESITESELECTOR);
108         }
109
110         // append start site to configuration
111
if (m_startSite != null) {
112             result.append("|");
113             result.append(CONFIGURATION_STARTSITE);
114             result.append("=");
115             result.append(m_startSite);
116         }
117
118         return result.toString();
119     }
120
121     /**
122      * @see org.opencms.widgets.I_CmsWidget#getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
123      */

124     public String JavaDoc getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) {
125
126         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
127         result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "commons/tree.js"));
128         result.append("\n");
129         result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "components/widgets/fileselector.js"));
130         return result.toString();
131     }
132
133     /**
134      * @see org.opencms.widgets.I_CmsWidget#getDialogInitCall(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
135      */

136     public String JavaDoc getDialogInitCall(CmsObject cms, I_CmsWidgetDialog widgetDialog) {
137
138         return "\tinitVfsFileSelector();\n";
139     }
140
141     /**
142      * @see org.opencms.widgets.I_CmsWidget#getDialogInitMethod(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
143      */

144     public String JavaDoc getDialogInitMethod(CmsObject cms, I_CmsWidgetDialog widgetDialog) {
145
146         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
147         result.append("function initVfsFileSelector() {\n");
148         //initialize tree javascript, does parts of CmsTree.initTree(CmsObject, encoding, skinuri);
149
result.append("\tinitResources(\"");
150         result.append(OpenCms.getWorkplaceManager().getEncoding());
151         result.append("\", \"");
152         result.append(CmsWorkplace.VFS_PATH_WORKPLACE);
153         result.append("\", \"");
154         result.append(CmsWorkplace.getSkinUri());
155         result.append("\", \"");
156         result.append(OpenCms.getSystemInfo().getOpenCmsContext());
157         result.append("\");\n");
158         result.append("}\n");
159         return result.toString();
160     }
161
162     /**
163      * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
164      */

165     public String JavaDoc getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
166
167         String JavaDoc id = param.getId();
168         StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
169
170         result.append("<td class=\"xmlTd\">");
171         result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\"><tr><td style=\"width: 100%;\">");
172         result.append("<input style=\"width: 99%;\" class=\"xmlInput");
173         if (param.hasError()) {
174             result.append(" xmlInputError");
175         }
176         result.append("\" value=\"");
177         result.append(param.getStringValue(cms));
178         result.append("\" name=\"");
179         result.append(id);
180         result.append("\" id=\"");
181         result.append(id);
182         result.append("\"></td>");
183         result.append(widgetDialog.dialogHorizontalSpacer(10));
184         result.append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
185
186         StringBuffer JavaDoc buttonJs = new StringBuffer JavaDoc(8);
187         buttonJs.append("javascript:openTreeWin('EDITOR', '");
188         buttonJs.append(id);
189         buttonJs.append("', document");
190         if (m_showSiteSelector) {
191             buttonJs.append(", true");
192         } else {
193             buttonJs.append(", false");
194         }
195         buttonJs.append(", '");
196         if (m_startSite != null) {
197             buttonJs.append(m_startSite);
198         } else {
199             buttonJs.append(cms.getRequestContext().getSiteRoot());
200         }
201         buttonJs.append("'");
202         buttonJs.append(");");
203
204         result.append(widgetDialog.button(
205             buttonJs.toString(),
206             null,
207             "folder",
208             org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_SEARCH_0,
209             widgetDialog.getButtonStyle()));
210         result.append("</tr></table>");
211         result.append("</td></tr></table>");
212
213         result.append("</td>");
214
215         return result.toString();
216     }
217
218     /**
219      * Returns the start site root shown by the widget when first displayed.<p>
220      *
221      * If <code>null</code> is returned, the dialog will display the current site of
222      * the current user.<p>
223      *
224      * @return the start site root shown by the widget when first displayed
225      */

226     public String JavaDoc getStartSite() {
227
228         return m_startSite;
229     }
230
231     /**
232      * Returns <code>true</code> if the site selector is shown.<p>
233      *
234      * The default is <code>true</code>.<p>
235      *
236      * @return <code>true</code> if the site selector is shown
237      */

238     public boolean isShowingSiteSelector() {
239
240         return m_showSiteSelector;
241     }
242
243     /**
244      * @see org.opencms.widgets.I_CmsWidget#newInstance()
245      */

246     public I_CmsWidget newInstance() {
247
248         return new CmsVfsFileWidget(getConfiguration());
249     }
250
251     /**
252      * @see org.opencms.widgets.A_CmsWidget#setConfiguration(java.lang.String)
253      */

254     public void setConfiguration(String JavaDoc configuration) {
255
256         m_showSiteSelector = true;
257         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration)) {
258             if (configuration.indexOf(CONFIGURATION_HIDESITESELECTOR) != -1) {
259                 // site selector should be hidden
260
m_showSiteSelector = false;
261             }
262             int siteIndex = configuration.indexOf(CONFIGURATION_STARTSITE);
263             if (siteIndex != -1) {
264                 // start site is given
265
String JavaDoc site = configuration.substring(CONFIGURATION_STARTSITE.length() + 1);
266                 if (site.indexOf('|') != -1) {
267                     // cut eventual following configuration values
268
site = site.substring(0, site.indexOf('|'));
269                 }
270                 m_startSite = site;
271             }
272         }
273         super.setConfiguration(configuration);
274     }
275 }
Popular Tags