001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/widgets/CmsVfsFileWidget.java,v $
003: * Date : $Date: 2008-02-27 12:05:44 $
004: * Version: $Revision: 1.21 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.widgets;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.main.OpenCms;
036: import org.opencms.util.CmsStringUtil;
037: import org.opencms.workplace.CmsWorkplace;
038:
039: /**
040: * Provides a OpenCms VFS file selection widget, for use on a widget dialog.<p>
041: *
042: * @author Andreas Zahner
043: *
044: * @version $Revision: 1.21 $
045: *
046: * @since 6.0.0
047: */
048: public class CmsVfsFileWidget extends A_CmsWidget {
049:
050: /** Configuration parameter to set the flag to include files in popup resource tree. */
051: public static final String CONFIGURATION_EXCLUDEFILES = "excludefiles";
052:
053: /** Configuration parameter to set the flag to show the site selector in popup resource tree. */
054: public static final String CONFIGURATION_HIDESITESELECTOR = "hidesiteselector";
055:
056: /** Configuration parameter to set the flag to include files in popup resource tree. */
057: public static final String CONFIGURATION_INCLUDEFILES = "includefiles";
058:
059: /** Configuration parameter to prevent the project awareness flag in the popup resource tree. */
060: public static final String CONFIGURATION_NOTPROJECTAWARE = "notprojectaware";
061:
062: /** Configuration parameter to set the project awareness flag in the popup resource tree. */
063: public static final String CONFIGURATION_PROJECTAWARE = "projectaware";
064:
065: /** Configuration parameter to set the flag to show the site selector in popup resource tree. */
066: public static final String CONFIGURATION_SHOWSITESELECTOR = "showsiteselector";
067:
068: /** Configuration parameter to set start site of the popup resource tree. */
069: public static final String CONFIGURATION_STARTSITE = "startsite";
070:
071: /** Flag to determine if files should be shown in popup window. */
072: private boolean m_includeFiles;
073:
074: /** Flag to determine project awareness, ie. if resources outside of the current project should be displayed as normal. */
075: private boolean m_projectAware;
076:
077: /** Flag to determine if the site selector should be shown in popup window. */
078: private boolean m_showSiteSelector;
079:
080: /** The start site used in the popup window. */
081: private String m_startSite;
082:
083: /**
084: * Creates a new vfs file widget.<p>
085: */
086: public CmsVfsFileWidget() {
087:
088: // empty constructor is required for class registration
089: this ("");
090: }
091:
092: /**
093: * Creates a new vfs file widget with the parameters to configure the popup tree window behavior.<p>
094: *
095: * @param showSiteSelector true if the site selector should be shown in the popup window
096: * @param startSite the start site root for the popup window
097: */
098: public CmsVfsFileWidget(boolean showSiteSelector, String startSite) {
099:
100: this (showSiteSelector, startSite, true);
101: }
102:
103: /**
104: * Creates a new vfs file widget with the parameters to configure the popup tree window behavior.<p>
105: *
106: * @param showSiteSelector true if the site selector should be shown in the popup window
107: * @param startSite the start site root for the popup window
108: * @param includeFiles true if files should be shown in the popup window
109: */
110: public CmsVfsFileWidget(boolean showSiteSelector, String startSite,
111: boolean includeFiles) {
112:
113: this (showSiteSelector, startSite, includeFiles, true);
114: }
115:
116: /**
117: * Creates a new vfs file widget with the parameters to configure the popup tree window behavior.<p>
118: *
119: * @param showSiteSelector true if the site selector should be shown in the popup window
120: * @param startSite the start site root for the popup window
121: * @param includeFiles <code>true</code> if files should be shown in the popup window
122: * @param projectAware <code>true</code> if resources outside of the current project should be displayed as normal
123: */
124: public CmsVfsFileWidget(boolean showSiteSelector, String startSite,
125: boolean includeFiles, boolean projectAware) {
126:
127: m_showSiteSelector = showSiteSelector;
128: m_startSite = startSite;
129: m_includeFiles = includeFiles;
130: m_projectAware = projectAware;
131: }
132:
133: /**
134: * Creates a new vfs file widget with the given configuration.<p>
135: *
136: * @param configuration the configuration to use
137: */
138: public CmsVfsFileWidget(String configuration) {
139:
140: super (configuration);
141: }
142:
143: /**
144: * @see org.opencms.widgets.A_CmsWidget#getConfiguration()
145: */
146: public String getConfiguration() {
147:
148: StringBuffer result = new StringBuffer(8);
149:
150: // append site selector flag to configuration
151: if (m_showSiteSelector) {
152: result.append(CONFIGURATION_SHOWSITESELECTOR);
153: } else {
154: result.append(CONFIGURATION_HIDESITESELECTOR);
155: }
156:
157: // append start site to configuration
158: if (m_startSite != null) {
159: result.append("|");
160: result.append(CONFIGURATION_STARTSITE);
161: result.append("=");
162: result.append(m_startSite);
163: }
164:
165: // append flag for including files
166: result.append("|");
167: if (m_includeFiles) {
168: result.append(CONFIGURATION_INCLUDEFILES);
169: } else {
170: result.append(CONFIGURATION_EXCLUDEFILES);
171: }
172:
173: // append flag for project awareness
174: result.append("|");
175: if (m_projectAware) {
176: result.append(CONFIGURATION_PROJECTAWARE);
177: } else {
178: result.append(CONFIGURATION_NOTPROJECTAWARE);
179: }
180:
181: return result.toString();
182: }
183:
184: /**
185: * @see org.opencms.widgets.I_CmsWidget#getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
186: */
187: public String getDialogIncludes(CmsObject cms,
188: I_CmsWidgetDialog widgetDialog) {
189:
190: StringBuffer result = new StringBuffer(16);
191: result.append(getJSIncludeFile(CmsWorkplace.getSkinUri()
192: + "commons/tree.js"));
193: result.append("\n");
194: result.append(getJSIncludeFile(CmsWorkplace.getSkinUri()
195: + "components/widgets/fileselector.js"));
196: return result.toString();
197: }
198:
199: /**
200: * @see org.opencms.widgets.I_CmsWidget#getDialogInitCall(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
201: */
202: public String getDialogInitCall(CmsObject cms,
203: I_CmsWidgetDialog widgetDialog) {
204:
205: return "\tinitVfsFileSelector();\n";
206: }
207:
208: /**
209: * @see org.opencms.widgets.I_CmsWidget#getDialogInitMethod(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
210: */
211: public String getDialogInitMethod(CmsObject cms,
212: I_CmsWidgetDialog widgetDialog) {
213:
214: StringBuffer result = new StringBuffer(16);
215: result.append("function initVfsFileSelector() {\n");
216: //initialize tree javascript, does parts of <code>CmsTree.initTree(CmsObject, encoding, skinuri);</code>
217: result.append("\tinitResources(\"");
218: result.append(OpenCms.getWorkplaceManager().getEncoding());
219: result.append("\", \"");
220: result.append(CmsWorkplace.VFS_PATH_WORKPLACE);
221: result.append("\", \"");
222: result.append(CmsWorkplace.getSkinUri());
223: result.append("\", \"");
224: result.append(OpenCms.getSystemInfo().getOpenCmsContext());
225: result.append("\");\n");
226: result.append("}\n");
227: return result.toString();
228: }
229:
230: /**
231: * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
232: */
233: public String getDialogWidget(CmsObject cms,
234: I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
235:
236: String id = param.getId();
237: StringBuffer result = new StringBuffer(128);
238:
239: result.append("<td class=\"xmlTd\">");
240: result
241: .append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\"><tr><td style=\"width: 100%;\">");
242: result.append("<input style=\"width: 99%;\" class=\"xmlInput");
243: if (param.hasError()) {
244: result.append(" xmlInputError");
245: }
246: result.append("\" value=\"");
247: result.append(param.getStringValue(cms));
248: result.append("\" name=\"");
249: result.append(id);
250: result.append("\" id=\"");
251: result.append(id);
252: result.append("\"></td>");
253: result.append(widgetDialog.dialogHorizontalSpacer(10));
254: result
255: .append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
256:
257: StringBuffer buttonJs = new StringBuffer(8);
258: buttonJs.append("javascript:openTreeWin('EDITOR', '");
259: buttonJs.append(id);
260: buttonJs.append("', document, ");
261: buttonJs.append(m_showSiteSelector);
262: buttonJs.append(", '");
263: if (m_startSite != null) {
264: buttonJs.append(m_startSite);
265: } else {
266: buttonJs.append(cms.getRequestContext().getSiteRoot());
267: }
268: buttonJs.append("', ");
269: // include files
270: buttonJs.append(m_includeFiles);
271: // project awareness
272: buttonJs.append(", ");
273: buttonJs.append(m_projectAware);
274: buttonJs.append(");return false;");
275:
276: result
277: .append(widgetDialog
278: .button(
279: buttonJs.toString(),
280: null,
281: "folder",
282: org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_SEARCH_0,
283: widgetDialog.getButtonStyle()));
284: result.append("</tr></table>");
285: result.append("</td></tr></table>");
286:
287: result.append("</td>");
288:
289: return result.toString();
290: }
291:
292: /**
293: * Returns the start site root shown by the widget when first displayed.<p>
294: *
295: * If <code>null</code> is returned, the dialog will display the current site of
296: * the current user.<p>
297: *
298: * @return the start site root shown by the widget when first displayed
299: */
300: public String getStartSite() {
301:
302: return m_startSite;
303: }
304:
305: /**
306: * Returns <code>true</code> if the site selector is shown.<p>
307: *
308: * The default is <code>true</code>.<p>
309: *
310: * @return <code>true</code> if the site selector is shown
311: */
312: public boolean isShowingSiteSelector() {
313:
314: return m_showSiteSelector;
315: }
316:
317: /**
318: * @see org.opencms.widgets.I_CmsWidget#newInstance()
319: */
320: public I_CmsWidget newInstance() {
321:
322: return new CmsVfsFileWidget(getConfiguration());
323: }
324:
325: /**
326: * @see org.opencms.widgets.A_CmsWidget#setConfiguration(java.lang.String)
327: */
328: public void setConfiguration(String configuration) {
329:
330: m_showSiteSelector = true;
331: m_includeFiles = true;
332: m_projectAware = true;
333:
334: if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration)) {
335: if (configuration.indexOf(CONFIGURATION_HIDESITESELECTOR) != -1) {
336: // site selector should be hidden
337: m_showSiteSelector = false;
338: }
339: int siteIndex = configuration
340: .indexOf(CONFIGURATION_STARTSITE);
341: if (siteIndex != -1) {
342: // start site is given
343: String site = configuration
344: .substring(CONFIGURATION_STARTSITE.length() + 1);
345: if (site.indexOf('|') != -1) {
346: // cut eventual following configuration values
347: site = site.substring(0, site.indexOf('|'));
348: }
349: m_startSite = site;
350: }
351: if (configuration.indexOf(CONFIGURATION_EXCLUDEFILES) != -1) {
352: // files should not be included
353: m_includeFiles = false;
354: }
355: if (configuration.indexOf(CONFIGURATION_NOTPROJECTAWARE) != -1) {
356: // resources outside of the current project should not be disabled
357: m_projectAware = false;
358: }
359: }
360: super.setConfiguration(configuration);
361: }
362: }
|