1 31 32 package org.opencms.workplace.tools; 33 34 import org.opencms.i18n.CmsMessageContainer; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.util.CmsStringUtil; 37 import org.opencms.workplace.CmsWorkplace; 38 39 import java.io.File ; 40 41 50 public abstract class A_CmsHtmlIconButton implements I_CmsHtmlIconButton { 51 52 53 public static final CmsMessageContainer EMPTY_MESSAGE = Messages.get().container(Messages.GUI_EMPTY_MESSAGE_0); 54 55 56 protected String m_id; 57 58 59 private boolean m_enabled = true; 60 61 62 private CmsMessageContainer m_helpText; 63 64 65 private String m_iconPath; 66 67 68 private CmsMessageContainer m_name; 69 70 71 private boolean m_visible = true; 72 73 78 public A_CmsHtmlIconButton(String id) { 79 80 m_id = id; 81 } 82 83 92 public A_CmsHtmlIconButton( 93 String id, 94 CmsMessageContainer name, 95 CmsMessageContainer helpText, 96 String iconPath, 97 boolean enabled) { 98 99 this(id); 100 setName(name); 101 setHelpText(helpText); 102 setIconPath(iconPath); 103 setEnabled(enabled); 104 } 105 106 121 public static String defaultButtonHtml( 122 CmsJspActionElement jsp, 123 CmsHtmlIconButtonStyleEnum style, 124 String id, 125 String name, 126 String helpText, 127 boolean enabled, 128 String iconPath, 129 String confirmationMessage, 130 String onClick) { 131 132 return defaultButtonHtml(jsp, style, id, id, name, helpText, enabled, iconPath, confirmationMessage, onClick, false); 133 } 134 135 152 public static String defaultButtonHtml( 153 CmsJspActionElement jsp, 154 CmsHtmlIconButtonStyleEnum style, 155 String id, 156 String helpId, 157 String name, 158 String helpText, 159 boolean enabled, 160 String iconPath, 161 String confirmationMessage, 162 String onClick, 163 boolean singleHelp) { 164 165 StringBuffer html = new StringBuffer (1024); 166 if (style == CmsHtmlIconButtonStyleEnum.BIG_ICON_TEXT) { 167 html.append("<div class='bigLink' id='img"); 168 html.append(id); 169 html.append("'>\n"); 170 } 171 html.append("\t<span class=\"link"); 172 if (enabled) { 173 html.append("\""); 174 } else { 175 html.append(" linkdisabled\""); 176 } 177 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText)) { 178 if (!singleHelp) { 179 html.append(" onMouseOver=\"sMH('"); 180 html.append(id); 181 html.append("');\" onMouseOut=\"hMH('"); 182 html.append(id); 183 html.append("');\""); 184 } else { 185 html.append(" onMouseOver=\"sMHS('"); 186 html.append(id); 187 html.append("', '"); 188 html.append(helpId); 189 html.append("');\" onMouseOut=\"hMH('"); 190 html.append(id); 191 html.append("', '"); 192 html.append(helpId); 193 html.append("');\""); 194 } 195 } 196 if (enabled && CmsStringUtil.isNotEmptyOrWhitespaceOnly(onClick)) { 197 html.append(" onClick=\""); 198 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) { 199 html.append("if (confirm('" + CmsStringUtil.escapeJavaScript(confirmationMessage) + "')) {"); 200 } 201 html.append(onClick); 202 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) { 203 html.append(" }"); 204 } 205 html.append("\""); 206 } 207 if (style == CmsHtmlIconButtonStyleEnum.SMALL_ICON_ONLY) { 208 html.append(" title='"); 209 html.append(name); 210 html.append("'"); 211 } 212 html.append(">"); 213 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(iconPath)) { 214 html.append("<img SRC='"); 215 html.append(CmsWorkplace.getSkinUri()); 216 if (!enabled) { 217 StringBuffer icon = new StringBuffer (128); 218 icon.append(iconPath.substring(0, iconPath.lastIndexOf('.'))); 219 icon.append("_disabled"); 220 icon.append(iconPath.substring(iconPath.lastIndexOf('.'))); 221 if (jsp != null) { 222 String resorcesRoot = jsp.getJspContext().getServletConfig().getServletContext().getRealPath( 223 "/resources/"); 224 File test = new File (resorcesRoot + "/" + icon.toString()); 225 if (test.exists()) { 226 html.append(icon); 227 } else { 228 html.append(iconPath); 229 } 230 } else { 231 html.append(iconPath); 232 } 233 } else { 234 html.append(iconPath); 235 } 236 html.append("'"); 237 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(name)) { 238 html.append(" alt='"); 239 html.append(name); 240 html.append("'"); 241 html.append(" title='"); 242 html.append(name); 243 html.append("'"); 244 } 245 html.append(">"); 246 if (style == CmsHtmlIconButtonStyleEnum.BIG_ICON_TEXT) { 247 html.append("<br>"); 248 } 249 } 250 if (style != CmsHtmlIconButtonStyleEnum.SMALL_ICON_ONLY && CmsStringUtil.isNotEmptyOrWhitespaceOnly(name)) { 251 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(iconPath) && style != CmsHtmlIconButtonStyleEnum.BIG_ICON_TEXT) { 252 html.append(" "); 253 } 254 if (enabled) { 255 html.append("<a HREF='#'>"); 256 } 257 html.append(name); 258 if (enabled) { 259 html.append("</a>"); 260 } 261 } 262 html.append("</span>"); 263 if (style == CmsHtmlIconButtonStyleEnum.BIG_ICON_TEXT) { 264 html.append("</div>\n"); 265 } 266 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText) && !singleHelp) { 267 html.append("<div class='help' id='help"); 268 html.append(helpId); 269 html.append("' onMouseOver=\"sMH('"); 270 html.append(id); 271 html.append("');\" onMouseOut=\"hMH('"); 272 html.append(id); 273 html.append("');\">"); 274 html.append(helpText); 275 html.append("</div>\n"); 276 } 277 return html.toString(); 278 } 279 280 288 public static String defaultHelpHtml(String helpId, String helpText) { 289 290 StringBuffer html = new StringBuffer (1024); 291 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText)) { 292 html.append("<div class='help' id='help"); 293 html.append(helpId); 294 html.append("' onMouseOut=\"hMH('"); 295 html.append(helpId); 296 html.append("');\">"); 297 html.append(helpText); 298 html.append("</div>\n"); 299 } 300 return html.toString(); 301 } 302 303 306 public CmsMessageContainer getHelpText() { 307 308 if (m_helpText == null) { 309 m_helpText = EMPTY_MESSAGE; 310 } 311 return m_helpText; 312 } 313 314 317 public String getIconPath() { 318 319 return m_iconPath; 320 } 321 322 325 public String getId() { 326 327 return m_id; 328 } 329 330 333 public CmsMessageContainer getName() { 334 335 return m_name; 336 } 337 338 341 public boolean isEnabled() { 342 343 return m_enabled; 344 } 345 346 349 public boolean isVisible() { 350 351 return m_visible; 352 } 353 354 357 public void setEnabled(boolean enabled) { 358 359 m_enabled = enabled; 360 } 361 362 365 public void setHelpText(CmsMessageContainer helpText) { 366 367 if (helpText == null) { 368 helpText = EMPTY_MESSAGE; 369 } 370 m_helpText = helpText; 371 } 372 373 376 public void setIconPath(String iconPath) { 377 378 m_iconPath = iconPath; 379 } 380 381 384 public void setName(CmsMessageContainer name) { 385 386 if (name == null) { 387 name = EMPTY_MESSAGE; 388 } 389 m_name = name; 390 } 391 392 395 public void setVisible(boolean visible) { 396 397 m_visible = visible; 398 } 399 } | Popular Tags |