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 org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.apache.tapestry.*;
21 import org.apache.tapestry.engine.IEngineService;
22 import org.apache.tapestry.engine.ILink;
23
24 import net.sf.tapfx.components.TapFXBaseComponent;
25
26
27 /***
28 * This provides many services and renders
29 * an icon as well as its label.
30 * You might imagine this where the Mail,
31 * or Calendar icons in Outlook are.
32 * <p/>
33 * Yuck.. I know this could be prettier.
34 *
35 * @author Joshua Long (josh@joshlong.com)
36 */
37 public abstract class OutlookLink extends TapFXBaseComponent
38
39 {
40 private static final Log log =
41 LogFactory.getLog(OutlookPane.class);
42
43 private String prefix;
44
45 public static final String SELECTED_OUTLOOK_LINK_ID =
46 "SELECTED_OUTLOOK_LINK_ID_";
47
48
49 public abstract String getPageName();
50
51 public abstract void setPageName(String page);
52
53 public abstract String getDirectUrl();
54
55 public abstract void setDirectUrl(String directUrl);
56
57 public abstract IActionListener getListener();
58
59 public abstract void setListener(IActionListener directLink);
60
61 public abstract IAsset getImage();
62
63 public abstract void setImage(IAsset asset);
64
65 public abstract String getImageUrl();
66
67 public abstract void setImageUrl(String imageUrl);
68
69
70
71
72
73
74
75 public abstract String getSelectedId();
76
77 public abstract void setSelectedId(String selectedId);
78
79 public abstract boolean isRestart();
80
81 public abstract void setRestart(boolean restart);
82
83 public boolean isStateful()
84 {
85 return false;
86 }
87
88 public String getPrefix()
89 {
90 return prefix;
91 }
92
93 public void trigger(IRequestCycle cycle)
94 {
95 IActionListener listener = getListener();
96 Object[] params = cycle.getServiceParameters();
97 for (int i = 0; i < params.length; i++)
98 {
99 log.debug("Inside trigger(), the param is " + params[i]);
100 }
101 if (listener == null)
102 {
103 throw Tapestry.createRequiredParameterException(this,
104 "directLink");
105 }
106 listener.actionTriggered(this, cycle);
107 if (OutlookBar.getOutlookBar(cycle).getForceSession())
108 {
109 cycle.getRequestContext().createSession().setAttribute(OutlookLink.SELECTED_OUTLOOK_LINK_ID, params[0]);
110 }
111 }
112
113 public void gotoPageAction(IRequestCycle cycle)
114 {
115
116 String id = OutlookBar.getOutlookBarAggregateId(cycle);
117 String pn = getPageName();
118
119 if (OutlookBar.getOutlookBar(cycle).getForceSession())
120 {
121 cycle.getRequestContext().createSession().setAttribute(OutlookLink.SELECTED_OUTLOOK_LINK_ID, id);
122 }
123 log.debug("goto setting memory: page is =" + pn + "selected id=" + id);
124
125 if (this.getPageName() != null)
126 {
127 log.debug("goto Forwarding to a page");
128 IPage page = cycle.getPage(getPageName());
129 cycle.activate(page);
130 }
131 else
132 {
133 log.debug("goto Invoking listener");
134 getListener().actionTriggered(this, cycle);
135 }
136 }
137
138 protected void setupComponent(IRequestCycle cycle)
139 {
140 if (cycle.isRewinding())
141 {
142 return;
143 }
144
145 prefix = OutlookBar.getOutlookBar(cycle).getPrefix();
146
147 IAsset img = getImage();
148 String url = img.buildURL(cycle);
149 setImageUrl(url);
150
151 String id = OutlookBar.getOutlookBarAggregateId(cycle);
152 setSelectedId(id);
153
154 Object[] params = {id};
155 IEngineService service =
156 cycle.getEngine().getService(Tapestry.DIRECT_SERVICE);
157 ILink link = service.getLink(cycle, this, params);
158 setDirectUrl(link.getURL());
159
160 /***
161 * service =
162 cycle.getEngine().getService(Tapestry.ACTION_SERVICE );
163 service.getLink(cycle, this, new Object[]{});
164
165 /// Object id = cycle.getAttribute(OutlookBar.AGGREGATE_ID);
166 // String pn = getPageName();
167 // log("the page name for this link is: " + pn + "; and the
168 selectedId is " + id);
169 //
170 cycle.getRequestContext().createSession().setAttribute(OutlookLink.SELECTED_OUTLOOK_LINK_ID, id);
171 */
172 if (isRestart())
173 log.debug("This is a restart link");
174
175
176 }
177
178 }
179