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