KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > console > plugins > helpers > servlet > NavigationTag


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.console.plugins.helpers.servlet;
23
24 import java.io.IOException JavaDoc;
25 import java.net.URLEncoder JavaDoc;
26 import java.util.ArrayList JavaDoc;
27
28 import javax.servlet.jsp.JspTagException JavaDoc;
29 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
30
31 /**
32  *
33  */

34 public class NavigationTag extends TagSupport JavaDoc
35 {
36     private ArrayList JavaDoc tabs = new ArrayList JavaDoc(10);
37     private String JavaDoc selectedTabName;
38     
39     public int doStartTag() throws JspTagException JavaDoc
40     {
41         tabs.clear();
42         return EVAL_BODY_INCLUDE;
43     }
44
45     //output the navigation table and the tabs, with the 'class' setting determining the
46
//selected tab.
47
public int doEndTag() throws JspTagException JavaDoc
48     {
49         try
50         {
51             pageContext.getOut().write(
52                 "<table width='100%' height='24' border='0' cellspacing='0' cellpadding='0'>");
53             pageContext.getOut().write("<tr valign='bottom'>");
54             for (int i = 0; i < tabs.size(); i++)
55             {
56                 Tab tab = (Tab) tabs.get(i);
57                 String JavaDoc name = tab.getName();
58                 
59                 pageContext.getOut().write("<td width='8' align='left' class='tabSpacer'>");
60                 pageContext.getOut().write("<p><img SRC='images/spacer.gif' width='8' height='24'></p>");
61                 pageContext.getOut().write("</td>");
62                 pageContext.getOut().write("<td align='left' nowrap class=");
63                 
64                 if (isSelected(tab))
65                 {
66                     pageContext.getOut().write("'tab'>");
67                 }
68                 else
69                 {
70                     pageContext.getOut().write("'tabOff'>");
71                 }
72                 pageContext.getOut().write("<p>");
73                 if (tab.getHref() != null)
74                 {
75                     pageContext.getOut().write("<a HREF='" + tab.getHref() + "'>");
76                 }
77                 pageContext.getOut().write(name);
78                 if (tab.getHref() != null)
79                 {
80                     pageContext.getOut().write("</a>");
81                 }
82                 pageContext.getOut().write("</p></td>");
83             }
84             //last spacer takes up rest of the space
85
pageContext.getOut().write("<td width='100%' align='left' class='tabSpacer'><p>&nbsp;</p></td>");
86             pageContext.getOut().write("</tr>");
87             pageContext.getOut().write("</table>");
88         }
89         catch (IOException JavaDoc e)
90         {
91             throw new JspTagException JavaDoc(e.toString());
92         }
93         return EVAL_PAGE;
94     }
95
96     /**
97      * @param tab
98      * @return
99      */

100     private boolean isSelected(Tab tab)
101     {
102         boolean selected = false;
103         
104         if (tab.isSelected())
105         {
106             selected = true;
107         }
108         
109         //navigation parent setting overrides if set
110
if (selectedTabName != null && !selectedTabName.equals(""))
111         {
112             selected = tab.getName().equals(selectedTabName);
113         }
114         
115         return selected;
116     }
117
118     public final void setTabs(Tab tab)
119     {
120         tabs.add(tab);
121     }
122
123     /**
124      * @return
125      */

126     public String JavaDoc getSelectedTabName()
127     {
128         return selectedTabName;
129     }
130
131     /**
132      * @param string
133      */

134     public void setSelectedTabName(String JavaDoc string)
135     {
136         selectedTabName = string;
137     }
138
139 }
140
Popular Tags