1 | |
package org.kuali.student.lum.program.client.major; |
2 | |
|
3 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
4 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
5 | |
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
6 | |
import org.kuali.student.lum.program.client.ProgramRegistry; |
7 | |
import org.kuali.student.lum.program.client.ProgramUtils; |
8 | |
import org.kuali.student.lum.program.client.events.ProgramViewEvent; |
9 | |
import org.kuali.student.lum.program.client.major.edit.MajorEditController; |
10 | |
import org.kuali.student.lum.program.client.major.proposal.MajorProposalController; |
11 | |
import org.kuali.student.lum.program.client.major.view.MajorViewController; |
12 | |
import org.kuali.student.lum.program.client.variation.edit.VariationEditController; |
13 | |
import org.kuali.student.lum.program.client.variation.view.VariationViewController; |
14 | |
import org.kuali.student.lum.program.client.versions.ProgramVersionsController; |
15 | |
import org.kuali.student.lum.program.client.widgets.ProgramSideBar; |
16 | |
|
17 | |
import com.google.gwt.event.shared.HandlerManager; |
18 | |
import com.google.gwt.user.client.Window; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
public class MajorManager { |
24 | |
|
25 | |
private MajorProposalController majorProposalController; |
26 | |
|
27 | |
private MajorViewController majorViewController; |
28 | |
|
29 | |
private MajorEditController majorEditController; |
30 | |
|
31 | |
private VariationViewController variationViewController; |
32 | |
|
33 | |
private VariationEditController variationEditController; |
34 | |
|
35 | |
private ProgramVersionsController programVersionsController; |
36 | |
|
37 | |
protected DataModel programModel; |
38 | |
|
39 | 0 | private ViewContext viewContext = new ViewContext(); |
40 | |
|
41 | |
private static HandlerManager eventBus; |
42 | |
|
43 | 0 | public MajorManager() { |
44 | 0 | eventBus = new HandlerManager(null); |
45 | 0 | programModel = new DataModel(); |
46 | 0 | ProgramRegistry.getSpecializationHandlers().clear(); |
47 | 0 | } |
48 | |
|
49 | |
public MajorViewController getProgramViewController() { |
50 | 0 | programModel.resetRoot(); |
51 | 0 | getMajorViewController(); |
52 | 0 | eventBus.fireEvent(new ProgramViewEvent()); |
53 | 0 | return majorViewController; |
54 | |
} |
55 | |
|
56 | |
public VariationViewController getVariationViewController() { |
57 | 0 | DataModel variationModel = new DataModel(); |
58 | |
|
59 | 0 | DataModelDefinition definition = new DataModelDefinition (); |
60 | 0 | definition.setMetadata (programModel.getDefinition ().getMetadata ("variations/*")); |
61 | 0 | variationModel.setDefinition(definition); |
62 | 0 | variationModel.setRoot(ProgramRegistry.getData()); |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | 0 | MajorController theController = null; |
69 | |
|
70 | |
|
71 | |
|
72 | 0 | boolean comingFromProposal = variationModel != null && variationModel.get("isProposal") != null && majorProposalController!=null; |
73 | |
|
74 | 0 | if (comingFromProposal){ |
75 | |
|
76 | 0 | theController = majorProposalController; |
77 | |
} |
78 | |
else { |
79 | |
|
80 | 0 | theController = (MajorController)majorViewController; |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | 0 | if (theController == null && majorEditController != null){ |
88 | 0 | theController = majorEditController; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | 0 | variationViewController = new VariationViewController(variationModel, viewContext, eventBus, theController); |
94 | |
|
95 | 0 | return variationViewController; |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public VariationEditController getVariationEditController() { |
125 | 0 | DataModel variationModel = new DataModel(); |
126 | |
|
127 | 0 | DataModelDefinition definition = new DataModelDefinition (); |
128 | |
|
129 | 0 | if(programModel==null||programModel.getDefinition()==null){ |
130 | 0 | Window.alert("Debug: null programModel or definition (MajorManager.getVariationEditController()"); |
131 | |
} |
132 | 0 | definition.setMetadata(programModel.getDefinition().getMetadata("variations/*")); |
133 | |
|
134 | |
|
135 | |
|
136 | 0 | variationModel.setDefinition(definition); |
137 | 0 | variationModel.setRoot(ProgramRegistry.getData()); |
138 | 0 | ProgramUtils.unregisterUnusedHandlers(eventBus); |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | 0 | MajorController theController = null; |
145 | |
|
146 | |
|
147 | |
|
148 | 0 | boolean comingFromProposal = variationModel != null && variationModel.get("isProposal") != null && majorProposalController!=null; |
149 | |
|
150 | 0 | if (comingFromProposal){ |
151 | |
|
152 | 0 | theController = majorProposalController; |
153 | |
} |
154 | |
else { |
155 | |
|
156 | 0 | theController = (MajorController)majorViewController; |
157 | |
} |
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | 0 | if (theController == null && majorEditController != null){ |
164 | 0 | theController = majorEditController; |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | 0 | variationEditController = new VariationEditController(variationModel, viewContext, eventBus, theController); |
172 | 0 | return variationEditController; |
173 | |
} |
174 | |
|
175 | |
public MajorEditController getProgramEditController() { |
176 | 0 | programModel.resetRoot(); |
177 | 0 | return getMajorEditController(); |
178 | |
} |
179 | |
|
180 | |
public MajorEditController getProgramSpecEditController() { |
181 | 0 | return getMajorEditController(); |
182 | |
} |
183 | |
|
184 | |
public ProgramVersionsController getProgramVersionsController() { |
185 | 0 | if (programVersionsController == null) { |
186 | 0 | programVersionsController = new ProgramVersionsController(programModel, ProgramSideBar.Type.MAJOR, viewContext, eventBus); |
187 | |
} |
188 | 0 | return programVersionsController; |
189 | |
} |
190 | |
|
191 | |
public static HandlerManager getEventBus() { |
192 | 0 | return eventBus; |
193 | |
} |
194 | |
|
195 | |
public MajorProposalController getMajorProposalController() { |
196 | 0 | if (majorProposalController == null) { |
197 | 0 | majorProposalController = new MajorProposalController(programModel, viewContext, eventBus); |
198 | |
} |
199 | 0 | return majorProposalController; |
200 | |
} |
201 | |
|
202 | |
|
203 | |
public MajorEditController getMajorEditController() { |
204 | 0 | eventBus = new HandlerManager(null); |
205 | 0 | majorEditController = new MajorEditController(programModel, viewContext, eventBus); |
206 | |
|
207 | 0 | return majorEditController; |
208 | |
} |
209 | |
|
210 | |
private MajorViewController getMajorViewController() { |
211 | 0 | majorViewController = new MajorViewController(programModel, viewContext, eventBus); |
212 | |
|
213 | 0 | return majorViewController; |
214 | |
} |
215 | |
|
216 | |
public DataModel getProgramModel() { |
217 | 0 | return programModel; |
218 | |
} |
219 | |
} |