| 1 31 32 package org.opencms.widgets; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.i18n.CmsEncoder; 36 import org.opencms.main.OpenCms; 37 import org.opencms.util.CmsStringUtil; 38 39 import java.util.Set ; 40 41 50 public class CmsDisplayWidget extends A_CmsWidget { 51 52 53 private static final String DISABLED_POSTFIX = ".disabled"; 54 55 58 public CmsDisplayWidget() { 59 60 this(""); 62 } 63 64 69 public CmsDisplayWidget(String configuration) { 70 71 super(configuration); 72 } 73 74 77 public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 78 79 String id = param.getId(); 80 81 StringBuffer result = new StringBuffer (16); 82 83 result.append("<td class=\"xmlTd\">"); 84 result.append("<span class=\"xmlInput textInput\" style=\"border: 0px solid black;\">"); 85 if (CmsStringUtil.isNotEmpty(getConfiguration())) { 86 result.append(getConfiguration()); 87 } else { 88 result.append(param.getStringValue(cms)); 89 } 90 result.append("</span>"); 91 result.append("<input type=\"hidden\""); 92 result.append(" name=\""); 93 result.append(id); 94 result.append("\" id=\""); 95 result.append(id); 96 result.append("\" value=\""); 97 result.append(CmsEncoder.escapeXml(param.getStringValue(cms))); 98 result.append("\">"); 99 result.append("</td>"); 100 101 return result.toString(); 102 } 103 104 107 public String getHelpBubble(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 108 109 StringBuffer result = new StringBuffer (128); 110 String locKey = getDisabledHelpKey(param); 111 String locValue = widgetDialog.getMessages().key(locKey, true); 112 if (locValue == null) { 113 return widgetDialog.dialogHorizontalSpacer(16); 115 } else { 116 result.append("<td>"); 117 result.append("<img name=\"img"); 118 result.append(locKey); 119 result.append("\" id=\"img"); 120 result.append(locKey); 121 result.append("\" SRC=\""); 122 result.append(OpenCms.getLinkManager().substituteLink(cms, "/system/workplace/resources/commons/help.png")); 123 result.append("\" alt=\"\" border=\"0\""); 124 if (widgetDialog.useNewStyle()) { 125 result.append(getJsHelpMouseHandler(widgetDialog, locKey, null)); 126 } else { 127 result.append(getJsHelpMouseHandler(widgetDialog, locKey, CmsEncoder.escape(locValue, cms.getRequestContext().getEncoding()))); 128 } 129 result.append("></td>"); 130 return result.toString(); 131 } 132 } 133 134 137 public String getHelpText(I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 138 139 String helpId = getDisabledHelpKey(param); 140 Set helpIdsShown = widgetDialog.getHelpMessageIds(); 141 if (helpIdsShown.contains(helpId)) { 142 return ""; 144 } 145 helpIdsShown.add(helpId); 146 147 String locValue = widgetDialog.getMessages().key(helpId, true); 149 if (locValue == null) { 150 return ""; 152 } else { 153 if (widgetDialog.useNewStyle()) { 154 StringBuffer result = new StringBuffer (128); 155 result.append("<div class=\"help\" id=\"help"); 156 result.append(helpId); 157 result.append("\""); 158 result.append(getJsHelpMouseHandler(widgetDialog, helpId, helpId)); 159 result.append(">"); 160 result.append(locValue); 161 result.append("</div>\n"); 162 return result.toString(); 163 } else { 164 return ""; 165 } 166 } 167 } 168 169 172 public I_CmsWidget newInstance() { 173 174 return new CmsDisplayWidget(getConfiguration()); 175 } 176 177 184 private String getDisabledHelpKey(I_CmsWidgetParameter param) { 185 186 StringBuffer result = new StringBuffer (64); 187 result.append(LABEL_PREFIX); 188 result.append(param.getKey()); 189 result.append(HELP_POSTFIX); 190 result.append(DISABLED_POSTFIX); 191 return result.toString(); 192 } 193 } | Popular Tags |