1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.element;
17
18 import java.io.Serializable;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.krad.datadictionary.Copyable;
24 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
25 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
26 import org.kuali.rice.krad.uif.container.Container;
27 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
28 import org.kuali.rice.krad.uif.util.ComponentUtils;
29 import org.kuali.rice.krad.uif.util.ContextUtils;
30 import org.kuali.rice.krad.uif.view.View;
31 import org.kuali.rice.krad.util.KRADUtils;
32 import org.kuali.rice.krad.web.form.HistoryFlow;
33 import org.kuali.rice.krad.web.form.UifFormBase;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 @BeanTag(name = "breadcrumbOptions", parent = "Uif-BreadcrumbOptions")
49 public class BreadcrumbOptions implements Serializable, Copyable {
50 private static final long serialVersionUID = -6705552809624394000L;
51
52
53 private List<BreadcrumbItem> homewardPathBreadcrumbs;
54 private List<BreadcrumbItem> preViewBreadcrumbs;
55 private List<BreadcrumbItem> prePageBreadcrumbs;
56 private List<BreadcrumbItem> breadcrumbOverrides;
57
58
59
60
61
62
63 public void setupBreadcrumbs(Object model) {
64 View view = ViewLifecycle.getView();
65
66 if (model != null && model instanceof UifFormBase) {
67 UifFormBase form = (UifFormBase) model;
68
69
70 boolean usingFlow = StringUtils.isNotBlank(form.getFlowKey()) || (view.getBreadcrumbs() != null && view
71 .getBreadcrumbs().isUsePathBasedBreadcrumbs());
72
73
74 if (usingFlow && form.getHistoryManager() != null) {
75
76
77 String formKey = form.getRequestedFormKey();
78 if (StringUtils.isBlank(formKey)) {
79 formKey = form.getFormKey();
80 form.setRequestedFormKey(formKey);
81 }
82
83
84 HistoryFlow historyFlow = form.getHistoryManager().process(form.getFlowKey(), formKey,
85 form.getRequestUrl());
86 if (historyFlow != null) {
87 form.setHistoryFlow(historyFlow);
88 form.setFlowKey(historyFlow.getFlowKey());
89 }
90 }
91
92 view.getBreadcrumbs().setUsePathBasedBreadcrumbs(usingFlow);
93
94
95 if (view.getBreadcrumbs() != null
96 && view.getBreadcrumbs().isUsePathBasedBreadcrumbs()
97 && form.getHistoryFlow() != null
98 && form.getHistoryFlow().getPastItems() != null) {
99 List<BreadcrumbItem> pastItems = form.getHistoryFlow().getPastItems();
100 ComponentUtils.clearAndAssignIds(pastItems);
101 view.setPathBasedBreadcrumbs(pastItems);
102 }
103 }
104 }
105
106
107
108
109
110
111
112
113
114 public void finalizeBreadcrumbs(Object model, Container parent, BreadcrumbItem breadcrumbItem) {
115 View view = ViewLifecycle.getView();
116
117
118 if (StringUtils.isBlank(breadcrumbItem.getLabel()) && view.getHeader() != null && !StringUtils.isBlank(
119 view.getHeader().getHeaderText()) && model instanceof UifFormBase) {
120 breadcrumbItem.setLabel(KRADUtils.generateUniqueViewTitle((UifFormBase) model, view));
121 }
122
123
124 if (StringUtils.isBlank(breadcrumbItem.getLabel())) {
125 breadcrumbItem.setRender(false);
126 }
127
128
129 finalizeBreadcrumbsUrl(model, parent, breadcrumbItem);
130
131
132
133 if (breadcrumbItem.getUrl().getPageId() == null && !view.getBreadcrumbs().isUsePathBasedBreadcrumbs()) {
134
135 if (view.getEntryPageId() != null) {
136 breadcrumbItem.getUrl().setPageId(view.getEntryPageId());
137 } else if (view.isSinglePageView() && view.getPage() != null) {
138
139 breadcrumbItem.getUrl().setPageId(view.getPage().getId());
140 } else if (!view.getItems().isEmpty() && view.getItems().get(0) != null) {
141
142 breadcrumbItem.getUrl().setPageId(view.getItems().get(0).getId());
143 }
144 }
145
146
147 if (model instanceof UifFormBase && ((UifFormBase) model).getHistoryFlow() != null) {
148
149 ContextUtils.cleanContextDeep(view.getBreadcrumbItem());
150
151 ((UifFormBase) model).getHistoryFlow().setCurrentViewItem(view.getBreadcrumbItem());
152 }
153 }
154
155
156
157
158
159
160
161
162 protected void finalizeBreadcrumbsUrl(Object model, Container parent, BreadcrumbItem breadcrumbItem) {
163
164 if (breadcrumbItem.getUrl().getControllerMapping() == null
165 && breadcrumbItem.getUrl().getViewId() == null
166 && model instanceof UifFormBase
167 && breadcrumbItem.getUrl().getRequestParameters() == null
168 && ((UifFormBase) model).getInitialRequestParameters() != null) {
169
170
171 Map<String, String[]> requestParameters = ((UifFormBase) model).getInitialRequestParameters();
172
173
174 requestParameters.remove("ajaxReturnType");
175 requestParameters.remove("ajaxRequest");
176
177
178 requestParameters.remove("pageId");
179
180 breadcrumbItem.getUrl().setRequestParameters(KRADUtils.translateRequestParameterMap(requestParameters));
181 }
182
183
184 if (breadcrumbItem.getUrl().getFormKey() == null
185 && model instanceof UifFormBase
186 && ((UifFormBase) model).getFormKey() != null) {
187 breadcrumbItem.getUrl().setFormKey(((UifFormBase) model).getFormKey());
188 }
189
190
191 if (breadcrumbItem.getUrl().getControllerMapping() == null && model instanceof UifFormBase) {
192 breadcrumbItem.getUrl().setControllerMapping(((UifFormBase) model).getControllerMapping());
193 }
194
195 if (breadcrumbItem.getUrl().getViewId() == null) {
196 breadcrumbItem.getUrl().setViewId(ViewLifecycle.getView().getId());
197 }
198 }
199
200
201
202
203
204
205
206 @BeanTagAttribute(name = "homewardPathBreadcrumbs", type = BeanTagAttribute.AttributeType.LISTBEAN)
207 public List<BreadcrumbItem> getHomewardPathBreadcrumbs() {
208 return homewardPathBreadcrumbs;
209 }
210
211
212
213
214
215
216 public void setHomewardPathBreadcrumbs(List<BreadcrumbItem> homewardPathBreadcrumbs) {
217 this.homewardPathBreadcrumbs = homewardPathBreadcrumbs;
218 }
219
220
221
222
223
224
225
226 @BeanTagAttribute(name = "preViewBreadcrumbs", type = BeanTagAttribute.AttributeType.LISTBEAN)
227 public List<BreadcrumbItem> getPreViewBreadcrumbs() {
228 return preViewBreadcrumbs;
229 }
230
231
232
233
234
235
236 public void setPreViewBreadcrumbs(List<BreadcrumbItem> preViewBreadcrumbs) {
237 this.preViewBreadcrumbs = preViewBreadcrumbs;
238 }
239
240
241
242
243
244
245
246 @BeanTagAttribute(name = "prePageBreadcrumbs", type = BeanTagAttribute.AttributeType.LISTBEAN)
247 public List<BreadcrumbItem> getPrePageBreadcrumbs() {
248 return prePageBreadcrumbs;
249 }
250
251
252
253
254
255
256 public void setPrePageBreadcrumbs(List<BreadcrumbItem> prePageBreadcrumbs) {
257 this.prePageBreadcrumbs = prePageBreadcrumbs;
258 }
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274 @BeanTagAttribute(name = "breadcrumbOverrides", type = BeanTagAttribute.AttributeType.LISTBEAN)
275 public List<BreadcrumbItem> getBreadcrumbOverrides() {
276 return breadcrumbOverrides;
277 }
278
279
280
281
282
283
284 public void setBreadcrumbOverrides(List<BreadcrumbItem> breadcrumbOverrides) {
285 this.breadcrumbOverrides = breadcrumbOverrides;
286 }
287
288
289
290
291 @Override
292 public BreadcrumbOptions clone() throws CloneNotSupportedException {
293 return (BreadcrumbOptions) super.clone();
294 }
295
296 }