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 private ViewContext viewContext = new ViewContext();
40
41 private static HandlerManager eventBus;
42
43 public MajorManager() {
44 eventBus = new HandlerManager(null);
45 programModel = new DataModel();
46 ProgramRegistry.getSpecializationHandlers().clear();
47 }
48
49 public MajorViewController getProgramViewController() {
50 programModel.resetRoot();
51 getMajorViewController();
52 eventBus.fireEvent(new ProgramViewEvent());
53 return majorViewController;
54 }
55
56 public VariationViewController getVariationViewController() {
57 DataModel variationModel = new DataModel();
58
59 DataModelDefinition definition = new DataModelDefinition ();
60 definition.setMetadata (programModel.getDefinition ().getMetadata ("variations/*"));
61 variationModel.setDefinition(definition);
62 variationModel.setRoot(ProgramRegistry.getData());
63
64
65
66
67
68 MajorController theController = null;
69
70
71
72 boolean comingFromProposal = variationModel != null && variationModel.get("isProposal") != null && majorProposalController!=null;
73
74 if (comingFromProposal){
75
76 theController = majorProposalController;
77 }
78 else {
79
80 theController = (MajorController)majorViewController;
81 }
82
83
84
85
86
87 if (theController == null && majorEditController != null){
88 theController = majorEditController;
89 }
90
91
92
93 variationViewController = new VariationViewController(variationModel, viewContext, eventBus, theController);
94
95 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 DataModel variationModel = new DataModel();
126
127 DataModelDefinition definition = new DataModelDefinition ();
128
129 if(programModel==null||programModel.getDefinition()==null){
130 Window.alert("Debug: null programModel or definition (MajorManager.getVariationEditController()");
131 }
132 definition.setMetadata(programModel.getDefinition().getMetadata("variations/*"));
133
134
135
136 variationModel.setDefinition(definition);
137 variationModel.setRoot(ProgramRegistry.getData());
138 ProgramUtils.unregisterUnusedHandlers(eventBus);
139
140
141
142
143
144 MajorController theController = null;
145
146
147
148 boolean comingFromProposal = variationModel != null && variationModel.get("isProposal") != null && majorProposalController!=null;
149
150 if (comingFromProposal){
151
152 theController = majorProposalController;
153 }
154 else {
155
156 theController = (MajorController)majorViewController;
157 }
158
159
160
161
162
163 if (theController == null && majorEditController != null){
164 theController = majorEditController;
165 }
166
167
168
169
170
171 variationEditController = new VariationEditController(variationModel, viewContext, eventBus, theController);
172 return variationEditController;
173 }
174
175 public MajorEditController getProgramEditController() {
176 programModel.resetRoot();
177 return getMajorEditController();
178 }
179
180 public MajorEditController getProgramSpecEditController() {
181 return getMajorEditController();
182 }
183
184 public ProgramVersionsController getProgramVersionsController() {
185 if (programVersionsController == null) {
186 programVersionsController = new ProgramVersionsController(programModel, ProgramSideBar.Type.MAJOR, viewContext, eventBus);
187 }
188 return programVersionsController;
189 }
190
191 public static HandlerManager getEventBus() {
192 return eventBus;
193 }
194
195 public MajorProposalController getMajorProposalController() {
196 if (majorProposalController == null) {
197 majorProposalController = new MajorProposalController(programModel, viewContext, eventBus);
198 }
199 return majorProposalController;
200 }
201
202
203 public MajorEditController getMajorEditController() {
204 eventBus = new HandlerManager(null);
205 majorEditController = new MajorEditController(programModel, viewContext, eventBus);
206
207 return majorEditController;
208 }
209
210 private MajorViewController getMajorViewController() {
211 majorViewController = new MajorViewController(programModel, viewContext, eventBus);
212
213 return majorViewController;
214 }
215
216 public DataModel getProgramModel() {
217 return programModel;
218 }
219 }