1 31 32 package org.opencms.workplace.list; 33 34 import org.opencms.util.CmsStringUtil; 35 import org.opencms.workplace.CmsWorkplace; 36 import org.opencms.workplace.tools.A_CmsHtmlIconButton; 37 import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum; 38 39 import java.text.MessageFormat ; 40 import java.util.Locale ; 41 42 51 public class CmsListDirectAction extends A_CmsListAction implements I_CmsListDirectAction { 52 53 54 private String m_columnForTexts; 55 56 57 private CmsListItem m_listItem; 58 59 64 public CmsListDirectAction(String id) { 65 66 super(id); 67 } 68 69 76 protected String resolveHelpText(Locale locale) { 77 78 String helpText = getHelpText().key(locale); 79 if (getColumnForTexts() != null && getItem().get(getColumnForTexts()) != null) { 80 helpText = new MessageFormat (helpText, locale).format(new Object [] {getItem().get(getColumnForTexts())}); 81 } 82 return helpText; 83 } 84 85 92 protected String resolveOnClic(Locale locale) { 93 94 String confirmationMessage = getConfirmationMessage().key(locale); 95 if (getColumnForTexts() != null && getItem().get(getColumnForTexts()) != null) { 96 confirmationMessage = new MessageFormat (confirmationMessage, locale).format(new Object [] {getItem().get( 97 getColumnForTexts())}); 98 } 99 StringBuffer onClic = new StringBuffer (128); 100 onClic.append("listAction('"); 101 onClic.append(getListId()); 102 onClic.append("', '"); 103 onClic.append(getId()); 104 onClic.append("', '"); 105 if (getColumnForTexts() == null 106 || getItem().get(getColumnForTexts()) == null 107 || confirmationMessage.equals(new MessageFormat (confirmationMessage, locale).format(new Object [] {""}))) { 108 onClic.append("conf" + getId()); 109 } else { 110 onClic.append(CmsStringUtil.escapeJavaScript(confirmationMessage)); 111 } 112 onClic.append("', '"); 113 onClic.append(CmsStringUtil.escapeJavaScript(getItem().getId())); 114 onClic.append("');"); 115 return onClic.toString(); 116 } 117 118 125 protected String resolveName(Locale locale) { 126 127 return getName().key(locale); 128 } 129 130 135 protected CmsHtmlIconButtonStyleEnum resolveButtonStyle() { 136 137 return CmsHtmlIconButtonStyleEnum.SMALL_ICON_ONLY; 138 } 139 140 143 public String buttonHtml(CmsWorkplace wp) { 144 145 if (!isVisible()) { 146 return ""; 147 } 148 return A_CmsHtmlIconButton.defaultButtonHtml( 149 wp.getJsp(), 150 resolveButtonStyle(), 151 getId() + getItem().getId(), 152 getId(), 153 resolveName(wp.getLocale()), 154 resolveHelpText(wp.getLocale()), 155 isEnabled(), 156 getIconPath(), 157 null, 158 resolveOnClic(wp.getLocale()), 159 getColumnForTexts() == null); 160 } 161 162 165 public String confirmationTextHtml(CmsWorkplace wp) { 166 167 StringBuffer html = new StringBuffer (512); 168 String cm = getConfirmationMessage().key(wp.getLocale()); 169 String confMessage = new MessageFormat (cm, wp.getLocale()).format(new Object [] {""}); 170 if (getColumnForTexts() == null 171 || confMessage.equals(new MessageFormat (cm, wp.getLocale()).format(new Object [] {getItem().get(getColumnForTexts())}))) { 172 html.append(A_CmsListAction.defaultConfirmationHtml(getId(), confMessage)); 173 } 174 return html.toString(); 175 } 176 177 180 public String getColumnForTexts() { 181 182 return m_columnForTexts; 183 } 184 185 188 public CmsListItem getItem() { 189 190 return m_listItem; 191 } 192 193 196 public String helpTextHtml(CmsWorkplace wp) { 197 198 StringBuffer html = new StringBuffer (512); 199 String ht = getHelpText().key(wp.getLocale()); 200 String helptext = new MessageFormat (ht, wp.getLocale()).format(new Object [] {""}); 201 if (getColumnForTexts() == null 202 || helptext.equals(new MessageFormat (ht, wp.getLocale()).format(new Object [] {getItem().get(getColumnForTexts())}))) { 203 html.append(A_CmsHtmlIconButton.defaultHelpHtml(getId(), helptext)); 204 } 205 return html.toString(); 206 } 207 208 211 public void setColumnForTexts(String columnId) { 212 213 m_columnForTexts = columnId; 214 } 215 216 219 public void setItem(CmsListItem item) { 220 221 m_listItem = item; 222 } 223 224 } | Popular Tags |