1 31 32 package org.opencms.workplace; 33 34 import org.opencms.i18n.CmsEncoder; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.main.CmsLog; 37 import org.opencms.util.CmsStringUtil; 38 39 import java.util.Iterator ; 40 import java.util.List ; 41 import java.util.Map ; 42 43 import javax.servlet.http.HttpServletRequest ; 44 import javax.servlet.http.HttpServletResponse ; 45 import javax.servlet.jsp.PageContext ; 46 47 import org.apache.commons.logging.Log; 48 49 68 public abstract class CmsTabDialog extends CmsDialog { 69 70 71 public static final int ACTION_SWITCHTAB = 100; 72 73 74 public static final String DIALOG_SWITCHTAB = "switchtab"; 75 76 77 public static final String PARAM_SETPRESSED = "setpressed"; 78 79 public static final String PARAM_TAB = "tab"; 80 81 82 private static final Log LOG = CmsLog.getLog(CmsTabDialog.class); 83 84 85 private int m_activeTab = -1; 86 87 private String m_paramSetPressed; 88 89 90 private String m_paramTab; 91 92 97 public CmsTabDialog(CmsJspActionElement jsp) { 98 99 super(jsp); 100 } 101 102 109 public CmsTabDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 110 111 this(new CmsJspActionElement(context, req, res)); 112 } 113 114 122 public String dialogTabContent(int segment, String title, String attributes) { 123 124 if (segment == HTML_START) { 125 StringBuffer result = new StringBuffer (512); 126 result.append(dialogHead(title)); 128 result.append("<div class=\"dialogtabstart\" unselectable=\"on\">\n"); 129 result.append("<!-- dialogtabs start -->\n"); 130 result.append(dialogTabRow()); 131 result.append("<div class=\"dialogtabcontent\""); 132 if (attributes != null) { 133 result.append(" " + attributes); 134 } 135 result.append(">\n"); 136 result.append("<!-- dialogcontent start -->\n"); 137 return result.toString(); 138 } else { 139 return "\n<!-- dialogcontent end --></div>\n<!-- dialogtabs end --></div>"; 140 } 141 } 142 143 148 public String dialogTabContentEnd() { 149 150 return dialogTabContent(HTML_END, null, null); 151 } 152 153 159 public String dialogTabContentStart(String title) { 160 161 return dialogTabContent(HTML_START, title, null); 162 } 163 164 171 public String dialogTabContentStart(String title, String attributes) { 172 173 return dialogTabContent(HTML_START, title, attributes); 174 } 175 176 181 public String dialogTabRow() { 182 183 StringBuffer result = new StringBuffer (512); 184 StringBuffer lineRow = new StringBuffer (256); 185 List tabNames = getTabs(); 186 if (tabNames.size() < 2) { 187 result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\" style=\"empty-cells: show;\">\n"); 189 result.append("<tr>\n"); 190 result.append("\t<td class=\"dialogtabrow\"></td>\n"); 191 result.append("</tr>\n"); 192 result.append("</table>\n"); 193 return result.toString(); 194 } 195 Iterator i = tabNames.iterator(); 196 int counter = 1; 197 int activeTab = getActiveTab(); 198 result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\" style=\"empty-cells: show;\">\n"); 199 result.append("<tr>\n"); 200 while (i.hasNext()) { 201 String curTab = (String )i.next(); 203 String curTabLink = "javascript:openTab('" + counter + "');"; 204 if (counter == activeTab) { 205 int addDelta = 0; 207 result.append("\t<td class=\"dialogtabactive\""); 208 if (counter == 1) { 209 result.append(" style=\"border-left-width: 1px;\""); 211 addDelta = 1; 212 } 213 result.append(">"); 214 result.append("<span class=\"tabactive\" unselectable=\"on\""); 215 result.append(" style=\"width: " + (curTab.length() * 8 + addDelta) + "px;\""); 216 result.append(">"); 217 result.append(curTab); 218 result.append("</span></td>\n"); 219 lineRow.append("\t<td></td>\n"); 220 } else { 221 result.append("\t<td class=\"dialogtab\" unselectable=\"on\">"); 223 result.append("<a class=\"tab\" HREF=\"" + curTabLink + "\""); 224 result.append(" style=\"width: " + (curTab.length() * 8) + "px;\""); 225 result.append(">"); 226 result.append(curTab); 227 result.append("</a></td>\n"); 228 lineRow.append("\t<td class=\"dialogtabrow\"></td>\n"); 229 } 230 231 counter++; 232 } 233 result.append("\t<td class=\"maxwidth\"></td>\n"); 234 result.append("</tr>\n"); 235 result.append("<tr>\n"); 236 result.append(lineRow); 237 result.append("\t<td class=\"dialogtabrow\"></td>\n"); 238 result.append("</tr>\n"); 239 result.append("</table>\n"); 240 return result.toString(); 241 } 242 243 250 public int getActiveTab() { 251 252 if (m_activeTab < 0) { 253 String paramTab = getParamTab(); 254 int tab = 1; 255 if (CmsStringUtil.isNotEmpty(paramTab)) { 256 try { 257 tab = Integer.parseInt(paramTab); 258 } catch (NumberFormatException e) { 259 if (LOG.isInfoEnabled()) { 261 LOG.info(e.getLocalizedMessage()); 262 } 263 } 264 } 265 setParamTab("" + tab); 266 m_activeTab = tab; 267 return tab; 268 } else { 269 return m_activeTab; 270 } 271 } 272 273 278 public String getActiveTabName() { 279 280 if (m_activeTab < 0) { 281 getActiveTab(); 282 } 283 List tabNames = getTabs(); 284 try { 285 return (String )tabNames.get(m_activeTab - 1); 286 } catch (IndexOutOfBoundsException e) { 287 if (LOG.isInfoEnabled()) { 289 LOG.info(e.getLocalizedMessage()); 290 } 291 return null; 292 } 293 } 294 295 300 public String getParamSetPressed() { 301 302 return m_paramSetPressed; 303 } 304 305 310 public String getParamTab() { 311 312 return m_paramTab; 313 } 314 315 327 public abstract List getTabParameterOrder(); 328 329 334 public abstract List getTabs(); 335 336 344 public String htmlStart() { 345 346 return htmlStart(null); 347 } 348 349 358 public String htmlStart(String helpUrl) { 359 360 String stylesheet = null; 361 if (isPopup()) { 362 stylesheet = "popup.css"; 363 } 364 StringBuffer result = new StringBuffer (super.pageHtmlStyle(HTML_START, null, stylesheet)); 365 if (getSettings().isViewExplorer()) { 366 result.append("<script type=\"text/javascript\" SRC=\""); 367 result.append(getSkinUri()); 368 result.append("commons/explorer.js\"></script>\n"); 369 } 370 result.append("<script type=\"text/javascript\">\n"); 371 if (helpUrl != null) { 372 result.append("top.head.helpUrl=\""); 373 result.append(helpUrl + "\";\n"); 374 375 } 376 result.append("function openTab(tabValue) {\n"); 378 result.append("\tdocument.forms[0]." + PARAM_TAB + ".value = tabValue;\n"); 379 result.append("\tdocument.forms[0]." + PARAM_ACTION + ".value = \"" + DIALOG_SWITCHTAB + "\";\n"); 380 result.append("\tdocument.forms[0].submit();\n"); 381 result.append("}\n"); 382 result.append("function submitAction(actionValue, theForm, formName) {\n"); 384 result.append("\tif (theForm == null) {\n"); 385 result.append("\t\ttheForm = document.forms[formName];\n"); 386 result.append("\t}\n"); 387 result.append("\ttheForm." + PARAM_FRAMENAME + ".value = window.name;\n"); 388 result.append("\tif (actionValue == \"" + DIALOG_SET + "\") {\n"); 389 result.append("\t\ttheForm." + PARAM_ACTION + ".value = \"" + DIALOG_SET + "\";\n"); 390 result.append("\t} else if (actionValue == \"" + DIALOG_CANCEL + "\") {\n"); 391 result.append("\t\ttheForm." + PARAM_ACTION + ".value = \"" + DIALOG_CANCEL + "\";\n"); 392 result.append("\t}\n"); 393 result.append("\ttheForm.submit();\n"); 394 result.append("\treturn false;\n"); 395 result.append("}\n"); 396 result.append("//-->\n</script>\n"); 397 return result.toString(); 398 } 399 400 410 public String paramsAsHidden() { 411 412 StringBuffer result = new StringBuffer (512); 413 String activeTab = (String )getTabParameterOrder().get(getActiveTab() - 1); 414 Map params = paramValues(); 415 Iterator i = params.keySet().iterator(); 416 while (i.hasNext()) { 417 String param = (String )i.next(); 418 if (!param.startsWith(activeTab)) { 419 Object value = params.get(param); 421 result.append("<input type=\"hidden\" name=\""); 422 result.append(param); 423 result.append("\" value=\""); 424 result.append(CmsEncoder.encode(value.toString(), getCms().getRequestContext().getEncoding())); 425 result.append("\">\n"); 426 } 427 } 428 return result.toString(); 429 } 430 431 436 public void setParamSetPressed(String value) { 437 438 m_paramSetPressed = value; 439 } 440 441 446 public void setParamTab(String value) { 447 448 m_paramTab = value; 449 } 450 451 } 452
| Popular Tags
|