1 31 32 package org.opencms.workplace.list; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.main.CmsException; 37 import org.opencms.main.OpenCms; 38 import org.opencms.util.CmsStringUtil; 39 import org.opencms.workplace.CmsWorkplace; 40 41 import java.io.File ; 42 43 52 public class CmsListResourceIconAction extends CmsListDirectAction { 53 54 55 private final CmsObject m_cms; 56 57 58 private final String m_resColumnTypeId; 59 60 67 public CmsListResourceIconAction(String id, String resColumnTypeId, CmsObject cms) { 68 69 super(id); 70 m_cms = cms; 71 m_resColumnTypeId = resColumnTypeId; 72 } 73 74 77 public String buttonHtml(CmsWorkplace wp) { 78 79 if (!isVisible()) { 80 return ""; 81 } 82 return defButtonHtml( 83 wp.getJsp(), 84 getId() + getItem().getId(), 85 getId(), 86 resolveName(wp.getLocale()), 87 resolveHelpText(wp.getLocale()), 88 isEnabled(), 89 getIconPath(), 90 null, 91 resolveOnClic(wp.getLocale()), 92 getColumnForTexts() == null); 93 } 94 95 100 public CmsObject getCms() { 101 102 return m_cms; 103 } 104 105 108 public String getIconPath() { 109 110 try { 111 int resourceType = Integer.parseInt(getItem().get(m_resColumnTypeId).toString()); 112 String typeName = OpenCms.getResourceManager().getResourceType(resourceType).getTypeName(); 113 return "filetypes/" + OpenCms.getWorkplaceManager().getExplorerTypeSetting(typeName).getIcon(); 114 } catch (CmsException e) { 115 return super.getIconPath(); 116 } 117 } 118 119 140 protected String defButtonHtml( 141 CmsJspActionElement jsp, 142 String id, 143 String helpId, 144 String name, 145 String helpText, 146 boolean enabled, 147 String iconPath, 148 String confirmationMessage, 149 String onClick, 150 boolean singleHelp) { 151 152 StringBuffer html = new StringBuffer (1024); 153 html.append("\t<span class=\"link"); 154 if (enabled) { 155 html.append("\""); 156 } else { 157 html.append(" linkdisabled\""); 158 } 159 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText)) { 160 if (!singleHelp) { 161 html.append(" onMouseOver=\"sMH('"); 162 html.append(id); 163 html.append("');\" onMouseOut=\"hMH('"); 164 html.append(id); 165 html.append("');\""); 166 } else { 167 html.append(" onMouseOver=\"sMHS('"); 168 html.append(id); 169 html.append("', '"); 170 html.append(helpId); 171 html.append("');\" onMouseOut=\"hMH('"); 172 html.append(id); 173 html.append("', '"); 174 html.append(helpId); 175 html.append("');\""); 176 } 177 } 178 if (enabled && CmsStringUtil.isNotEmptyOrWhitespaceOnly(onClick)) { 179 html.append(" onClick=\""); 180 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) { 181 html.append("if (confirm('" + CmsStringUtil.escapeJavaScript(confirmationMessage) + "')) {"); 182 } 183 html.append(onClick); 184 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) { 185 html.append(" }"); 186 } 187 html.append("\""); 188 } 189 html.append(" title='"); 190 html.append(name); 191 html.append("'"); 192 html.append(" style='display: block; width: 20px; height: 20px;'>"); 193 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(iconPath)) { 194 html.append("<img SRC='"); 195 html.append(CmsWorkplace.getSkinUri()); 196 if (!enabled) { 197 StringBuffer icon = new StringBuffer (128); 198 icon.append(iconPath.substring(0, iconPath.lastIndexOf('.'))); 199 icon.append("_disabled"); 200 icon.append(iconPath.substring(iconPath.lastIndexOf('.'))); 201 if (jsp != null) { 202 String resorcesRoot = jsp.getJspContext().getServletConfig().getServletContext().getRealPath( 203 "/resources/"); 204 File test = new File (resorcesRoot + "/" + icon.toString()); 205 if (test.exists()) { 206 html.append(icon); 207 } else { 208 html.append(iconPath); 209 } 210 } else { 211 html.append(iconPath); 212 } 213 } else { 214 html.append(iconPath); 215 } 216 html.append("'"); 217 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(name)) { 218 html.append(" alt='"); 219 html.append(name); 220 html.append("'"); 221 html.append(" title='"); 222 html.append(name); 223 html.append("'"); 224 } 225 html.append("style='width: 16px; height: 16px;' >"); 226 } 227 html.append("</span>\n"); 228 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText) && !singleHelp) { 229 html.append("<div class='help' id='help"); 230 html.append(helpId); 231 html.append("' onMouseOver=\"sMH('"); 232 html.append(id); 233 html.append("');\" onMouseOut=\"hMH('"); 234 html.append(id); 235 html.append("');\">"); 236 html.append(helpText); 237 html.append("</div>\n"); 238 } 239 return html.toString(); 240 } 241 } | Popular Tags |