View Javadoc

1   /***
2    *  The contents of this file are subject to the Mozilla Public
3    *  License Version 1.1 (the "License"); you may not use this file
4    *  except in compliance with the License. You may obtain a copy of
5    *  the License at http://www.mozilla.org/MPL/
6    *
7    *  Software distributed under the License is distributed on an "AS
8    *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9    *  implied. See the License for the specific language governing
10   *  rights and limitations under the License.
11   *
12   *  The Original Code is pow2WebGui library.
13   *
14   *  The Initial Owner of the Original Code is Power Of Two S.R.L.
15   *  Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16   *  All Rights Reserved.
17   *
18   * Contributor(s):
19   *   Henner.Kollmann
20   *     provides code to set the default tab automatically and optimization
21   *     on body rendering; 
22   */
23  
24  package com.pow2.webgui.taglib;
25  
26  import javax.servlet.jsp.JspException;
27  import javax.servlet.jsp.JspTagException;
28  
29  import com.pow2.webgui.WidgetFactory;
30  import com.pow2.webgui.tabbedselector.Tab;
31  import com.pow2.webgui.tabbedselector.TabbedSelector;
32  
33  
34  /***
35   *  TabTag class.
36   *  <br>
37   *  Represents a tab component for a TabbedPanel component.<br>
38   *  Here's an example of the usage of this tag:
39   *
40   *  <code>
41   *    <gui:tabbedPanel ... >
42   *      <gui:tab name="tab1" title="option1" followUp="myPage.jsp">
43   *        content of tab1
44   *      </gui:tab>
45   *      ...
46   *    </gui:tabbedPanel>
47   *  </code>
48   *
49   * @author  Luca Fossato
50   * @created  22 September 2001
51   */
52  public class TabTag extends Tab
53  {
54    private WidgetFactory  wf  = null;
55    private TabbedSelector ts  = null;
56    private Tab            tab = null;
57  
58  
59    /***
60     *  Constructor
61     */
62    public TabTag()
63    {
64      super();
65    }
66  
67  
68    /***
69     *  Process the start tag for this instance.
70     *
71     * @return  EVAL_BODY_TAG
72     * @exception  JspTagException Description of Exception
73     */
74    public int doStartTag() throws JspTagException
75    {
76      try
77      {
78        wf   = WidgetFactory.instance();
79        tab  = (Tab)wf.getWidget(Tab.KEY);
80        tab.updateAttributes(this);
81        tab.setWidgetDrawer(drawer);
82      }
83      catch (Exception e)
84      {
85        cat.error("::doStartTag - error", e);
86        throw new JspTagException(e.getMessage());
87      }
88  
89      // 2002118 Henner.Kollmann@aucos.de:
90      // Set default tab, so the JSP code on the page is unnecessary!
91      // get the parent TabbedSelector and add to it a new Tab;
92      // 20041023 Henner.Kollmann@gmx.de:
93      // moved from doEndTag to doStartTag!
94      TabbedSelectorTag parent = null;
95      // get and check the parent tag;
96      if ((parent = (TabbedSelectorTag) findAncestorWithClass(this, TabbedSelectorTag.class)) == null)
97      {
98        cat.error("::doAfterBody - cannot retrieve the TabbedSelectorTag parent tag class.");
99        throw new JspTagException("Tab tag without TabbedSelector tag.");
100     }
101     ts = parent.getTabbedSelector();
102     String mySelectedTab = ts.getSelectedTab();
103     if (mySelectedTab == null)
104       ts.setSelectedTab(tab.getName());
105 
106     // 20041023 Henner.Kollmann@gmx.de:
107     // Body should be rendered only if tab is the selected tab.
108     // Otherwise all tabs are rendered - but not shown.
109     // This needs a lot of time...
110     // We can not use isSelected() because the tabs parent isn't
111     // setted yet - so we must compare agaist the selectedTab! 
112     String myName = getName();
113     
114     /*
115     if ((myName != null) && myName.equals(mySelectedTab)) 
116     {
117       return  EVAL_BODY_BUFFERED;
118     } 
119     else 
120     {
121       return  SKIP_BODY;
122     }
123     */
124     
125     int returnValue = ((myName != null) && myName.equals(mySelectedTab)) ? EVAL_BODY_BUFFERED : SKIP_BODY;
126     return returnValue;
127   }
128 
129 
130   /***
131    * @return  Description of the Returned Value
132    * @exception  JspException Description of Exception
133    */
134   public int doEndTag() throws JspException
135   {
136     StringBuffer cnt = new StringBuffer();
137     if (bodyContent != null)
138       cnt.append(bodyContent.getString());
139 
140     ts.addTab(tab, cnt);
141 
142     return EVAL_PAGE;
143   }
144 }