1 package gboat2.base.view.components;
2
3 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse;
5
6 import org.apache.commons.lang3.RandomStringUtils;
7 import org.apache.commons.lang3.StringUtils;
8 import org.apache.struts2.components.ClosingUIBean;
9 import org.apache.struts2.views.annotations.StrutsTag;
10 import org.apache.struts2.views.annotations.StrutsTagAttribute;
11
12 import com.opensymphony.xwork2.util.ValueStack;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 @StrutsTag(
41 name = "tabbedpanel",
42 tldTagClass = "gboat2.base.view.jsp.TabbedPanelTag",
43 description = "一种多panel(面板)的单内容区,详见 http://api.jqueryui.com/tabs/",
44 allowDynamicAttributes=true)
45 public class TabbedPanel extends ClosingUIBean {
46
47 public static final String TEMPLATE = "tabbedpanel";
48 public static final String TEMPLATE_CLOSE = "tabbedpanel-close";
49
50 public static final String JQUERYACTION = "tabbedpanel";
51
52 protected String active;
53 protected String collapsible;
54 protected String disabled;
55 protected String event;
56 protected String heightStyle;
57 protected String hide;
58 protected String show;
59
60 protected String tabPosition;
61 protected String cache;
62 protected String useSelectedTabCookie;
63
64 protected String onActivateTopics;
65 protected String onBeforeActivateTopics;
66 protected String onLoadTopics;
67
68 public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
69 super(stack, request, response);
70 }
71
72 @Override
73 public String getDefaultOpenTemplate() {
74 return TEMPLATE;
75 }
76
77 @Override
78 protected String getDefaultTemplate() {
79 return TEMPLATE_CLOSE;
80 }
81
82 @Override
83 public void evaluateExtraParams() {
84 super.evaluateExtraParams();
85
86 addParameter("jqueryaction", JQUERYACTION);
87
88 if (active != null)
89 addParameter("active", findValue(active, Integer.class));
90
91 if (this.collapsible != null)
92 addParameter("collapsible", findValue(collapsible, Boolean.class));
93
94 if (this.disabled != null)
95 addParameter("disabled", findString(disabled));
96
97 if (this.event != null)
98 addParameter("event", findString(event));
99
100 if (heightStyle != null)
101 addParameter("heightStyle", findString(heightStyle));
102
103 if (hide != null)
104 addParameter("hide", findString(hide));
105
106 if (show != null)
107 addParameter("show", findString(show));
108
109 if (this.tabPosition != null)
110 addParameter("tabPosition", findString(tabPosition));
111
112 if (this.cache != null)
113 addParameter("cache", findValue(cache, Boolean.class));
114
115 if (useSelectedTabCookie != null)
116 addParameter("useSelectedTabCookie", findValue(useSelectedTabCookie, Boolean.class));
117
118
119 if (this.onActivateTopics != null)
120 addParameter("onActivateTopics", findString(onActivateTopics));
121
122 if (this.onBeforeActivateTopics != null)
123 addParameter("onBeforeActivateTopics", findString(onBeforeActivateTopics));
124
125 if (this.onLoadTopics != null)
126 addParameter("onLoadTopics", findString(onLoadTopics));
127
128 if (StringUtils.isBlank(id)) {
129 this.id = "tabbedpanel_" + RandomStringUtils.randomNumeric(3);
130 addParameter("id", this.id);
131 }
132 }
133
134 @StrutsTagAttribute(description = "当前打开哪一个 panel(面板),索引从 0 开始,详见 http://api.jqueryui.com/tabs/#option-active。", type = "Integer", defaultValue = "0")
135 public void setActive(String active) {
136 this.active = active;
137 }
138
139 @StrutsTagAttribute(description = "是否可以被收起和展开, 详见 http://api.jqueryui.com/tabs/#option-collapsible。", type = "Boolean", defaultValue = "false")
140 public void setCollapsible(String collapsible) {
141 this.collapsible = collapsible;
142 }
143
144 @StrutsTagAttribute(description = "设置哪些标签被禁用,多值之间使用逗号分隔,如: 0,2 表示禁用第一个和第三个 tab 页, 详见 http://api.jqueryui.com/tabs/#option-disabled")
145 public void setDisabled(String disabled) {
146 this.disabled = disabled;
147 }
148
149 @StrutsTagAttribute(description = "激活选项卡的事件类型。 要悬停(hover)激活选项卡,用 mouseover, 详见 http://api.jqueryui.com/tabs/#option-event", defaultValue = "click")
150 public void setEvent(String event) {
151 this.event = event;
152 }
153
154 @StrutsTagAttribute(description = "控制Tab(选项卡)部件和每个panel(面板)的高度,可选值:auto、fill、content, 详见 http://api.jqueryui.com/tabs/#option-heightStyle", defaultValue = "content")
155 public void setHeightStyle(String heightStyle) {
156 this.heightStyle = heightStyle;
157 }
158
159 @StrutsTagAttribute(description = "panel(面板)隐藏时的动画效果,如:fold, 详见 http://api.jqueryui.com/tabs/#option-hide")
160 public void setHide(String hide) {
161 this.hide = hide;
162 }
163
164 @StrutsTagAttribute(description = "panel(面板)显示时的动画效果,如:fold, 详见 http://api.jqueryui.com/tabs/#option-show")
165 public void setShow(String show) {
166 this.show = show;
167 }
168
169 @StrutsTagAttribute(description = "Tab 选项卡显示的位置,可选值: top, bottom, left", defaultValue = "top")
170 public void setTabPosition(String tabPosition) {
171 this.tabPosition = tabPosition;
172 }
173
174 @StrutsTagAttribute(description = "当面板中的内容是通过 Ajax 从远程服务器加载的时候,是否缓存加载后的内容。如果值为 true, 则在 tab 之间切换时,只在第一次显示对应的面板时会从远程加载数据。", type = "Boolean", defaultValue = "false")
175 public void setCache(String cache) {
176 this.cache = cache;
177 }
178
179 @StrutsTagAttribute(description = "是否使用 cookie 保存最后一次选中的选项卡的索引,如果值为 true,则需要引入 jquery.cookie 插件。注意: useSelectedTabCookie 的值为 true 时,必须明确指定 id 属性值,否则不会生效!", type = "Boolean", defaultValue = "false")
180 public void setUseSelectedTabCookie(String useSelectedTabCookie) {
181 this.useSelectedTabCookie = useSelectedTabCookie;
182 }
183
184 @StrutsTagAttribute(description = "面板被激活后(在动画完成之后),即触发 activate 事件时发布的话题, 详见 http://api.jqueryui.com/tabs/#event-activate", type = "String", defaultValue = "")
185 public void setOnActivateTopics(String onActivateTopics) {
186 this.onActivateTopics = onActivateTopics;
187 }
188
189 @StrutsTagAttribute(description = "tabs(选项卡)被激活前,即触发 beforeActivate 事件时发布的话题, 详见 http://api.jqueryui.com/tabs/#event-beforeActivate", type = "String", defaultValue = "")
190 public void setOnBeforeActivateTopics(String onBeforeActivateTopics) {
191 this.onBeforeActivateTopics = onBeforeActivateTopics;
192 }
193
194 @StrutsTagAttribute(description = "远程选项卡加载后,即触发 load 事件时发布的话题, 详见 http://api.jqueryui.com/tabs/#event-load", type = "String", defaultValue = "")
195 public void setOnLoadTopics(String onLoadTopics) {
196 this.onLoadTopics = onLoadTopics;
197 }
198
199 }