1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.lifecycle;
17
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Queue;
21 import java.util.Set;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.rice.krad.uif.UifConstants;
25 import org.kuali.rice.krad.uif.component.Component;
26 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle.LifecycleEvent;
27 import org.kuali.rice.krad.uif.lifecycle.finalize.SetReadOnlyOnDataBindingTask;
28 import org.kuali.rice.krad.uif.lifecycle.model.AfterEvaluateExpressionTask;
29 import org.kuali.rice.krad.uif.lifecycle.model.ApplyAuthAndPresentationLogicTask;
30 import org.kuali.rice.krad.uif.lifecycle.model.ComponentDefaultApplyModelTask;
31 import org.kuali.rice.krad.uif.lifecycle.model.EvaluateExpressionsTask;
32 import org.kuali.rice.krad.uif.lifecycle.model.HelperCustomApplyModelTask;
33 import org.kuali.rice.krad.uif.lifecycle.model.PopulateComponentContextTask;
34 import org.kuali.rice.krad.uif.lifecycle.model.RefreshStateModifyTask;
35 import org.kuali.rice.krad.uif.lifecycle.model.SuffixIdFromContainerTask;
36 import org.kuali.rice.krad.uif.lifecycle.model.SyncClientSideStateTask;
37 import org.kuali.rice.krad.uif.util.LifecycleElement;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 public class ApplyModelComponentPhase extends ViewLifecyclePhaseBase {
65
66
67
68
69
70
71
72
73 private Set<String> visitedIds;
74
75
76
77
78 @Override
79 protected void recycle() {
80 super.recycle();
81 visitedIds = null;
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95 protected void prepare(LifecycleElement element, Object model, String path, List<String> refreshPaths,
96 Component parent, ViewLifecyclePhaseBase nextPhase, Set<String> visitedIds) {
97 super.prepare(element, model, path, refreshPaths, parent, nextPhase);
98
99 this.visitedIds = visitedIds;
100 }
101
102
103
104
105 @Override
106 public String getViewPhase() {
107 return UifConstants.ViewPhases.APPLY_MODEL;
108 }
109
110
111
112
113 @Override
114 public String getStartViewStatus() {
115 return UifConstants.ViewStatus.INITIALIZED;
116 }
117
118
119
120
121 @Override
122 public String getEndViewStatus() {
123 return UifConstants.ViewStatus.MODEL_APPLIED;
124 }
125
126
127
128
129 @Override
130 public LifecycleEvent getEventToNotify() {
131 return null;
132 }
133
134
135
136
137
138
139
140 public boolean visit(LifecycleElement element) {
141 if (visitedIds.contains(element.getId())) {
142 return true;
143 }
144
145 synchronized (visitedIds) {
146 return !visitedIds.add(element.getId());
147 }
148 }
149
150
151
152
153
154
155
156
157
158
159
160
161
162 @Override
163 protected void initializePendingTasks(Queue<ViewLifecycleTask<?>> tasks) {
164 if ((getParent() != null) && StringUtils.isNotBlank(getParent().getContainerIdSuffix())) {
165 tasks.add(LifecycleTaskFactory.getTask(SuffixIdFromContainerTask.class, this));
166 }
167
168 tasks.add(LifecycleTaskFactory.getTask(PopulateComponentContextTask.class, this));
169 tasks.add(LifecycleTaskFactory.getTask(EvaluateExpressionsTask.class, this));
170 tasks.add(LifecycleTaskFactory.getTask(AfterEvaluateExpressionTask.class, this));
171
172 tasks.add(LifecycleTaskFactory.getTask(SyncClientSideStateTask.class, this));
173 tasks.add(LifecycleTaskFactory.getTask(ApplyAuthAndPresentationLogicTask.class, this));
174
175 if (ViewLifecycle.isRefreshComponent(getViewPhase(), getViewPath())) {
176 tasks.add(LifecycleTaskFactory.getTask(RefreshStateModifyTask.class, this));
177 }
178
179 tasks.add(LifecycleTaskFactory.getTask(ComponentDefaultApplyModelTask.class, this));
180 getElement().initializePendingTasks(this, tasks);
181 tasks.offer(LifecycleTaskFactory.getTask(RunComponentModifiersTask.class, this));
182 tasks.add(LifecycleTaskFactory.getTask(HelperCustomApplyModelTask.class, this));
183 tasks.add(LifecycleTaskFactory.getTask(SetReadOnlyOnDataBindingTask.class, this));
184 }
185
186
187
188
189
190
191 @Override
192 protected ViewLifecyclePhase initializeSuccessor(LifecycleElement nestedElement, String nestedPath,
193 Component parent) {
194 ApplyModelComponentPhase applyModelPhase = LifecyclePhaseFactory.applyModel(nestedElement, getModel(),
195 nestedPath, getRefreshPaths(), parent, null, visitedIds);
196
197 if (nestedElement.isInitialized()) {
198 return applyModelPhase;
199 }
200
201 return LifecyclePhaseFactory.initialize(nestedElement, getModel(), nestedPath, getRefreshPaths(), parent,
202 applyModelPhase);
203 }
204
205 }