Source code: com/webobjects/woextensions/WOTabPanel.java
1 /*
2 * WOTabPanel.java
3 * © Copyright 2001 Apple Computer, Inc. All rights reserved.
4 * This a modified version.
5 * Original license: http://www.opensource.apple.com/apsl/
6 */
7
8 package com.webobjects.woextensions;
9
10 import com.webobjects.appserver.*;
11 import com.webobjects.foundation.*;
12 import com.webobjects.eocontrol.*;
13 import java.util.Enumeration;
14
15 /*
16
17 An HTML based Tab Panel
18
19 Bindings:
20
21 - tabs: a list of objects representing the tabs
22 - tabNameKey: a string containing a key to apply to tabs to get the title of the tab
23 - selectedTab: contains the selected tab
24 - submitActionName: if this binding is non null, tabs will contain a submit button instead of a regular hyperlink and the action
25 pointed to by the binding will be called
26 - bgcolor: color to use for the selected tab and the body of the panel
27 - nonSelectedBgColor: color to use for the non-selected tabs
28
29
30 */
31
32
33 public class WOTabPanel extends WOComponent
34 {
35 protected static String _undefinedMarker="UNDEFINED";
36
37 public Object currentTab;
38 protected Object _selectedTab;
39 protected String _submitActionName;
40 protected String _tabNameKey;
41 protected NSArray _tabs;
42 public String bgcolor;
43 protected String _nonSelectedBgColor;
44
45 public WOTabPanel(WOContext aContext) {
46 super(aContext);
47 _selectedTab=null;
48 currentTab=null;
49 _tabs=null;
50 _submitActionName=_undefinedMarker;
51 _tabNameKey=null;
52 }
53
54 public boolean synchronizesVariablesWithBindings() {
55 return false;
56 }
57
58 public Object selectedTab() {
59 if (_selectedTab==null) {
60 _selectedTab=valueForBinding("selectedTab");
61 if (_selectedTab==null) {
62 _selectedTab=((NSArray)valueForBinding("tabs")).objectAtIndex(0);
63 setValueForBinding(_selectedTab, "selectedTab");
64 }
65 }
66 return _selectedTab;
67 }
68
69 public String tabNameKey() {
70 if (_tabNameKey==null) {
71 _tabNameKey=(String)_WOJExtensionsUtil.valueForBindingOrNull("tabNameKey",this);
72 if (_tabNameKey==null) _tabNameKey="toString";
73 }
74 return _tabNameKey;
75 }
76
77 public String selectedTabName() {
78 return (String)NSKeyValueCodingAdditions.Utility.valueForKeyPath(selectedTab(), tabNameKey());
79 }
80
81 public String currentTabName() {
82 return (String)NSKeyValueCodingAdditions.Utility.valueForKeyPath(currentTab, tabNameKey());
83 }
84
85 public boolean isCellShaded() {
86 return !selectedTab().equals(currentTab);
87 }
88
89 public NSArray tabs() {
90 if (_tabs==null) {
91 _tabs=(NSArray)_WOJExtensionsUtil.valueForBindingOrNull("tabs",this);
92 if (_tabs == null) {
93 _tabs = NSArray.EmptyArray;
94 }
95 }
96 return _tabs;
97 }
98
99 public String nonSelectedBgColor() {
100 if (null==_nonSelectedBgColor) {
101 if (hasBinding("nonSelectedBgColor"))
102 _nonSelectedBgColor=(String)_WOJExtensionsUtil.valueForBindingOrNull("nonSelectedBgColor",this);
103 else
104 _nonSelectedBgColor="#B5B5B5";
105 }
106 return _nonSelectedBgColor;
107 }
108
109 public String tabBgColor() {
110 if (isCellShaded())
111 return nonSelectedBgColor();
112 else {
113 if (null==bgcolor) {
114 if (hasBinding("bgcolor"))
115 bgcolor=(String)_WOJExtensionsUtil.valueForBindingOrNull("bgcolor",this);
116 else
117 bgcolor="#E0E0E0";
118 }
119 return bgcolor;
120 }
121 }
122
123 public void switchTab() {
124 _selectedTab=currentTab;
125 setValueForBinding(_selectedTab, "selectedTab");
126 }
127
128 public String submitActionName() {
129 if (_submitActionName==_undefinedMarker) {
130 if (hasBinding("submitActionName"))
131 _submitActionName=(String)_WOJExtensionsUtil.valueForBindingOrNull("submitActionName",this);
132 else
133 _submitActionName=null;
134 }
135 return _submitActionName;
136 }
137
138 public boolean hasSubmitAction() {
139 if (submitActionName()!=null) return true;
140 return false;
141 }
142
143 public void switchSubmitTab() {
144 switchTab();
145 if ((submitActionName()!=null) && !submitActionName().equals(""))
146 performParentAction(submitActionName());
147 }
148
149 public int contentColSpan() {
150 return 2+tabs().count();
151 }
152
153 public int rowSpan() {
154 if (isCellShaded())
155 return 1;
156 else
157 return 2;
158 }
159
160 public void appendToResponse(WOResponse aResponse, WOContext aContext) {
161 _tabs=null;
162 currentTab=null;
163 _selectedTab=null;
164 _submitActionName=_undefinedMarker;
165 _tabNameKey=null;
166 super.appendToResponse(aResponse, aContext);
167 }
168 }