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 java.text.MessageFormat;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.rice.core.api.CoreApiServiceLocator;
22 import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
23 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
24 import org.kuali.rice.krad.datadictionary.HelpDefinition;
25 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
26 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
27 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean;
28 import org.kuali.rice.krad.uif.CssConstants;
29 import org.kuali.rice.krad.uif.UifConstants;
30 import org.kuali.rice.krad.uif.element.Action;
31 import org.kuali.rice.krad.uif.field.InputField;
32 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
33 import org.kuali.rice.krad.uif.util.ComponentFactory;
34 import org.kuali.rice.krad.uif.util.LifecycleElement;
35 import org.kuali.rice.krad.uif.view.ExpressionEvaluator;
36
37
38
39
40
41
42
43
44
45
46 @BeanTag(name = "help", parent = "Uif-Help")
47 public class Help extends WidgetBase {
48 private static final long serialVersionUID = -1514436681476297241L;
49
50 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(Help.class);
51
52 private Action helpAction;
53 private HelpDefinition helpDefinition;
54 private String externalHelpUrl;
55
56 private String tooltipHelpContent;
57
58
59
60
61
62
63
64
65
66
67
68 @Override
69 public void performInitialization(Object model) {
70 super.performInitialization(model);
71
72 if (helpAction == null) {
73 if(hasValueOrPropertyExpression(externalHelpUrl, this, "externalHelpUrl") || (
74 helpDefinition != null &&
75 hasValueOrPropertyExpression(helpDefinition.getParameterName(), helpDefinition, "parameterName") &&
76 hasValueOrPropertyExpression(helpDefinition.getParameterDetailType(), helpDefinition, "parameterDetailType")
77 )){
78 helpAction = ComponentFactory.getHelpAction();
79 helpAction.addDataAttribute(UifConstants.DataAttributes.ROLE, "help");
80 }
81 }
82 else{
83 helpAction.addDataAttribute(UifConstants.DataAttributes.ROLE, "help");
84 }
85 }
86
87
88
89
90
91
92
93
94
95 private boolean hasValueOrPropertyExpression(String defaultValue, UifDictionaryBean dictionaryBean, String expressionName) {
96 return StringUtils.isNotBlank(defaultValue) || (dictionaryBean != null && dictionaryBean.getPropertyExpressions() != null &&
97 StringUtils.isNotBlank(dictionaryBean.getPropertyExpression(expressionName)));
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112 @Override
113 public void performFinalize(Object model, LifecycleElement parent) {
114 super.performFinalize(model, parent);
115
116 buildExternalHelp(parent);
117 buildTooltipHelp(parent);
118
119
120 if (StringUtils.isBlank(this.externalHelpUrl) && StringUtils.isBlank(this.tooltipHelpContent)) {
121 setRender(false);
122 }
123
124
125 if (parent != null && !(parent instanceof InputField) && helpAction != null) {
126 helpAction.getLibraryCssClasses().remove(CssConstants.Classes.BTN);
127 helpAction.getLibraryCssClasses().remove(CssConstants.Classes.BTN_DEFAULT);
128 helpAction.getLibraryCssClasses().add(CssConstants.Classes.ICON_ONLY_BUTTON);
129 }
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 protected void buildExternalHelp(LifecycleElement parent) {
152 if (StringUtils.isBlank(externalHelpUrl) && (helpDefinition != null)) {
153 if (StringUtils.isBlank(helpDefinition.getParameterNamespace())) {
154 helpDefinition.setParameterNamespace(ViewLifecycle.getView().getNamespaceCode());
155 }
156
157 String parameterNamespace = helpDefinition.getParameterNamespace();
158 String parameterDetailType = helpDefinition.getParameterDetailType();
159 String parameterName = helpDefinition.getParameterName();
160
161 ExpressionEvaluator expressionEvaluator = ViewLifecycle.getExpressionEvaluator();
162 if (parameterNamespace == null && helpDefinition.getPropertyExpression("parameterNamespace") != null) {
163 parameterNamespace = (String) expressionEvaluator.evaluateExpression(this.getContext(),
164 helpDefinition.getPropertyExpression("parameterNamespace"));
165 }
166
167 if (parameterDetailType == null && helpDefinition.getPropertyExpression("parameterDetailType") != null) {
168 parameterDetailType = (String) expressionEvaluator.evaluateExpression(this.getContext(),
169 helpDefinition.getPropertyExpression("parameterDetailType"));
170 }
171
172 if (parameterName == null && helpDefinition.getPropertyExpression("parameterName") != null) {
173 parameterName = (String) expressionEvaluator.evaluateExpression(this.getContext(),
174 helpDefinition.getPropertyExpression("parameterName"));
175 }
176
177 if (StringUtils.isNotBlank(parameterNamespace)
178 && StringUtils.isNotBlank(parameterDetailType)
179 && StringUtils.isNotBlank(parameterName)) {
180 externalHelpUrl = getParameterService().getParameterValueAsFilteredString(
181 parameterNamespace, parameterDetailType, parameterName);
182 }
183 }
184
185 if (StringUtils.isNotBlank(externalHelpUrl)) {
186
187 getHelpAction().setActionScript("openHelpWindow('" + externalHelpUrl + "')");
188
189
190 String helpTitle;
191
192
193 if ((parent instanceof Helpable) && (((Helpable) parent).getHelp() == this)) {
194 helpTitle = MessageFormat.format(
195 CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
196 "help.icon.title.tag.with.field.label"), ((Helpable) parent).getHelpTitle());
197 } else {
198 helpTitle = CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
199 "help.icon.title.tag");
200 }
201
202 getHelpAction().setTitle(helpTitle);
203 }
204 }
205
206
207
208
209
210
211
212
213
214
215
216 protected void buildTooltipHelp(LifecycleElement parent) {
217 if (StringUtils.isNotBlank(tooltipHelpContent) && this.isRender()) {
218
219 if (this.getToolTip() != null && (parent instanceof Helpable)
220 && (((Helpable) parent).getHelp() == this)) {
221 this.getToolTip().setTooltipContent(tooltipHelpContent);
222 ((Helpable) parent).setTooltipOfComponent(this.getToolTip());
223 }
224 }
225 }
226
227
228
229
230
231
232 @BeanTagAttribute
233 public Action getHelpAction() {
234 return helpAction;
235 }
236
237
238
239
240
241
242 public void setHelpAction(Action helpAction) {
243 this.helpAction = helpAction;
244 }
245
246
247
248
249
250
251
252 @BeanTagAttribute(type= BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
253 public HelpDefinition getHelpDefinition() {
254 return helpDefinition;
255 }
256
257
258
259
260
261
262 public void setHelpDefinition(HelpDefinition helpDefinition) {
263 this.helpDefinition = helpDefinition;
264 }
265
266
267
268
269
270
271
272
273
274
275
276 @BeanTagAttribute
277 public String getExternalHelpUrl() {
278 return this.externalHelpUrl;
279 }
280
281
282
283
284
285
286 public void setExternalHelpUrl(String externalHelpUrl) {
287 this.externalHelpUrl = externalHelpUrl;
288 }
289
290
291
292
293
294
295 @BeanTagAttribute
296 public String getTooltipHelpContent() {
297 return this.tooltipHelpContent;
298 }
299
300
301
302
303
304
305 public void setTooltipHelpContent(String tooltipHelpContent) {
306 this.tooltipHelpContent = tooltipHelpContent;
307 }
308
309
310
311
312
313
314 protected ParameterService getParameterService() {
315 return CoreFrameworkServiceLocator.getParameterService();
316 }
317 }