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.UifConstants;
28 import org.kuali.rice.krad.uif.element.Action;
29 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
30 import org.kuali.rice.krad.uif.util.ComponentFactory;
31 import org.kuali.rice.krad.uif.util.LifecycleElement;
32
33
34
35
36
37
38
39
40
41
42 @BeanTag(name = "help-bean", parent = "Uif-Help")
43 public class Help extends WidgetBase {
44 private static final long serialVersionUID = -1514436681476297241L;
45
46 private Action helpAction;
47 private HelpDefinition helpDefinition;
48 private String externalHelpUrl;
49
50 private String tooltipHelpContent;
51
52
53
54
55
56
57
58
59
60
61
62 @Override
63 public void performInitialization(Object model) {
64 super.performInitialization(model);
65
66 if (helpAction == null) {
67
68 if ((StringUtils.isNotBlank(externalHelpUrl) || (getPropertyExpression("externalHelpUrl") != null))
69 || ((helpDefinition != null) && StringUtils.isNotBlank(helpDefinition.getParameterName()))
70 && StringUtils.isNotBlank(helpDefinition.getParameterDetailType())) {
71 helpAction = ComponentFactory.getHelpAction();
72 helpAction.addDataAttribute(UifConstants.DataAttributes.ROLE, "help");
73 }
74 }
75 else{
76 helpAction.addDataAttribute(UifConstants.DataAttributes.ROLE, "help");
77 }
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91
92 @Override
93 public void performFinalize(Object model, LifecycleElement parent) {
94 super.performFinalize(model, parent);
95
96 buildExternalHelp(parent);
97 buildTooltipHelp(parent);
98
99
100 if (StringUtils.isBlank(this.externalHelpUrl) && StringUtils.isBlank(this.tooltipHelpContent)) {
101 setRender(false);
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(LifecycleElement parent) {
125 if (StringUtils.isBlank(externalHelpUrl) && (helpDefinition != null)) {
126 if (StringUtils.isBlank(helpDefinition.getParameterNamespace())) {
127 helpDefinition.setParameterNamespace(ViewLifecycle.getView().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 CoreApiServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
149 "help.icon.title.tag.with.field.label"), ((Helpable) parent).getHelpTitle());
150 } else {
151 helpTitle = CoreApiServiceLocator.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(LifecycleElement parent) {
171 if (StringUtils.isNotBlank(tooltipHelpContent) && this.isRender()) {
172
173 if (this.getToolTip() != null && (parent instanceof Helpable)
174 && (((Helpable) parent).getHelp() == this)) {
175 this.getToolTip().setTooltipContent(tooltipHelpContent);
176 ((Helpable) parent).setTooltipOfComponent(this.getToolTip());
177 }
178 }
179 }
180
181
182
183
184
185
186 @BeanTagAttribute(name="helpAction",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
187 public Action getHelpAction() {
188 return helpAction;
189 }
190
191
192
193
194
195
196 public void setHelpAction(Action helpAction) {
197 this.helpAction = helpAction;
198 }
199
200
201
202
203
204
205
206 @BeanTagAttribute(name="helpDefinition",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
207 public HelpDefinition getHelpDefinition() {
208 return helpDefinition;
209 }
210
211
212
213
214
215
216 public void setHelpDefinition(HelpDefinition helpDefinition) {
217 this.helpDefinition = helpDefinition;
218 }
219
220
221
222
223
224
225
226
227
228
229
230 @BeanTagAttribute(name="externalHelpUrl")
231 public String getExternalHelpUrl() {
232 return this.externalHelpUrl;
233 }
234
235
236
237
238
239
240 public void setExternalHelpUrl(String externalHelpUrl) {
241 this.externalHelpUrl = externalHelpUrl;
242 }
243
244
245
246
247
248
249 @BeanTagAttribute(name="tooltipHelpContent")
250 public String getTooltipHelpContent() {
251 return this.tooltipHelpContent;
252 }
253
254
255
256
257
258
259 public void setTooltipHelpContent(String tooltipHelpContent) {
260 this.tooltipHelpContent = tooltipHelpContent;
261 }
262
263
264
265
266
267
268 protected ParameterService getParameterService() {
269 return CoreFrameworkServiceLocator.getParameterService();
270 }
271 }