View Javadoc

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   * @author Igor
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  //        variationModel.setDefinition(programModel.getDefinition());
59          DataModelDefinition definition = new DataModelDefinition ();
60          definition.setMetadata (programModel.getDefinition ().getMetadata ("variations/*"));
61          variationModel.setDefinition(definition);
62          variationModel.setRoot(ProgramRegistry.getData());
63         
64          // Determine if we are coming from a link to a proposal
65          // If so, we need to instantiate the variation controller using an
66          // instance of the proposal controller, otherwise we should just
67          // use the major discipline controller
68          MajorController theController = null;
69          
70          // Look in model to see if we have passed a flag to say we are working with
71          // a proposal (passed from VariationsBinding.java, search for isProposal)
72          boolean comingFromProposal = variationModel != null && variationModel.get("isProposal") != null && majorProposalController!=null;
73             
74          if (comingFromProposal){
75   	       // We are coming from a link to a proposal, so use the proposal controller
76              theController = majorProposalController;
77          }
78          else {
79          	// This is not a link to a proposal, so use the normal major discipline controller
80          	 theController = (MajorController)majorViewController;
81          } 
82          
83          // Fix for 2417
84          // A case exists where we are coming from majorEditController
85          // TODO: we really need to think about how this works rather than
86          // add these if/then cases, but we are out of time 
87          if (theController == null && majorEditController != null){
88              theController = majorEditController;
89          }
90          
91      	// Instantiate a controller used to work with the specialization, passing it
92      	// either the proposal controller or the major discipline controller
93          variationViewController = new VariationViewController(variationModel, viewContext, eventBus, theController);
94     
95          return variationViewController;
96      }
97  
98  //  private String formatMetadata (Metadata md, String fieldKey)
99  //  {
100 //   String msg = "metadata for fieldKey=" + fieldKey
101 //                //    + "\n Name=" + md.getName ()
102 //                + "\n LabelKey=" + md.getLabelKey ()
103 //                + "\n defaultValuePath=" + md.getDefaultValuePath ()
104 //                + "\n LookupContextPath=" + md.getLookupContextPath ()
105 //                //    + "\n maskForatter="  + md.getMaskFormatter ()
106 //                //    + "\n partialMaskFormatter="  + md.getPartialMaskFormatter ()
107 //                + "\n dataType=" + md.getDataType ()
108 //                + "\n defaultValue=" + md.getDefaultValue ()
109 //                + "\n WriteAccess=" + md.getWriteAccess ()
110 //                + "\n initialLookup=" + md.getInitialLookup ()
111 //                + "\n additionalLookups=" + md.getAdditionalLookups ();
112 //   if (md.getProperties () != null)
113 //   {
114 //    msg += "\n It has " + md.getProperties ().size () + " properties: \n";
115 //    for (String fk : md.getProperties ().keySet ())
116 //    {
117 //     msg += "\n" + formatMetadata (md.getProperties ().get (fk), fk);
118 //    }
119 //   }
120 //   return msg;
121 //  }
122 
123 
124     public VariationEditController getVariationEditController() {
125         DataModel variationModel = new DataModel();
126 //        variationModel.setDefinition(programModel.getDefinition());
127         DataModelDefinition definition = new DataModelDefinition ();
128         //What if the program model is not ready yet??
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 //        KSErrorDialog.show (new NullPointerException
134 //     ("metada for: "
135 //     +  formatMetadata (definition.getMetadata (), "variations/*")));
136         variationModel.setDefinition(definition);
137         variationModel.setRoot(ProgramRegistry.getData());
138         ProgramUtils.unregisterUnusedHandlers(eventBus);
139  
140         // Determine if we are coming from a link to a proposal
141         // If so, we need to instantiate the variation controller using an
142         // instance of the proposal controller, otherwise we should just
143         // use the major discipline controller
144         MajorController theController = null;
145         
146         // Look in model to see if we have passed a flag to say we are working with
147         // a proposal (passed from VariationsBinding.java, search for isProposal)
148         boolean comingFromProposal = variationModel != null && variationModel.get("isProposal") != null && majorProposalController!=null;
149            
150         if (comingFromProposal){
151  	       // We are coming from a link to a proposal, so use the proposal controller
152             theController = majorProposalController;
153         }
154         else {
155         	// This is not a link to a proposal, so use the normal major discipline controller
156         	 theController = (MajorController)majorViewController;
157         } 
158     	
159         // Fix for 2417
160         // A case exists where we are coming from majorEditController
161         // TODO: we really need to think about how this works rather than
162         // add these if/then cases, but we are out of time 
163         if (theController == null && majorEditController != null){
164             theController = majorEditController;
165         }
166        
167         
168         
169     	// Instantiate a controller used to work with the specialization, passing it
170     	// either the proposal controller or the major discipline controller
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 }