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