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
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.tapestry.IRequestCycle;
24 import org.apache.tapestry.IScript;
25 import org.apache.tapestry.PageRenderSupport;
26 import org.apache.tapestry.TapestryUtils;
27
28 import net.sf.tapfx.components.TapFXBaseComponent;
29
30 /***
31 * This component encloses a panes. It decorates
32 * the enclosed panes. It also starts basic state
33 * management...
34 *
35 * @author Joshua Long (josh@joshlong.com)
36 * @author andyhot
37 * @version $Id: OutlookBar.java,v 1.2 2005/11/04 23:37:22 andyhot Exp $
38 */
39 public abstract class OutlookBar extends TapFXBaseComponent
40 {
41 private static final Log log =
42 LogFactory.getLog(OutlookBar.class);
43
44 private static final String OUTLOOK_BAR_COUNT =
45 "net.sf.tapfx.components.outlookbar.outlook_bar_count_id";
46 private static final String AGGREGATE_ID =
47 "net.sf.tapfx.components.outlookbar.aggregate id string";
48 private static final String OUTLOOK_BAR_CURRENT_ID =
49 "net.sf.tapfx.components.outlookbar.outlook_bar_current_id";
50 private static final String OUTLOOK_BAR_CONTROL =
51 "net.sf.tapfx.components.outlookbar.OutlookBar";
52
53 public abstract IScript getScript();
54
55 public abstract String getCssPrefix();
56
57 public abstract boolean getForceSession();
58
59 public abstract String getTitle();
60 public abstract void setTitle(String title);
61
62 public abstract String getSelection();
63 public abstract void setSelection(String selection);
64
65 public String getPrefix()
66 {
67 String ret = getCssPrefix();
68 if (ret == null)
69 ret = "";
70 return ret;
71 }
72
73 public static OutlookBar getOutlookBar(IRequestCycle cycle)
74 {
75 return (OutlookBar) cycle.getAttribute(OUTLOOK_BAR_CONTROL);
76 }
77
78 static void setOutlookBarCount(IRequestCycle cycle, Integer obj)
79 {
80 cycle.setAttribute(OutlookBar.OUTLOOK_BAR_COUNT, obj);
81 }
82
83 static Integer getOutlookBarCount(IRequestCycle cycle)
84 {
85 Integer value = (Integer)
86 cycle.getAttribute(OutlookBar.OUTLOOK_BAR_COUNT);
87 if (null == value)
88 {
89 value = new Integer(0);
90 }
91 else
92 {
93 value = new Integer(value.intValue() + 1);
94 }
95 return value;
96 }
97
98 static void setOutlookBarCurrentId(IRequestCycle cycle, String obj)
99 {
100 cycle.setAttribute(OutlookBar.OUTLOOK_BAR_CURRENT_ID, obj);
101 }
102
103 static String getOutlookBarCurrentId(IRequestCycle cycle)
104 {
105 return (String) cycle.getAttribute(OutlookBar.OUTLOOK_BAR_CURRENT_ID);
106 }
107
108 static void setOutlookBarAggregateId(IRequestCycle cycle, String id)
109 {
110 cycle.setAttribute(AGGREGATE_ID, id);
111 }
112
113 static String getOutlookBarAggregateId(IRequestCycle cycle)
114 {
115 return (String) cycle.getAttribute(AGGREGATE_ID);
116 }
117
118 protected void setupComponent(IRequestCycle cycle)
119 {
120 cycle.setAttribute(OUTLOOK_BAR_CONTROL, this);
121
122 OutlookPane.setOutlookPaneCount(cycle, null);
123 OutlookBar.setOutlookBarCount(cycle, null);
124 String selected_id = null;
125 if (getForceSession())
126 {
127 selected_id = getSelection();
128 }
129 if (selected_id == null || selected_id.length()==0)
130 {
131 selected_id = this.getId() + "$0";
132 }
133 log.debug("trigger the selected pane is = " + selected_id);
134 log.debug("Initing Outlook bar");
135 Integer value = OutlookBar.getOutlookBarCount(cycle);
136 OutlookBar.setOutlookBarCount(cycle, value);
137 OutlookBar.setOutlookBarCurrentId(cycle, getId());
138
139 log.debug("outlook_bar_count: " + value);
140
141 Map symbols = new HashMap();
142 symbols.put("selectedPaneId", selected_id);
143 symbols.put("barId", this.getId());
144 symbols.put("cookies", new Boolean(!this.getForceSession()));
145
146 PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
147 getScript().execute(cycle, pageRenderSupport, symbols);
148 }
149 }