1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2WebGui library.
13 *
14 * The Initial Owner of the Original Code is Power Of Two S.R.L.
15 * Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16 * All Rights Reserved.
17 *
18 * Contributor(s):
19 */
20
21 package com.pow2.webgui.tabbedselector;
22
23
24 import com.pow2.util.Util;
25 import com.pow2.webgui.Widget;
26
27
28 /***
29 * Tab class.
30 *
31 * @author Luca Fossato
32 * @created 22 September 2001
33 */
34 public class Tab extends Widget
35 {
36 /*** LEFTUP is the left-most selected tab. */
37 public final static int LEFTUP = 0;
38
39 /*** LEFTDOWN is the left-most deselected tab. */
40 protected final static int LEFTDOWN = 1;
41
42 /*** UP is a selected tab, but not a left-most one. */
43 protected final static int UP = 2;
44
45 /*** DOWN is a deselected tab, but not a left-most one. */
46 protected final static int DOWN = 3;
47
48 /*** tabbedSelector key */
49 public final static String KEY = "tab";
50
51 protected final static String FOLLOWUP_PARAMETER_PREFIX = "webgui.tbdselector.";
52 protected final static String FOLLOWUP_PARAMETER = ".tab";
53
54
55 /***
56 * Tab type.
57 * <br>
58 * Its value can be:<br>
59 * <ul>
60 * <li>LEFTUP the left-most selected tab.</li>
61 * <li>LEFTDOWN the left-most deselected tab.</li>
62 * <li>UP a selected tab, but not a left-most one.</li>
63 * <li>DOWN a deselected tab, but not a left-most one.</li>
64 * </ul>
65 */
66 protected int type;
67
68
69 /***
70 * Default constructor.
71 */
72 public Tab()
73 {
74 type = LEFTUP;
75 }
76
77
78
79 /***
80 * Sets the type attribute of the Tab object
81 *
82 * @param newType The new type value
83 */
84 public void setType(int newType)
85 {
86 type = newType;
87 }
88
89
90 /***
91 * Gets the type attribute of the Tab object
92 *
93 * @return The type value
94 */
95 public int getType()
96 {
97 return type;
98 }
99
100
101 /***
102 * Gets the followUp attribute of the Tab object.
103 * <br>
104 * If the Tab followUp attribute value is null, this method
105 * uses the parent TabbedPanel followUp attribute value, adding to it
106 * the new parameter FOLLOWUP_PARAMETER={tabName}
107 * where<br>
108 * FOLLOWUP_PARAMETER = webGUI.tabbedPanel.tab<br>
109 * {tabName} = the name of the selected tab
110 *
111 * @return The followUp value
112 */
113 public String getFollowUp()
114 {
115 if (parentW == null)
116 return followUp;
117
118
119 if (Util.isNull(followUp) && Util.isNull(followUp = parentW.getFollowUp()))
120 {
121 cat.warn("::getFollowUp - followUp is null either for tag [" + name + "] and for its parent");
122 return followUp;
123 }
124
125
126 if (followUp.indexOf(FOLLOWUP_PARAMETER_PREFIX) == -1)
127 followUp = Util.addURLParameter(followUp, getSelectedTabParam());
128
129
130
131
132 return (followUp.startsWith("/")) ?
133 followUp.substring(1, followUp.length()) : followUp;
134 }
135
136
137
138
139 /***
140 * PROTECTED METHODS here
141 */
142
143
144 /***
145 * Sets the type attribute of the Tab object.
146 */
147 protected void setType()
148 {
149 if (isFirst() && isSelected()) type = LEFTUP;
150 else if (isFirst() && !isSelected()) type = LEFTDOWN;
151 else if (!isFirst() && isSelected()) type = UP;
152 else if (!isFirst() && !isSelected()) type = DOWN;
153 }
154
155
156 /***
157 * Check if this tab is the tabbedPanel selected tab.
158 *
159 * @return true if this tab is the tabbedPanel selected tab;
160 * false otherwise.
161 */
162 protected boolean isSelected()
163 {
164 if (parentW == null)
165 {
166 cat.warn("::isSelected - parent is null. Cannot operate.");
167 return false;
168 }
169
170
171 TabbedSelector p = (TabbedSelector) parentW;
172 String st = p.getSelectedTab();
173
174 return ((st != null) && (name != null) && name.equals(st));
175 }
176
177
178
179
180 /***
181 * PRIVATE METHODS here
182 */
183
184
185 /***
186 * Check if this tab is the first tab of the TabbedPanel widget.
187 *
188 * @return true if this tab is the first tab of the TabbedPanel widget;
189 * false otherwise.
190 */
191 private boolean isFirst()
192 {
193 if (parentW == null)
194 {
195 cat.warn("::isFirst - parent is null. Cannot operate.");
196 return false;
197 }
198
199 TabbedSelector p = (TabbedSelector) parentW;
200
201 return (p.getTabs().size() <= 1);
202 }
203
204
205 /***
206 * Build the selectedTab parameter
207 *
208 * @return the selectedTab parameter
209 */
210 private String getSelectedTabParam()
211 {
212 return TabbedSelectorUtil.getSelectedTabParam(getParentW().getName(), name);
213 }
214 }