1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.widget;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
24 import org.kuali.rice.krad.uif.UifConstants;
25 import org.kuali.rice.krad.uif.component.ClientSideState;
26 import org.kuali.rice.krad.uif.component.Component;
27 import org.kuali.rice.krad.uif.container.TabGroup;
28 import org.kuali.rice.krad.uif.view.View;
29
30
31
32
33
34
35
36 @BeanTag(name = "tabs-bean", parent = "Uif-Tabs")
37 public class Tabs extends WidgetBase {
38 private static final long serialVersionUID = 2L;
39
40 @ClientSideState(variableName = "activeTab")
41 private String defaultActiveTabId;
42
43 private UifConstants.Position position = UifConstants.Position.TOP;
44
45 public Tabs() {
46 super();
47 }
48
49
50
51
52
53
54
55
56 @Override
57 public void performFinalize(View view, Object model, Component component) {
58 super.performFinalize(view, model, component);
59
60 if (!(component instanceof TabGroup)) {
61 throw new RuntimeException("Parent for tabs widget should be tab group, not " + component.getClass());
62 }
63
64 TabGroup tabGroup = (TabGroup) component;
65
66 if (StringUtils.isNotBlank(defaultActiveTabId)) {
67
68 int index = 0;
69
70 boolean found = false;
71 for (Component tabComponent : tabGroup.getItems()) {
72 if (StringUtils.equals(defaultActiveTabId, tabComponent.getId())) {
73 found = true;
74
75 break;
76 }
77
78 index += 1;
79 }
80
81
82 if (found) {
83 Map<String, String> oTemplateOptions = this.getTemplateOptions();
84
85 if (oTemplateOptions == null) {
86 setTemplateOptions(oTemplateOptions = new HashMap<String, String>());
87 }
88
89 oTemplateOptions.put(UifConstants.TabOptionKeys.ACTIVE, Integer.toString(index));
90 }
91 }
92 }
93
94
95
96
97
98
99
100 @BeanTagAttribute(name = "defaultActiveTabId")
101 public String getDefaultActiveTabId() {
102 return defaultActiveTabId;
103 }
104
105
106
107
108
109
110 public void setDefaultActiveTabId(String defaultActiveTabId) {
111 this.defaultActiveTabId = defaultActiveTabId;
112 }
113
114
115
116
117
118
119 @BeanTagAttribute(name = "position")
120 public UifConstants.Position getPosition() {
121 return position;
122 }
123
124
125
126
127
128
129 public void setPosition(UifConstants.Position position) {
130 this.position = position;
131 }
132
133
134
135
136 @Override
137 protected <T> void copyProperties(T component) {
138 super.copyProperties(component);
139 Tabs tabsCopy = (Tabs) component;
140 tabsCopy.setDefaultActiveTabId(this.getDefaultActiveTabId());
141 tabsCopy.setPosition(this.getPosition());
142 }
143 }