1 package fr.improve.struts.taglib.layout.util; 2 3 import java.util.Iterator ; 4 import java.util.Map ; 5 6 import javax.servlet.jsp.JspException ; 7 import javax.servlet.jsp.PageContext ; 8 import javax.servlet.jsp.tagext.TagSupport ; 9 10 import fr.improve.struts.taglib.layout.FormTag; 11 import fr.improve.struts.taglib.layout.tab.TabHeader; 12 import fr.improve.struts.taglib.layout.tab.TabsTag; 13 14 22 public class BasicTabs extends BasicPanel implements TabsInterface { 23 protected static String STYLE_HEADER_ENA = "ongletTextEna"; 26 protected static String STYLE_HEADER_DIS = "ongletTextDis"; 27 protected static String STYLE_HEADER_ERR = "ongletTextErr"; 28 protected static String STYLE_TAB_SPACE = "ongletSpace"; 29 protected static String STYLE_TAB_MAIN = "ongletMain"; 30 protected static String STYLE_TAB_MIDDLE = "ongletMiddle"; 31 32 protected PageContext pageContext; 33 34 protected String selectedTabKeyName; 35 36 public String getHeaderEnabledStyle() { 37 return STYLE_HEADER_ENA; 38 } 39 public String getHeaderDisabledStyle() { 40 return STYLE_HEADER_DIS; 41 } 42 public String getHeaderErrorStyle() { 43 return STYLE_HEADER_ERR; 44 } 45 46 public void doPrintTitle() { 47 } 49 50 public void doStartPanel(StringBuffer buffer, String align, String width) { 51 buffer.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\""); 52 if (width!=null) { 53 buffer.append(" width=\""); 54 buffer.append(width); 55 buffer.append("\""); 56 } 57 buffer.append(">"); 58 } 59 60 public void doStartHeaders(StringBuffer buffer) { 61 buffer.append("<tr><td><table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>"); 62 } 63 64 public void doPrintHeaders(StringBuffer out_buffer, String in_tabId, Map in_headers) { 65 66 Iterator lc_it = in_headers.entrySet().iterator();; 68 while (lc_it.hasNext()) { 69 Map.Entry lc_entry = (Map.Entry ) lc_it.next(); 70 String lc_id = (String ) lc_entry.getKey(); 71 TabHeader lc_header = (TabHeader) lc_entry.getValue(); 72 out_buffer.append("<td id=\"tabs"); 74 out_buffer.append(in_tabId); 75 out_buffer.append("head"); 76 out_buffer.append(lc_id); 77 out_buffer.append("\" class=\""); 78 out_buffer.append(lc_header.styleClass); 79 if (lc_header.width!=null) { 80 out_buffer.append("\" width=\""); 81 out_buffer.append(lc_header.width); 82 } 83 out_buffer.append("\" onmouseover=\"onTabHeaderOver("); 84 out_buffer.append(in_tabId); 85 out_buffer.append(","); 86 out_buffer.append(lc_id); 87 out_buffer.append(",'"); 88 out_buffer.append(STYLE_HEADER_ENA); 89 out_buffer.append("')\""); 90 91 if (lc_header.href==null ){ 92 out_buffer.append(" onclick=\""); 93 if (lc_header.reqCode==null) { 94 out_buffer.append("selectTab("); 95 out_buffer.append(in_tabId); 96 out_buffer.append(","); 97 out_buffer.append(in_headers.size()); 98 out_buffer.append(","); 99 out_buffer.append(lc_id); 100 out_buffer.append(",'"); 101 out_buffer.append(STYLE_HEADER_ENA); 102 out_buffer.append("','"); 103 out_buffer.append(STYLE_HEADER_DIS); 104 out_buffer.append("','"); 105 out_buffer.append(STYLE_HEADER_ERR); 106 out_buffer.append("'"); 107 if (selectedTabKeyName!=null) { 108 out_buffer.append(",'"); 109 out_buffer.append(selectedTabKeyName); 110 out_buffer.append("','"); 111 out_buffer.append(FilterUtils.filterQuotes(lc_header.titleKey)); 112 out_buffer.append("'"); 113 } else { 114 out_buffer.append(",null,null"); 115 } 116 out_buffer.append(");"); 117 } 118 119 if (lc_header.reqCode!=null){ 120 String lc_formName = FormTag.computeFormName(pageContext); 121 String lc_parameter = FormTag.computeActionParameter(pageContext); 122 out_buffer.append(" document.forms[\'"); 123 out_buffer.append(lc_formName); 124 out_buffer.append("\']."); 125 out_buffer.append(lc_parameter); 126 out_buffer.append(".value=\'"); 127 out_buffer.append(lc_header.reqCode); 128 out_buffer.append("\';document.forms[\'"); 129 out_buffer.append(lc_formName); 130 out_buffer.append("\'].submit();"); 131 } 132 } 133 134 out_buffer.append("\">"); 135 136 if (lc_header.href!=null) { 137 out_buffer.append("<a HREF=\""); 138 out_buffer.append(lc_header.href); 139 out_buffer.append("\" class=\""); 140 out_buffer.append(lc_header.styleClass); 141 out_buffer.append("\">"); 142 } 143 out_buffer.append(lc_header.title); 144 if (lc_header.href!=null) { 145 out_buffer.append("</a>"); 146 } 147 out_buffer.append("</td>"); 148 149 out_buffer.append("<td width=\"5\" class=\""); 151 out_buffer.append(STYLE_TAB_SPACE); 152 out_buffer.append("\"> </td>"); 153 } 154 155 out_buffer.append("<td class=\""); 157 out_buffer.append(STYLE_TAB_SPACE); 158 out_buffer.append("\"> </td></tr>"); 159 160 out_buffer.append("<tr><td height=\"5\" colspan=\""); 162 out_buffer.append(in_headers.size()*2 + 1); 163 out_buffer.append("\" class=\""); 164 out_buffer.append(STYLE_TAB_MIDDLE); 165 out_buffer.append("\"> </td></tr>"); 166 } 167 168 public void doEndHeaders(StringBuffer buffer) { 169 buffer.append("</table></td></tr>"); 170 } 171 172 public void doBeforeBody(StringBuffer out_buffer, String in_align) { 173 out_buffer.append("<tr><td class=\""); 174 out_buffer.append(STYLE_TAB_MAIN); 175 out_buffer.append("\">"); 176 } 177 178 public void doAfterBody(StringBuffer out_buffer) { 179 out_buffer.append("</td></tr>"); 180 } 181 182 public void doEndPanel(StringBuffer out_buffer) { 183 out_buffer.append("</table>\n"); 184 } 185 public void init(PageContext pg, String in_styleClass, TagSupport in_tabs) throws JspException { 186 super.init(pg, in_styleClass, in_tabs); 187 TabsTag lc_tabs = (TabsTag) in_tabs; 188 selectedTabKeyName = lc_tabs.getSelectedTabKeyName(); 189 pageContext = pg; 190 } 191 192 } 193 | Popular Tags |