KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > ui > TabbedPaneTag


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.jsp.ui;
6
7 import com.opensymphony.webwork.util.TabbedPane;
8
9 import javax.servlet.jsp.JspException JavaDoc;
10 import javax.servlet.jsp.JspTagException JavaDoc;
11 import javax.servlet.jsp.PageContext JavaDoc;
12 import java.util.Map JavaDoc;
13 import java.util.Vector JavaDoc;
14
15
16 /**
17  * TabbedPane tag.
18  *
19  * @author Onyeje Bose (digi9ten@yahoo.com)
20  * @version $Revision: 1.8 $
21  */

22 public class TabbedPaneTag extends ComponentTag {
23     //~ Static fields/initializers /////////////////////////////////////////////
24

25     private final static String JavaDoc TEMPLATE = "tabbedpane";
26
27     //~ Instance fields ////////////////////////////////////////////////////////
28

29     protected String JavaDoc contentName;
30
31     // Protected --------------------------------------------------------
32
protected TabbedPane tabPane;
33
34     //~ Methods ////////////////////////////////////////////////////////////////
35

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 JavaDoc content) {
41         tabPane.setContent(content);
42     }
43
44     public java.util.Vector JavaDoc getContent() {
45         return tabPane.getContent();
46     }
47
48     public void setContentName(String JavaDoc contentName) {
49         this.contentName = strVal(contentName);
50
51         Object JavaDoc obj = findValue(this.contentName);
52
53         if (obj instanceof Vector JavaDoc) {
54             this.setContent((Vector JavaDoc) obj);
55         }
56     }
57
58     public String JavaDoc getContentName() {
59         return this.contentName;
60     }
61
62     public String JavaDoc getIndexLink() {
63         return ("TABBEDPANE_" + getId() + "_INDEX");
64     }
65
66     // BodyTagSupport overrides --------------------------------------
67
public void setPageContext(PageContext JavaDoc 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 JavaDoc getSelectedUrl() {
85         Map.Entry JavaDoc me = (Map.Entry JavaDoc) this.getContent().elementAt(this.getSelectedIndex());
86
87         return me.getValue().toString();
88     }
89
90     public void setTabAlign(String JavaDoc tabAlign) {
91         tabPane.setTabAlign(strVal(tabAlign));
92     }
93
94     public String JavaDoc getTabAlign() {
95         return tabPane.getTabAlign();
96     }
97
98     public boolean compareNumbers(Number JavaDoc n1, Number JavaDoc n2) {
99         return n1.longValue() == n2.longValue();
100     }
101
102     // BodyTag implementation ----------------------------------------
103
public int doStartTag() throws JspException JavaDoc {
104         String JavaDoc 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 JavaDoc e) {
111                 throw new JspTagException JavaDoc("TabbedPane Error: " + e.toString());
112             }
113         }
114
115         return super.doStartTag();
116     }
117
118     // IncludeTag overrides ------------------------------------------
119
public void release() {
120         this.setSelectedIndex(0);
121
122         if (this.getTabAlign() == null) {
123             this.setTabAlign("'CENTER'");
124         }
125     }
126
127     protected String JavaDoc getDefaultTemplate() {
128         return TEMPLATE;
129     }
130
131     protected String JavaDoc strVal(String JavaDoc objName) {
132         try {
133             return findString(objName);
134         } catch (Exception JavaDoc e) {
135             return objName;
136         }
137     }
138 }
139
Popular Tags