1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.tapfx.components.outlookbar;
17
18 import java.util.HashMap;
19 import java.util.Map;
20 import javax.servlet.http.HttpSession;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.tapestry.IRequestCycle;
25 import org.apache.tapestry.IResourceLocation;
26 import org.apache.tapestry.IScript;
27 import org.apache.tapestry.Tapestry;
28 import org.apache.tapestry.engine.IScriptSource;
29 import org.apache.tapestry.html.Body;
30
31 import net.sf.tapfx.components.TapFXBaseComponent;
32
33 /***
34 * This component encloses a panes. It decorates
35 * the enclosed panes. It also starts basic state
36 * management...
37 *
38 * @author Joshua Long (josh@joshlong.com)
39 */
40 public abstract class OutlookBar extends TapFXBaseComponent
41 {
42 private static final Log log =
43 LogFactory.getLog(OutlookBar.class);
44
45 private static final String OUTLOOK_BAR_COUNT =
46 "net.sf.tapfx.components.outlookbar.outlook_bar_count_id";
47 private static final String AGGREGATE_ID =
48 "net.sf.tapfx.components.outlookbar.aggregate id string";
49 private static final String OUTLOOK_BAR_CURRENT_ID =
50 "net.sf.tapfx.components.outlookbar.outlook_bar_current_id";
51 private static final String OUTLOOK_BAR_CONTROL =
52 "net.sf.tapfx.components.outlookbar.OutlookBar";
53
54 private IScript script = null;
55
56 public abstract String getCssPrefix();
57
58 public abstract boolean getForceSession();
59
60 public abstract String getTitle();
61
62 public abstract void setTitle(String title);
63
64 public String getPrefix()
65 {
66 String ret = getCssPrefix();
67 if (ret == null)
68 ret = "";
69 return ret;
70 }
71
72 public static OutlookBar getOutlookBar(IRequestCycle cycle)
73 {
74 return (OutlookBar) cycle.getAttribute(OUTLOOK_BAR_CONTROL);
75 }
76
77 static void setOutlookBarCount(IRequestCycle cycle, Integer obj)
78 {
79 cycle.setAttribute(OutlookBar.OUTLOOK_BAR_COUNT, obj);
80 }
81
82 static Integer getOutlookBarCount(IRequestCycle cycle)
83 {
84 Integer value = (Integer)
85 cycle.getAttribute(OutlookBar.OUTLOOK_BAR_COUNT);
86 if (null == value)
87 {
88 value = new Integer(0);
89 }
90 else
91 {
92 value = new Integer(value.intValue() + 1);
93 }
94 return value;
95 }
96
97 static void setOutlookBarCurrentId(IRequestCycle cycle, String obj)
98 {
99 cycle.setAttribute(OutlookBar.OUTLOOK_BAR_CURRENT_ID, obj);
100 }
101
102 static String getOutlookBarCurrentId(IRequestCycle cycle)
103 {
104 return (String) cycle.getAttribute(OutlookBar.OUTLOOK_BAR_CURRENT_ID);
105 }
106
107 static void setOutlookBarAggregateId(IRequestCycle cycle, String id)
108 {
109 cycle.setAttribute(AGGREGATE_ID, id);
110 }
111
112 static String getOutlookBarAggregateId(IRequestCycle cycle)
113 {
114 return (String) cycle.getAttribute(AGGREGATE_ID);
115 }
116
117 protected void setupComponent(IRequestCycle cycle)
118 {
119 cycle.setAttribute(OUTLOOK_BAR_CONTROL, this);
120
121 OutlookPane.setOutlookPaneCount(cycle, null);
122 OutlookBar.setOutlookBarCount(cycle, null);
123 String selected_id = null;
124 HttpSession session;
125 if (getForceSession())
126 {
127 session = cycle.getRequestContext().createSession();
128 if (session != null)
129 {
130 selected_id = (String) session.getAttribute(OutlookLink.SELECTED_OUTLOOK_LINK_ID);
131 }
132 }
133 if (selected_id == null)
134 {
135 selected_id = this.getId() + "$0";
136 }
137 log.debug("trigger the selected pane is = " + selected_id);
138 log.debug("Initing Outlook bar");
139 Integer value = OutlookBar.getOutlookBarCount(cycle);
140 OutlookBar.setOutlookBarCount(cycle, value);
141 OutlookBar.setOutlookBarCurrentId(cycle, getId());
142
143 log.debug("outlook_bar_count: " + value);
144
145
146
147
148 if (script == null)
149 {
150 IScriptSource source = cycle.getEngine().getScriptSource();
151 IResourceLocation location =
152 getSpecification().getLocation().getResourceLocation();
153 IResourceLocation script_location =
154 location.getRelativeLocation("OutlookBar.script");
155 script = source.getScript(script_location);
156 }
157 Body body = Body.get(cycle);
158 if (body == null)
159 {
160 throw Tapestry.createRequiredParameterException(this,
161 "You need to provide a @Body around this component");
162 }
163 Map symbols = new HashMap();
164 symbols.put("selectedPaneId", selected_id);
165 symbols.put("barId", this.getId());
166 symbols.put("cookies", new Boolean(!this.getForceSession()));
167 script.execute(cycle, body, symbols);
168 }
169 }