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 import org.apache.velocity.VelocityContext;
24
25 import com.pow2.webgui.*;
26 import com.pow2.util.*;
27
28
29 /***
30 * AmazonTabDrawer class.
31 *
32 * @author Luca Fossato
33 */
34 public class AmazonTabDrawer extends WidgetDrawer
35 {
36 /***
37 * Constructor.
38 *
39 * @param widget the widget to draw
40 */
41 public AmazonTabDrawer(Widget widget)
42 {
43 super(widget);
44 }
45
46
47 /***
48 * Gets the string representation of the Tab widget.
49 *
50 * @return the string representation of the Tab widget
51 * @exception Exception if any error occurs
52 */
53 public StringBuffer draw() throws Exception
54 {
55 VelocityContext context = new VelocityContext();
56 StringBuffer sb = new StringBuffer();
57 Tab tab = (Tab)widget;
58
59
60 String tabTemplate = "tabbedselector/amazon/tab.vm";
61
62
63 context.put("followUp", tab.getFollowUp());
64 context.put("title", tab.getTitle());
65 context.put("titleType", tab.getTitleType());
66
67
68
69
70
71 if (tab.getTitleType().equals("image"))
72 {
73 String title = null;
74 if ((title = tab.getTitle()) == null)
75 throw new Exception("tab title attribute value cannot be null if tab titleType == 'image'");
76
77 String titleImage1 = title.substring(0, title.indexOf(';')).trim();
78 String titleImage2 = title.substring(title.indexOf(';')+1, title.length()).trim();
79
80 context.put("titleImage1", titleImage1);
81 context.put("titleImage2", titleImage2);
82 }
83
84
85
86
87 switch (tab.getType())
88 {
89 case Tab.LEFTUP:
90 context.put("tabType", "up");
91 break;
92
93 case Tab.UP:
94 context.put("tabType", "up");
95 break;
96
97 case Tab.LEFTDOWN:
98 context.put("tabType", "down");
99 break;
100
101 case Tab.DOWN:
102 context.put("tabType", "down");
103 break;
104
105 default:
106 throw new Exception("cannot get the tab type");
107 }
108
109 return sb.append(VelocityUtil.getTemplate(context, tabTemplate));
110 }
111 }