PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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