001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListDirectAction.java,v $
003: * Date : $Date: 2008-02-27 12:05:28 $
004: * Version: $Revision: 1.22 $
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.workplace.list;
033:
034: import org.opencms.util.CmsStringUtil;
035: import org.opencms.workplace.CmsWorkplace;
036: import org.opencms.workplace.tools.A_CmsHtmlIconButton;
037: import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum;
038:
039: import java.text.MessageFormat;
040: import java.util.Locale;
041:
042: /**
043: * Default implementation of a direct action for a html list column.<p>
044: *
045: * @author Michael Moossen
046: *
047: * @version $Revision: 1.22 $
048: *
049: * @since 6.0.0
050: */
051: public class CmsListDirectAction extends A_CmsListAction implements
052: I_CmsListDirectAction {
053:
054: /** Id of the Column to use when setting param in help and conf texts. */
055: private String m_columnForTexts;
056:
057: /** List item. */
058: private CmsListItem m_listItem;
059:
060: /**
061: * Default Constructor.<p>
062: *
063: * @param id unique id
064: */
065: public CmsListDirectAction(String id) {
066:
067: super (id);
068: }
069:
070: /**
071: * Help method to resolve the help text to use.<p>
072: *
073: * @param locale the used locale
074: *
075: * @return the help text
076: */
077: protected String resolveHelpText(Locale locale) {
078:
079: String helpText = getHelpText().key(locale);
080: if ((getColumnForTexts() != null)
081: && (getItem().get(getColumnForTexts()) != null)) {
082: helpText = new MessageFormat(helpText, locale)
083: .format(new Object[] { getItem().get(
084: getColumnForTexts()) });
085: }
086: return helpText;
087: }
088:
089: /**
090: * Help method to resolve the on clic text to use.<p>
091: *
092: * @param locale the used locale
093: *
094: * @return the on clic text
095: */
096: protected String resolveOnClic(Locale locale) {
097:
098: String confirmationMessage = getConfirmationMessage().key(
099: locale);
100: if ((getColumnForTexts() != null)
101: && (getItem().get(getColumnForTexts()) != null)) {
102: confirmationMessage = new MessageFormat(
103: confirmationMessage, locale)
104: .format(new Object[] { getItem().get(
105: getColumnForTexts()) });
106: }
107: StringBuffer onClic = new StringBuffer(128);
108: onClic.append("listAction('");
109: onClic.append(getListId());
110: onClic.append("', '");
111: onClic.append(getId());
112: onClic.append("', '");
113: if ((getColumnForTexts() == null)
114: || (getItem().get(getColumnForTexts()) == null)
115: || confirmationMessage.equals(new MessageFormat(
116: confirmationMessage, locale)
117: .format(new Object[] { "" }))) {
118: onClic.append("conf" + getId());
119: } else {
120: onClic.append(CmsStringUtil
121: .escapeJavaScript(confirmationMessage));
122: }
123: onClic.append("', '");
124: onClic
125: .append(CmsStringUtil.escapeJavaScript(getItem()
126: .getId()));
127: onClic.append("');");
128: return onClic.toString();
129: }
130:
131: /**
132: * Help method to resolve the name to use.<p>
133: *
134: * @param locale the used locale
135: *
136: * @return the name
137: */
138: protected String resolveName(Locale locale) {
139:
140: return getName().key(locale);
141: }
142:
143: /**
144: * Help method to resolve the style of the button.<p>
145: *
146: * @return the style of the button
147: */
148: protected CmsHtmlIconButtonStyleEnum resolveButtonStyle() {
149:
150: return CmsHtmlIconButtonStyleEnum.SMALL_ICON_ONLY;
151: }
152:
153: /**
154: * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#buttonHtml(CmsWorkplace)
155: */
156: public String buttonHtml(CmsWorkplace wp) {
157:
158: if (!isVisible()) {
159: return "";
160: }
161: return A_CmsHtmlIconButton.defaultButtonHtml(
162: resolveButtonStyle(), getId() + getItem().getId(),
163: getId(), resolveName(wp.getLocale()),
164: resolveHelpText(wp.getLocale()), isEnabled(),
165: getIconPath(), null, resolveOnClic(wp.getLocale()),
166: getColumnForTexts() == null, null);
167: }
168:
169: /**
170: * @see org.opencms.workplace.list.I_CmsListDirectAction#confirmationTextHtml()
171: */
172: public String confirmationTextHtml() {
173:
174: StringBuffer html = new StringBuffer(512);
175: String cm = getConfirmationMessage().key(getWp().getLocale());
176: String confMessage = new MessageFormat(cm, getWp().getLocale())
177: .format(new Object[] { "" });
178: if ((getColumnForTexts() == null)
179: || confMessage.equals(new MessageFormat(cm, getWp()
180: .getLocale()).format(new Object[] { getItem()
181: .get(getColumnForTexts()) }))) {
182: html.append(A_CmsListAction.defaultConfirmationHtml(
183: getId(), confMessage));
184: }
185: return html.toString();
186: }
187:
188: /**
189: * @see org.opencms.workplace.list.I_CmsListDirectAction#getColumnForTexts()
190: */
191: public String getColumnForTexts() {
192:
193: return m_columnForTexts;
194: }
195:
196: /**
197: * @see org.opencms.workplace.list.I_CmsListDirectAction#getItem()
198: */
199: public CmsListItem getItem() {
200:
201: return m_listItem;
202: }
203:
204: /**
205: * @see org.opencms.workplace.list.I_CmsListDirectAction#helpTextHtml()
206: */
207: public String helpTextHtml() {
208:
209: StringBuffer html = new StringBuffer(512);
210: String ht = getHelpText().key(getWp().getLocale());
211: String helptext = new MessageFormat(ht, getWp().getLocale())
212: .format(new Object[] { "" });
213: if ((getColumnForTexts() == null)
214: || helptext.equals(new MessageFormat(ht, getWp()
215: .getLocale()).format(new Object[] { getItem()
216: .get(getColumnForTexts()) }))) {
217: html.append(A_CmsHtmlIconButton.defaultHelpHtml(getId(),
218: helptext));
219: }
220: return html.toString();
221: }
222:
223: /**
224: * @see org.opencms.workplace.list.I_CmsListDirectAction#setColumnForTexts(java.lang.String)
225: */
226: public void setColumnForTexts(String columnId) {
227:
228: m_columnForTexts = columnId;
229: }
230:
231: /**
232: * @see org.opencms.workplace.list.I_CmsListDirectAction#setItem(org.opencms.workplace.list.CmsListItem)
233: */
234: public void setItem(CmsListItem item) {
235:
236: m_listItem = item;
237: }
238:
239: }
|