1 31 32 package org.opencms.widgets; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.main.OpenCms; 36 import org.opencms.util.CmsStringUtil; 37 38 import java.util.Map ; 39 import java.util.Set ; 40 41 50 public abstract class A_CmsWidget implements I_CmsWidget { 51 52 53 public static final String HELP_POSTFIX = ".help"; 54 55 56 public static final String LABEL_PREFIX = "label."; 57 58 59 private String m_configuration; 60 61 64 protected A_CmsWidget() { 65 66 setConfiguration(""); 67 } 68 69 74 protected A_CmsWidget(String configuration) { 75 76 setConfiguration(configuration); 77 } 78 79 85 public static String getHelpKey(I_CmsWidgetParameter param) { 86 87 StringBuffer result = new StringBuffer (64); 89 result.append(LABEL_PREFIX); 90 result.append(param.getKey()); 91 result.append(HELP_POSTFIX); 92 93 return result.toString(); 94 } 95 96 102 public static String getLabelKey(I_CmsWidgetParameter param) { 103 104 StringBuffer result = new StringBuffer (64); 106 result.append(LABEL_PREFIX); 107 result.append(param.getKey()); 108 return result.toString(); 109 } 110 111 114 public boolean equals(Object obj) { 115 116 if (obj == this) { 117 return true; 118 } 119 if (obj instanceof A_CmsWidget) { 120 return getClass().getName().equals(obj.getClass().getName()); 122 } 123 return false; 124 } 125 126 131 public String getConfiguration() { 132 133 return m_configuration; 134 } 135 136 139 public String getDialogHtmlEnd(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter value) { 140 141 return getHelpText(widgetDialog, value); 142 } 143 144 147 public String getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 148 149 return ""; 150 } 151 152 155 public String getDialogInitCall(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 156 157 return ""; 158 } 159 160 163 public String getDialogInitMethod(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 164 165 return ""; 166 } 167 168 171 public String getHelpBubble(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 172 173 StringBuffer result = new StringBuffer (128); 174 String locKey = getHelpKey(param); 175 String locValue = widgetDialog.getMessages().key(locKey, true); 176 if (!widgetDialog.useNewStyle()) { 177 locKey = param.getId(); 179 } 180 if (locValue == null) { 181 return widgetDialog.dialogHorizontalSpacer(16); 183 } else { 184 result.append("<td>"); 185 result.append("<img id=\"img"); 186 result.append(locKey); 187 result.append("\" SRC=\""); 188 result.append(OpenCms.getLinkManager().substituteLink(cms, "/system/workplace/resources/commons/help.png")); 189 result.append("\" alt=\"\" border=\"0\""); 190 if (widgetDialog.useNewStyle()) { 191 result.append(getJsHelpMouseHandler(widgetDialog, locKey, null)); 193 } else { 194 locValue = CmsStringUtil.substitute(locValue, "\"", """); 196 result.append(getJsHelpMouseHandler(widgetDialog, locKey, CmsStringUtil.escapeJavaScript(locValue))); 198 } 199 result.append("></td>"); 200 return result.toString(); 201 } 202 } 203 204 207 public String getHelpText(I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 208 209 String helpId = getHelpKey(param); 210 Set helpIdsShown = widgetDialog.getHelpMessageIds(); 211 if (helpIdsShown.contains(helpId)) { 212 return ""; 214 } 215 helpIdsShown.add(helpId); 216 217 String locValue = widgetDialog.getMessages().key(helpId, true); 219 if (locValue == null) { 220 return ""; 222 } else { 223 if (widgetDialog.useNewStyle()) { 224 StringBuffer result = new StringBuffer (128); 225 result.append("<div class=\"help\" id=\"help"); 226 result.append(helpId); 227 result.append("\""); 228 result.append(getJsHelpMouseHandler(widgetDialog, helpId, helpId)); 229 result.append(">"); 230 result.append(locValue); 231 result.append("</div>\n"); 232 return result.toString(); 233 } else { 234 return ""; 236 } 237 238 } 239 } 240 241 244 public String getWidgetStringValue(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 245 246 if (param != null) { 247 return param.getStringValue(cms); 248 } 249 return null; 250 } 251 252 255 public int hashCode() { 256 257 return getClass().getName().hashCode(); 258 } 259 260 263 public void setConfiguration(String configuration) { 264 265 m_configuration = configuration; 266 } 267 268 271 public void setEditorValue( 272 CmsObject cms, 273 Map formParameters, 274 I_CmsWidgetDialog widgetDialog, 275 I_CmsWidgetParameter param) { 276 277 String [] values = (String [])formParameters.get(param.getId()); 278 if ((values != null) && (values.length > 0)) { 279 param.setStringValue(cms, values[0]); 280 } 281 } 282 283 294 protected String getJsHelpMouseHandler(I_CmsWidgetDialog widgetDialog, String key, String value) { 295 296 String jsShow; 297 String jsHide; 298 String keyHide; 299 if (widgetDialog.useNewStyle()) { 300 jsShow = "sMH"; 302 jsHide = "hMH"; 303 keyHide = "'" + key + "'"; 304 } else { 305 jsShow = "showHelpText"; 307 jsHide = "hideHelpText"; 308 keyHide = ""; 309 } 310 StringBuffer result = new StringBuffer (128); 311 result.append(" onmouseover=\""); 312 result.append(jsShow); 313 result.append("('"); 314 result.append(key); 315 if (!widgetDialog.useNewStyle()) { 316 result.append("', '"); 317 result.append(value); 318 } 319 result.append("');\" onmouseout=\""); 320 result.append(jsHide); 321 result.append("("); 322 result.append(keyHide); 323 result.append(");\""); 324 325 return result.toString(); 326 } 327 328 334 protected String getJSIncludeFile(String fileName) { 335 336 StringBuffer result = new StringBuffer (8); 337 result.append("<script type=\"text/javascript\" SRC=\""); 338 result.append(fileName); 339 result.append("\"></script>"); 340 return result.toString(); 341 } 342 } | Popular Tags |