Coverage Report - org.kuali.student.lum.program.client.major.MajorManager
 
Classes in this File Line Coverage Branch Coverage Complexity
MajorManager
0%
0/57
0%
0/32
2.167
 
 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  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  
 //        variationModel.setDefinition(programModel.getDefinition());
 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  
         // 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  0
         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  0
         boolean comingFromProposal = variationModel != null && variationModel.get("isProposal") != null && majorProposalController!=null;
 73  
            
 74  0
         if (comingFromProposal){
 75  
                 // We are coming from a link to a proposal, so use the proposal controller
 76  0
             theController = majorProposalController;
 77  
         }
 78  
         else {
 79  
                 // This is not a link to a proposal, so use the normal major discipline controller
 80  0
                  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  0
         if (theController == null && majorEditController != null){
 88  0
             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  0
         variationViewController = new VariationViewController(variationModel, viewContext, eventBus, theController);
 94  
    
 95  0
         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  0
         DataModel variationModel = new DataModel();
 126  
 //        variationModel.setDefinition(programModel.getDefinition());
 127  0
         DataModelDefinition definition = new DataModelDefinition ();
 128  
         //What if the program model is not ready yet??
 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  
 //        KSErrorDialog.show (new NullPointerException
 134  
 //     ("metada for: "
 135  
 //     +  formatMetadata (definition.getMetadata (), "variations/*")));
 136  0
         variationModel.setDefinition(definition);
 137  0
         variationModel.setRoot(ProgramRegistry.getData());
 138  0
         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  0
         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  0
         boolean comingFromProposal = variationModel != null && variationModel.get("isProposal") != null && majorProposalController!=null;
 149  
            
 150  0
         if (comingFromProposal){
 151  
                 // We are coming from a link to a proposal, so use the proposal controller
 152  0
             theController = majorProposalController;
 153  
         }
 154  
         else {
 155  
                 // This is not a link to a proposal, so use the normal major discipline controller
 156  0
                  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  0
         if (theController == null && majorEditController != null){
 164  0
             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  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  
 }