1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.widget;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
20 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
21 import org.kuali.rice.krad.datadictionary.HelpDefinition;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
24 import org.kuali.rice.krad.service.KRADServiceLocator;
25 import org.kuali.rice.krad.uif.component.Component;
26 import org.kuali.rice.krad.uif.element.Action;
27 import org.kuali.rice.krad.uif.view.View;
28 import org.kuali.rice.krad.uif.UifConstants;
29 import org.kuali.rice.krad.uif.util.ComponentFactory;
30
31 import java.text.MessageFormat;
32 import java.util.List;
33
34
35
36
37
38
39
40
41
42
43 @BeanTag(name = "help-bean", parent = "Uif-Help")
44 public class Help extends WidgetBase {
45 private static final long serialVersionUID = -1514436681476297241L;
46
47 private Action helpAction;
48 private HelpDefinition helpDefinition;
49 private String externalHelpUrl;
50
51 private String tooltipHelpContent;
52
53
54
55
56
57
58
59
60
61
62
63
64 @Override
65 public void performInitialization(View view, Object model) {
66 super.performInitialization(view, model);
67
68 if (helpAction == null) {
69
70 if ((StringUtils.isNotBlank(externalHelpUrl) || (getPropertyExpression("externalHelpUrl") != null))
71 || ((helpDefinition != null) && StringUtils.isNotBlank(helpDefinition.getParameterName()))
72 && StringUtils.isNotBlank(helpDefinition.getParameterDetailType())) {
73 helpAction = ComponentFactory.getHelpAction();
74
75 view.assignComponentIds(helpAction);
76 helpAction.addDataAttribute("role", "help");
77 }
78 }
79 else{
80 helpAction.addDataAttribute("role", "help");
81 }
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96 @Override
97 public void performFinalize(View view, Object model, Component parent) {
98 super.performFinalize(view, model, parent);
99
100 buildExternalHelp(view, parent);
101 buildTooltipHelp(parent);
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 protected void buildExternalHelp(View view, Component parent) {
125 if (StringUtils.isBlank(externalHelpUrl) && (helpDefinition != null)) {
126 if (StringUtils.isBlank(helpDefinition.getParameterNamespace())) {
127 helpDefinition.setParameterNamespace(view.getNamespaceCode());
128 }
129
130 if (StringUtils.isNotBlank(helpDefinition.getParameterNamespace())
131 && StringUtils.isNotBlank(helpDefinition.getParameterDetailType())
132 && StringUtils.isNotBlank(helpDefinition.getParameterName())) {
133 externalHelpUrl = getParameterService().getParameterValueAsString(helpDefinition.getParameterNamespace(),
134 helpDefinition.getParameterDetailType(), helpDefinition.getParameterName());
135 }
136 }
137
138 if (StringUtils.isNotBlank(externalHelpUrl)) {
139
140 getHelpAction().setActionScript("openHelpWindow('" + externalHelpUrl + "')");
141
142
143 String helpTitle;
144
145
146 if ((parent instanceof Helpable) && (((Helpable) parent).getHelp() == this)) {
147 helpTitle = MessageFormat.format(
148 KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
149 "help.icon.title.tag.with.field.label"), ((Helpable) parent).getHelpTitle());
150 } else {
151 helpTitle = KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
152 "help.icon.title.tag");
153 }
154
155 getHelpAction().getActionImage().setAltText(helpTitle);
156 getHelpAction().getActionImage().setTitle(helpTitle);
157 }
158 }
159
160
161
162
163
164
165
166
167
168
169
170 protected void buildTooltipHelp(Component parent) {
171 if (StringUtils.isNotBlank(tooltipHelpContent) && this.isRender()) {
172
173 if ((parent instanceof Helpable) && (((Helpable) parent).getHelp() == this)) {
174 this.getToolTip().setTooltipContent(tooltipHelpContent);
175 ((Helpable) parent).setTooltipOfComponent(this.getToolTip());
176 }
177 }
178 }
179
180
181
182
183 @Override
184 public List<Component> getComponentsForLifecycle() {
185 List<Component> components = super.getComponentsForLifecycle();
186
187 components.add(helpAction);
188
189 return components;
190 }
191
192
193
194
195
196
197 @BeanTagAttribute(name="helpAction",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
198 public Action getHelpAction() {
199 return helpAction;
200 }
201
202
203
204
205
206
207 public void setHelpAction(Action helpAction) {
208 this.helpAction = helpAction;
209 }
210
211
212
213
214
215
216
217 @BeanTagAttribute(name="helpDefinition",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
218 public HelpDefinition getHelpDefinition() {
219 return helpDefinition;
220 }
221
222
223
224
225
226
227 public void setHelpDefinition(HelpDefinition helpDefinition) {
228 this.helpDefinition = helpDefinition;
229 }
230
231
232
233
234
235
236
237
238
239
240
241 @BeanTagAttribute(name="externalHelpUrl")
242 public String getExternalHelpUrl() {
243 return this.externalHelpUrl;
244 }
245
246
247
248
249
250
251 public void setExternalHelpUrl(String externalHelpUrl) {
252 this.externalHelpUrl = externalHelpUrl;
253 }
254
255
256
257
258
259
260 @BeanTagAttribute(name="tooltipHelpContent")
261 public String getTooltipHelpContent() {
262 return this.tooltipHelpContent;
263 }
264
265
266
267
268
269
270 public void setTooltipHelpContent(String tooltipHelpContent) {
271 this.tooltipHelpContent = tooltipHelpContent;
272 }
273
274
275
276
277
278
279 protected ParameterService getParameterService() {
280 return CoreFrameworkServiceLocator.getParameterService();
281 }
282
283 }