001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/widgets/CmsDisplayWidget.java,v $
003: * Date : $Date: 2008-02-27 12:05:44 $
004: * Version: $Revision: 1.16 $
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.i18n.CmsEncoder;
036: import org.opencms.main.OpenCms;
037: import org.opencms.util.CmsStringUtil;
038:
039: import java.util.Set;
040:
041: /**
042: * Provides a display only widget, for use on a widget dialog.<p>
043: *
044: * @author Michael Moossen
045: *
046: * @version $Revision: 1.16 $
047: *
048: * @since 6.0.0
049: */
050: public class CmsDisplayWidget extends A_CmsWidget {
051:
052: /** Key post fix, so you can display different help text if used a "normal" widget, and a display widget. */
053: private static final String DISABLED_POSTFIX = ".disabled";
054:
055: /**
056: * Creates a new input widget.<p>
057: */
058: public CmsDisplayWidget() {
059:
060: // empty constructor is required for class registration
061: this ("");
062: }
063:
064: /**
065: * Creates a new input widget with the given configuration.<p>
066: *
067: * @param configuration the configuration to use
068: */
069: public CmsDisplayWidget(String configuration) {
070:
071: super (configuration);
072: }
073:
074: /**
075: * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
076: */
077: public String getDialogWidget(CmsObject cms,
078: I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
079:
080: String value = param.getStringValue(cms);
081: String localizedValue = value;
082: if (CmsStringUtil.TRUE.equalsIgnoreCase(value)
083: || CmsStringUtil.FALSE.equalsIgnoreCase(value)) {
084: boolean booleanValue = Boolean.valueOf(value)
085: .booleanValue();
086: if (booleanValue) {
087: localizedValue = Messages.get().getBundle(
088: widgetDialog.getLocale()).key(
089: Messages.GUI_LABEL_TRUE_0);
090: } else {
091: localizedValue = Messages.get().getBundle(
092: widgetDialog.getLocale()).key(
093: Messages.GUI_LABEL_FALSE_0);
094: }
095: }
096:
097: String id = param.getId();
098: StringBuffer result = new StringBuffer(16);
099: result.append("<td class=\"xmlTd\">");
100: result
101: .append("<span class=\"xmlInput textInput\" style=\"border: 0px solid black;\">");
102: if (CmsStringUtil.isNotEmpty(getConfiguration())) {
103: result.append(getConfiguration());
104: } else {
105: result.append(localizedValue);
106: }
107: result.append("</span>");
108: result.append("<input type=\"hidden\"");
109: result.append(" name=\"");
110: result.append(id);
111: result.append("\" id=\"");
112: result.append(id);
113: result.append("\" value=\"");
114: result.append(CmsEncoder.escapeXml(value));
115: result.append("\">");
116: result.append("</td>");
117:
118: return result.toString();
119: }
120:
121: /**
122: * @see org.opencms.widgets.A_CmsWidget#getHelpBubble(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
123: */
124: public String getHelpBubble(CmsObject cms,
125: I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
126:
127: StringBuffer result = new StringBuffer(128);
128: String locKey = getDisabledHelpKey(param);
129: String locValue = widgetDialog.getMessages().key(locKey, true);
130: if (locValue == null) {
131: // there was no help message found for this key, so return a spacer cell
132: return widgetDialog.dialogHorizontalSpacer(16);
133: } else {
134: result.append("<td>");
135: result.append("<img name=\"img");
136: result.append(locKey);
137: result.append("\" id=\"img");
138: result.append(locKey);
139: result.append("\" src=\"");
140: result.append(OpenCms.getLinkManager().substituteLink(cms,
141: "/system/workplace/resources/commons/help.png"));
142: result.append("\" alt=\"\" border=\"0\"");
143: if (widgetDialog.useNewStyle()) {
144: result.append(getJsHelpMouseHandler(widgetDialog,
145: locKey, null));
146: } else {
147: result.append(getJsHelpMouseHandler(widgetDialog,
148: locKey, CmsEncoder.escape(locValue, cms
149: .getRequestContext().getEncoding())));
150: }
151: result.append("></td>");
152: return result.toString();
153: }
154: }
155:
156: /**
157: * @see org.opencms.widgets.A_CmsWidget#getHelpText(org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
158: */
159: public String getHelpText(I_CmsWidgetDialog widgetDialog,
160: I_CmsWidgetParameter param) {
161:
162: String helpId = getDisabledHelpKey(param);
163: Set helpIdsShown = widgetDialog.getHelpMessageIds();
164: if (helpIdsShown.contains(helpId)) {
165: // help hey has already been included in output
166: return "";
167: }
168: helpIdsShown.add(helpId);
169:
170: // calculate the key
171: String locValue = widgetDialog.getMessages().key(helpId, true);
172: if (locValue == null) {
173: // there was no help message found for this key, so return an empty string
174: return "";
175: } else {
176: if (widgetDialog.useNewStyle()) {
177: StringBuffer result = new StringBuffer(128);
178: result.append("<div class=\"help\" id=\"help");
179: result.append(helpId);
180: result.append("\"");
181: result.append(getJsHelpMouseHandler(widgetDialog,
182: helpId, helpId));
183: result.append(">");
184: result.append(locValue);
185: result.append("</div>\n");
186: return result.toString();
187: } else {
188: return "";
189: }
190: }
191: }
192:
193: /**
194: * @see org.opencms.widgets.I_CmsWidget#newInstance()
195: */
196: public I_CmsWidget newInstance() {
197:
198: return new CmsDisplayWidget(getConfiguration());
199: }
200:
201: /**
202: * Returns the localized help key for the provided widget parameter.<p>
203: *
204: * @param param the widget parameter to return the localized help key for
205: *
206: * @return the localized help key for the provided widget parameter
207: */
208: private String getDisabledHelpKey(I_CmsWidgetParameter param) {
209:
210: StringBuffer result = new StringBuffer(64);
211: result.append(LABEL_PREFIX);
212: result.append(param.getKey());
213: result.append(HELP_POSTFIX);
214: result.append(DISABLED_POSTFIX);
215: return result.toString();
216: }
217: }
|