PageRenderTime 36ms CodeModel.GetById 25ms app.highlight 8ms RepoModel.GetById 0ms app.codeStats 1ms

/src/main/java/com/googlecode/struts2yuiplugin/components/TabView.java

http://struts2yuiplugin.googlecode.com/
Java | 89 lines | 58 code | 15 blank | 16 comment | 6 complexity | f4197cec8f4702ea300c524ef08be816 MD5 | raw file
 1package com.googlecode.struts2yuiplugin.components;
 2
 3import org.apache.struts2.views.annotations.StrutsTag;
 4import org.apache.struts2.views.annotations.StrutsTagAttribute;
 5import com.opensymphony.xwork2.util.ValueStack;
 6import com.googlecode.struts2yuiplugin.tools.YUITools;
 7
 8import javax.servlet.http.HttpServletRequest;
 9import javax.servlet.http.HttpServletResponse;
10import java.util.List;
11import java.util.LinkedList;
12
13/**
14 * A YUI TabView
15 */
16@StrutsTag(name = "tabview", tldTagClass = "com.googlecode.struts2yuiplugin.views.jsp.ui.TabViewTag", description = "Renders a YUI TabView")
17public class TabView extends ClosingYUIBean implements OGNLEvaluator {
18
19    public static final String OPEN_TEMPLATE = "yuitabview";
20    public static final String TEMPLATE = OPEN_TEMPLATE +"-close";
21
22    /** List of tabs added to the TabvVew at creation time */
23    private List<Tab> tabs;
24    private String selectedTab;
25    /** If no tab is selected the first will be automatically selected */
26    private boolean noTabSelected;
27
28    public TabView(ValueStack valueStack, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
29        super(valueStack, httpServletRequest, httpServletResponse);
30        tabs = new LinkedList<Tab>();
31        noTabSelected = true;
32    }
33
34    @Override
35    public void evaluateParams() {
36        super.evaluateParams();
37        parameters.put("tabs", tabs);
38        parameters.put("noTabSelected", noTabSelected);
39    }
40
41    @Override
42    protected void evaluateExtraParams() {
43        super.evaluateExtraParams();    
44    }
45
46    public String getDefaultOpenTemplate() {
47        return OPEN_TEMPLATE;
48    }
49
50    protected String getDefaultTemplate() {
51        return TEMPLATE;
52    }
53
54    /**
55     * Declare a tab to for this TabView 
56     * @param tab
57     * @return
58     */
59    public boolean addTab(Tab tab) {
60        if (selectedTab != null) {
61            if (selectedTab.equals(tab.getId())) {
62                tab.setSelected(true);
63            }
64        }
65        if (tab.isSelected()) {
66            noTabSelected = false;
67        }
68        return tabs.add(tab);
69    }
70
71    @StrutsTagAttribute(description = "The ID of a tab to make initially selected", required = false)
72    public void setSelectedTab(String selectedTab) {
73        if (selectedTab != null) {
74            this.selectedTab = evaluateExpression(selectedTab);
75        }
76    }
77
78    /**
79     * Evaluates the OGNL expression
80     *
81     * @param expr OGNL expression.
82     * @return the String value found.
83     */
84    public String evaluateExpression(String expr) {
85        return super.findString(expr);
86    }
87
88
89}