1 5 package com.opensymphony.webwork.views.jsp.ui; 6 7 import com.opensymphony.webwork.util.TabbedPane; 8 9 import javax.servlet.jsp.JspException ; 10 import javax.servlet.jsp.JspTagException ; 11 import javax.servlet.jsp.PageContext ; 12 import java.util.Map ; 13 import java.util.Vector ; 14 15 16 22 public class TabbedPaneTag extends ComponentTag { 23 25 private final static String TEMPLATE = "tabbedpane"; 26 27 29 protected String contentName; 30 31 protected TabbedPane tabPane; 33 34 36 public int getColSpanLength() { 37 return ((this.getTabAlign().compareToIgnoreCase("CENTER") == 0) ? (this.getContent().size() + 2) : (this.getContent().size() + 1)); 38 } 39 40 public void setContent(java.util.Vector content) { 41 tabPane.setContent(content); 42 } 43 44 public java.util.Vector getContent() { 45 return tabPane.getContent(); 46 } 47 48 public void setContentName(String contentName) { 49 this.contentName = strVal(contentName); 50 51 Object obj = findValue(this.contentName); 52 53 if (obj instanceof Vector ) { 54 this.setContent((Vector ) obj); 55 } 56 } 57 58 public String getContentName() { 59 return this.contentName; 60 } 61 62 public String getIndexLink() { 63 return ("TABBEDPANE_" + getId() + "_INDEX"); 64 } 65 66 public void setPageContext(PageContext aPageContext) { 68 tabPane = new TabbedPane(0); 69 contentName = null; 70 setSelectedIndex(0); 71 setTabAlign("'CENTER'"); 72 73 super.setPageContext(aPageContext); 74 } 75 76 public void setSelectedIndex(int selectedIndex) { 77 tabPane.setSelectedIndex(selectedIndex); 78 } 79 80 public int getSelectedIndex() { 81 return tabPane.getSelectedIndex(); 82 } 83 84 public String getSelectedUrl() { 85 Map.Entry me = (Map.Entry ) this.getContent().elementAt(this.getSelectedIndex()); 86 87 return me.getValue().toString(); 88 } 89 90 public void setTabAlign(String tabAlign) { 91 tabPane.setTabAlign(strVal(tabAlign)); 92 } 93 94 public String getTabAlign() { 95 return tabPane.getTabAlign(); 96 } 97 98 public boolean compareNumbers(Number n1, Number n2) { 99 return n1.longValue() == n2.longValue(); 100 } 101 102 public int doStartTag() throws JspException { 104 String indexStr = pageContext.getRequest().getParameter(getIndexLink()); 105 106 if (indexStr != null) { 107 try { 108 int index = Integer.parseInt(indexStr); 109 this.setSelectedIndex(((index < 0) ? 0 : index)); 110 } catch (Exception e) { 111 throw new JspTagException ("TabbedPane Error: " + e.toString()); 112 } 113 } 114 115 return super.doStartTag(); 116 } 117 118 public void release() { 120 this.setSelectedIndex(0); 121 122 if (this.getTabAlign() == null) { 123 this.setTabAlign("'CENTER'"); 124 } 125 } 126 127 protected String getDefaultTemplate() { 128 return TEMPLATE; 129 } 130 131 protected String strVal(String objName) { 132 try { 133 return findString(objName); 134 } catch (Exception e) { 135 return objName; 136 } 137 } 138 } 139 | Popular Tags |