Coverage Report - org.kuali.student.lum.program.client.major.edit.MajorEditController
 
Classes in this File Line Coverage Branch Coverage Complexity
MajorEditController
0%
0/91
0%
0/20
1.868
MajorEditController$1
0%
0/3
N/A
1.868
MajorEditController$10
0%
0/6
N/A
1.868
MajorEditController$10$1
0%
0/7
0%
0/2
1.868
MajorEditController$11
0%
0/49
0%
0/12
1.868
MajorEditController$12
0%
0/6
0%
0/2
1.868
MajorEditController$13
0%
0/5
0%
0/4
1.868
MajorEditController$13$1
0%
0/6
N/A
1.868
MajorEditController$2
0%
0/3
N/A
1.868
MajorEditController$3
0%
0/6
0%
0/2
1.868
MajorEditController$4
0%
0/3
N/A
1.868
MajorEditController$4$1
0%
0/3
N/A
1.868
MajorEditController$4$1$1
0%
0/13
0%
0/6
1.868
MajorEditController$4$1$1$1
0%
0/5
0%
0/2
1.868
MajorEditController$4$1$1$1$1
0%
0/5
0%
0/2
1.868
MajorEditController$5
0%
0/27
0%
0/10
1.868
MajorEditController$6
0%
0/9
N/A
1.868
MajorEditController$7
0%
0/12
0%
0/4
1.868
MajorEditController$8
0%
0/3
N/A
1.868
MajorEditController$9
0%
0/13
N/A
1.868
 
 1  
 package org.kuali.student.lum.program.client.major.edit;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Iterator;
 5  
 import java.util.List;
 6  
 import java.util.Set;
 7  
 import java.util.TreeSet;
 8  
 
 9  
 import org.kuali.student.common.assembly.data.Data;
 10  
 import org.kuali.student.common.assembly.data.QueryPath;
 11  
 import org.kuali.student.common.assembly.data.Data.Property;
 12  
 import org.kuali.student.common.ui.client.application.Application;
 13  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 14  
 import org.kuali.student.common.ui.client.application.ViewContext;
 15  
 import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView;
 16  
 import org.kuali.student.common.ui.client.mvc.Callback;
 17  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 18  
 import org.kuali.student.common.ui.client.mvc.HasCrossConstraints;
 19  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 20  
 import org.kuali.student.common.ui.client.mvc.View;
 21  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 22  
 import org.kuali.student.common.ui.client.service.DataSaveResult;
 23  
 import org.kuali.student.common.ui.client.validator.ValidatorClientUtils;
 24  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 25  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract;
 26  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
 27  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 28  
 import org.kuali.student.common.ui.shared.IdAttributes;
 29  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 30  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 31  
 import org.kuali.student.lum.common.client.configuration.LUMViews;
 32  
 import org.kuali.student.lum.common.client.helpers.RecentlyViewedHelper;
 33  
 import org.kuali.student.lum.common.client.widgets.AppLocations;
 34  
 import org.kuali.student.lum.program.client.ProgramConstants;
 35  
 import org.kuali.student.lum.program.client.ProgramRegistry;
 36  
 import org.kuali.student.lum.program.client.ProgramSections;
 37  
 import org.kuali.student.lum.program.client.ProgramStatus;
 38  
 import org.kuali.student.lum.program.client.ProgramUtils;
 39  
 import org.kuali.student.lum.program.client.events.AddSpecializationEvent;
 40  
 import org.kuali.student.lum.program.client.events.AfterSaveEvent;
 41  
 import org.kuali.student.lum.program.client.events.ChangeViewEvent;
 42  
 import org.kuali.student.lum.program.client.events.MetadataLoadedEvent;
 43  
 import org.kuali.student.lum.program.client.events.ModelLoadedEvent;
 44  
 import org.kuali.student.lum.program.client.events.SpecializationCreatedEvent;
 45  
 import org.kuali.student.lum.program.client.events.SpecializationSaveEvent;
 46  
 import org.kuali.student.lum.program.client.events.SpecializationUpdateEvent;
 47  
 import org.kuali.student.lum.program.client.events.StateChangeEvent;
 48  
 import org.kuali.student.lum.program.client.events.StoreRequirementIDsEvent;
 49  
 import org.kuali.student.lum.program.client.events.UpdateEvent;
 50  
 import org.kuali.student.lum.program.client.major.MajorController;
 51  
 import org.kuali.student.lum.program.client.properties.ProgramProperties;
 52  
 import org.kuali.student.lum.program.client.rpc.AbstractCallback;
 53  
 import org.kuali.student.lum.program.client.widgets.ProgramSideBar;
 54  
 
 55  
 import com.google.gwt.core.client.GWT;
 56  
 import com.google.gwt.event.dom.client.ClickEvent;
 57  
 import com.google.gwt.event.dom.client.ClickHandler;
 58  
 import com.google.gwt.event.shared.HandlerManager;
 59  
 import com.google.gwt.user.client.Window;
 60  
 
 61  
 /**
 62  
  * @author Igor
 63  
  */
 64  0
 public class MajorEditController extends MajorController {
 65  
 
 66  0
     private final KSButton saveButton = new KSButton(ProgramProperties.get().common_save());
 67  0
     private final KSButton cancelButton = new KSButton(ProgramProperties.get().common_cancel(), KSButtonAbstract.ButtonStyle.ANCHOR_LARGE_CENTERED);
 68  0
     private final Set<String> existingVariationIds = new TreeSet<String>();
 69  
 
 70  
     private ProgramStatus previousState;
 71  
 
 72  
     /**
 73  
      * Constructor.
 74  
      *
 75  
      * @param programModel
 76  
      */
 77  
     public MajorEditController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus) {
 78  0
         super(programModel, viewContext, eventBus);
 79  0
         configurer = GWT.create(MajorEditConfigurer.class);
 80  0
         sideBar.setState(ProgramSideBar.State.EDIT);
 81  0
         initHandlers();
 82  0
     }
 83  
 
 84  
     @Override
 85  
     protected void configureView() {
 86  0
         super.configureView();
 87  0
         if (!initialized) {
 88  0
             eventBus.fireEvent(new MetadataLoadedEvent(programModel.getDefinition(), this));
 89  0
             List<Enum<?>> excludedViews = new ArrayList<Enum<?>>();
 90  0
             excludedViews.add(ProgramSections.PROGRAM_REQUIREMENTS_EDIT);
 91  0
             excludedViews.add(ProgramSections.SUPPORTING_DOCUMENTS_EDIT);
 92  0
             excludedViews.add(ProgramSections.SUMMARY);
 93  0
             addCommonButton(ProgramProperties.get().program_menu_sections(), saveButton, excludedViews);
 94  0
             addCommonButton(ProgramProperties.get().program_menu_sections(), cancelButton, excludedViews);
 95  0
             initialized = true;
 96  
         }
 97  0
     }
 98  
 
 99  
     private void initHandlers() {
 100  0
         saveButton.addClickHandler(new ClickHandler() {
 101  
 
 102  
             @Override
 103  
             public void onClick(ClickEvent event) {
 104  0
                 doSave();
 105  0
             }
 106  
         });
 107  0
         cancelButton.addClickHandler(new ClickHandler() {
 108  
 
 109  
             @Override
 110  
             public void onClick(ClickEvent event) {
 111  0
                 doCancel();
 112  0
             }
 113  
         });
 114  0
         eventBus.addHandler(UpdateEvent.TYPE, new UpdateEvent.Handler() {
 115  
             @Override
 116  
             public void onEvent(UpdateEvent event) {
 117  0
                 Enum<?> view = event.getCurrentView();
 118  0
                 if (view != null) {
 119  0
                     setCurrentViewEnum(view);
 120  
                 }
 121  0
                 doSave(event.getOkCallback());
 122  
 
 123  0
             }
 124  
         });
 125  0
         eventBus.addHandler(StateChangeEvent.TYPE, new StateChangeEvent.Handler() {
 126  
             @Override
 127  
             public void onEvent(final StateChangeEvent event) {
 128  
                     //FIXME: The proper way of doing this would be a single server side call to validate next state
 129  
                     //which would retrieve warnings & required for next state, instead of re-validating warnings for
 130  
                     //current state server side and validating required for next state client side.
 131  0
                     programRemoteService.validate(programModel.getRoot(), new KSAsyncCallback<List<ValidationResultInfo>>(){
 132  
                                         @Override
 133  
                                         public void onSuccess(final List<ValidationResultInfo> currentStateResults) {
 134  0
                                 programModel.validateNextState(new Callback<List<ValidationResultInfo>>() {
 135  
                                     @Override
 136  
                                     public void exec(List<ValidationResultInfo> nextStateResults) {
 137  
                                             //Update validation warnings and process for all screens
 138  0
                                             Application.getApplicationContext().clearValidationWarnings();
 139  0
                                             Application.getApplicationContext().addValidationWarnings(currentStateResults);
 140  0
                                             isValid(Application.getApplicationContext().getValidationWarnings(), false);
 141  
                                         
 142  0
                                             boolean isSectionValid = isValid(nextStateResults, true) 
 143  
                                                 && Application.getApplicationContext().getValidationWarnings().isEmpty();
 144  0
                                         if (isSectionValid) {
 145  0
                                             Callback<Boolean> callback = new Callback<Boolean>() {
 146  
                                                 @Override
 147  
                                                 public void exec(Boolean result) {
 148  0
                                                     if (result) {
 149  0
                                                         reloadMetadata = true;
 150  0
                                                         loadMetadata(new Callback<Boolean>() {
 151  
                                                             @Override
 152  
                                                             public void exec(Boolean result) {
 153  0
                                                                 if (result) {
 154  0
                                                                     ProgramUtils.syncMetadata(configurer, programModel.getDefinition());
 155  0
                                                                     HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), context);
 156  
                                                                 }
 157  0
                                                             }
 158  
                                                         });
 159  
                                                     }
 160  0
                                                 }
 161  
                                             };
 162  0
                                             previousState = ProgramStatus.of(programModel);
 163  0
                                             ProgramUtils.setStatus(programModel, event.getProgramStatus().getValue());
 164  0
                                             saveData(callback);
 165  0
                                         } else {
 166  0
                                             KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000));
 167  
                                         }
 168  0
                                     }
 169  
                                 });
 170  
 
 171  
                                                 
 172  0
                                         }
 173  
                             
 174  
                     });                
 175  0
             }
 176  
         });
 177  
 
 178  0
         eventBus.addHandler(SpecializationSaveEvent.TYPE, new SpecializationSaveEvent.Handler() {
 179  
             @Override
 180  
             public void onEvent(SpecializationSaveEvent event) {
 181  
 
 182  0
                 Data currentVariations = getDataProperty(ProgramConstants.VARIATIONS);
 183  
 
 184  0
                 existingVariationIds.clear();
 185  
 
 186  0
                 for (Data.Property prop : currentVariations) {
 187  0
                     String existingId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);
 188  0
                     existingVariationIds.add(existingId);
 189  0
                 }
 190  0
                 String updatedId = event.getData().get(ProgramConstants.ID);
 191  0
                 Integer updatedKey = null;
 192  
 
 193  
                 //FIXME: This is ugly but gets us past a  blocker issue. 
 194  
                 // Theres something wrong with the way the models are
 195  
                 // handled in the major and variation controllers  so they get out of sync.
 196  
                 // This is a temporary workaround
 197  0
                 if (updatedId != null) { // this is an update of an existing variation
 198  0
                     for (Data.Property prop : currentVariations) {
 199  0
                         String id = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);
 200  0
                         if (updatedId.equals(id)) {
 201  0
                             updatedKey = prop.getKey();
 202  0
                             Data currentMetaInfo = ((Data) prop.getValue()).get("metaInfo");
 203  0
                             String latestVersionInd = currentMetaInfo.get("versionInd");
 204  0
                             Data newMetaInfo = event.getData().get("metaInfo");
 205  0
                             if (newMetaInfo == null) {
 206  0
                                 newMetaInfo = new Data();
 207  0
                                 event.getData().set("metaInfo", newMetaInfo);
 208  
                             }
 209  0
                             newMetaInfo.set("versionInd", latestVersionInd);
 210  0
                             break;
 211  
                         }
 212  0
                     }
 213  
 
 214  0
                     currentVariations.set(updatedKey, event.getData());
 215  
                 } else {
 216  0
                     currentVariations.add(event.getData());
 217  
 
 218  
                 }
 219  0
                 doSave();
 220  0
             }
 221  
         });
 222  0
         eventBus.addHandler(AddSpecializationEvent.TYPE, new AddSpecializationEvent.Handler() {
 223  
             @Override
 224  
             public void onEvent(AddSpecializationEvent event) {
 225  0
                 String id = getStringProperty(ProgramConstants.ID);
 226  0
                 ProgramRegistry.setRow((getDataProperty(ProgramConstants.VARIATIONS)).size());
 227  0
                 ProgramRegistry.setData(ProgramUtils.createNewSpecializationBasedOnMajor(programModel));
 228  0
                 ViewContext viewContext = new ViewContext();
 229  0
                 viewContext.setId(id);
 230  0
                 viewContext.setIdType(IdAttributes.IdType.OBJECT_ID);
 231  0
                 HistoryManager.navigate(AppLocations.Locations.EDIT_VARIATION.getLocation(), viewContext);
 232  
 
 233  0
             }
 234  
         });
 235  
 
 236  0
         eventBus.addHandler(StoreRequirementIDsEvent.TYPE, new StoreRequirementIDsEvent.Handler() {
 237  
             @Override
 238  
             public void onEvent(StoreRequirementIDsEvent event) {
 239  0
                 List<String> ids = event.getProgramRequirementIds();
 240  
 
 241  0
                 programModel.set(QueryPath.parse(ProgramConstants.PROGRAM_REQUIREMENTS), new Data());
 242  0
                 Data programRequirements = programModel.get(ProgramConstants.PROGRAM_REQUIREMENTS);
 243  
 
 244  0
                 if (programRequirements == null) {
 245  0
                     Window.alert("Cannot find program requirements in data model.");
 246  0
                     GWT.log("Cannot find program requirements in data model", null);
 247  0
                     return;
 248  
                 }
 249  
 
 250  0
                 for (String id : ids) {
 251  0
                     programRequirements.add(id);
 252  
                 }
 253  0
                 doSave();
 254  0
             }
 255  
         });
 256  0
         eventBus.addHandler(ChangeViewEvent.TYPE, new ChangeViewEvent.Handler() {
 257  
             @Override
 258  
             public void onEvent(ChangeViewEvent event) {
 259  0
                 showView(event.getViewToken());
 260  0
             }
 261  
         });
 262  0
     }
 263  
 
 264  
     @Override
 265  
     protected void loadModel(ModelRequestCallback<DataModel> callback) {
 266  0
         ViewContext viewContext = getViewContext();
 267  0
         if (viewContext.getIdType() == IdType.COPY_OF_OBJECT_ID) {
 268  0
             createNewVersionAndLoadModel(callback, viewContext);
 269  
         } else {
 270  0
             super.loadModel(callback);
 271  
         }
 272  0
     }
 273  
 
 274  
     protected void createNewVersionAndLoadModel(final ModelRequestCallback<DataModel> callback, final ViewContext viewContext) {
 275  0
         Data data = new Data();
 276  0
         Data versionData = new Data();
 277  0
         versionData.set(new Data.StringKey("versionIndId"), getViewContext().getId());
 278  0
         versionData.set(new Data.StringKey("versionComment"), "Major Disicpline Version");
 279  0
         data.set(new Data.StringKey("versionInfo"), versionData);
 280  
 
 281  0
         programRemoteService.saveData(data, new AbstractCallback<DataSaveResult>(ProgramProperties.get().common_retrievingData()) {
 282  
             @Override
 283  
             public void onSuccess(DataSaveResult result) {
 284  0
                 super.onSuccess(result);
 285  0
                 programModel.setRoot(result.getValue());
 286  0
                 viewContext.setId(ProgramUtils.getProgramId(programModel));
 287  0
                 viewContext.setIdType(IdType.OBJECT_ID);
 288  0
                 setHeaderTitle();
 289  0
                 setStatus();
 290  0
                 callback.onModelReady(programModel);
 291  0
                 eventBus.fireEvent(new ModelLoadedEvent(programModel));
 292  0
             }
 293  
 
 294  
             @Override
 295  
             public void onFailure(Throwable caught) {
 296  0
                 super.onFailure(caught);
 297  0
                 callback.onRequestFail(caught);
 298  0
             }
 299  
         });
 300  
 
 301  0
     }
 302  
 
 303  
     private void doSave(final Callback<Boolean> okCallback) {
 304  0
         requestModel(new ModelRequestCallback<DataModel>() {
 305  
             @Override
 306  
             public void onModelReady(DataModel model) {
 307  0
                 MajorEditController.this.updateModelFromCurrentView();
 308  0
                 model.validate(new Callback<List<ValidationResultInfo>>() {
 309  
                     @Override
 310  
                     public void exec(List<ValidationResultInfo> result) {
 311  0
                         boolean isSectionValid = isValid(result, true);
 312  0
                         if (isSectionValid) {
 313  0
                             saveData(okCallback);
 314  
                         } else {
 315  0
                             okCallback.exec(false);
 316  0
                             KSNotifier.add(new KSNotification("Unable to save, please check fields for errors.", false, true, 5000));
 317  
                         }
 318  0
                     }
 319  
                 });
 320  
 
 321  0
             }
 322  
 
 323  
             @Override
 324  
             public void onRequestFail(Throwable cause) {
 325  0
                 GWT.log("Unable to retrieve model for validation and save", cause);
 326  0
             }
 327  
         });
 328  0
     }
 329  
 
 330  
     private void doCancel() {
 331  0
         showView(ProgramSections.SUMMARY);
 332  0
     }
 333  
 
 334  
     @Override
 335  
     protected void doSave() {
 336  0
         doSave(NO_OP_CALLBACK);
 337  0
     }
 338  
 
 339  
     private void saveData(final Callback<Boolean> okCallback) {
 340  0
         programRemoteService.saveData(programModel.getRoot(), new AbstractCallback<DataSaveResult>(ProgramProperties.get().common_savingData()) {
 341  
             @Override
 342  
             public void onSuccess(DataSaveResult result) {
 343  0
                 super.onSuccess(result);
 344  
 
 345  
                 //Clear warning states on field and any warnings stored in ApplicationContext;
 346  0
                 clearAllWarnings();
 347  0
                 Application.getApplicationContext().clearValidationWarnings();
 348  
                 
 349  0
                 List<ValidationResultInfo> validationResults = result.getValidationResults();
 350  0
                 Application.getApplicationContext().addValidationWarnings(validationResults);
 351  0
                 if (ValidatorClientUtils.hasErrors(validationResults)) {
 352  0
                     if (previousState != null) {
 353  0
                         ProgramUtils.setStatus(programModel, previousState.getValue());
 354  
                     }
 355  0
                     ProgramUtils.retrofitValidationResults(validationResults);
 356  0
                     isValid(validationResults, false, true);
 357  0
                     ProgramUtils.handleValidationErrorsForSpecializations(validationResults, programModel);
 358  
                     
 359  
                     //Clean up anything created by earlier code
 360  0
                     Data currentVariations = getDataProperty(ProgramConstants.VARIATIONS);
 361  
 
 362  0
                     existingVariationIds.clear();
 363  
 
 364  0
                     for (Iterator<Property> iter = currentVariations.iterator();iter.hasNext();) {
 365  0
                             Property prop = iter.next();
 366  0
                         String existingId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);
 367  0
                         if(existingId==null){
 368  0
                                 iter.remove();
 369  
                         }else{
 370  0
                                 existingVariationIds.add(existingId);
 371  
                         }
 372  0
                     }
 373  
                     
 374  0
                     okCallback.exec(false);
 375  0
                 } else {
 376  0
                     Data data = result.getValue();
 377  0
                     if (data != null) {
 378  0
                         programModel.setRoot(result.getValue());
 379  
                     }
 380  0
                     previousState = null;
 381  0
                     setHeaderTitle();
 382  0
                     setStatus();
 383  0
                     resetFieldInteractionFlag();
 384  0
                     configurer.applyPermissions();
 385  0
                     handleSpecializations();
 386  0
                     throwAfterSaveEvent();
 387  0
                     HistoryManager.logHistoryChange();
 388  0
                     ViewContext viewContext = getViewContext();
 389  0
                     viewContext.setId(getStringProperty(ProgramConstants.ID));
 390  0
                     viewContext.setIdType(IdType.OBJECT_ID);
 391  
 
 392  0
                                     if (ValidatorClientUtils.hasWarnings(validationResults)){
 393  
                                             //Show validation warnings for major
 394  0
                                             isValid(result.getValidationResults(), false, true);                                            
 395  0
                                             KSNotifier.show("Saved with Warnings");
 396  
                                     } else {
 397  0
                         KSNotifier.show(ProgramProperties.get().common_successfulSave());
 398  
                                     }                                  
 399  
                     
 400  
                     // add to recently viewed now that we're sure to know the program's id
 401  0
                     ViewContext docContext = new ViewContext();
 402  0
                     docContext.setId(getStringProperty(ProgramConstants.ID));
 403  0
                     docContext.setIdType(IdType.OBJECT_ID);
 404  0
                     docContext.setAttribute(ProgramConstants.TYPE, ProgramConstants.MAJOR_LU_TYPE_ID + '/' + ProgramSections.PROGRAM_DETAILS_VIEW);
 405  0
                     RecentlyViewedHelper.addDocument(getProgramName(),
 406  
                             HistoryManager.appendContext(AppLocations.Locations.VIEW_PROGRAM.getLocation(), docContext));
 407  
                    
 408  0
                     okCallback.exec(true);
 409  0
                     processCurrentView();
 410  
                 }
 411  0
             }
 412  
         });
 413  0
     }
 414  
 
 415  
     private void processCurrentView() {
 416  0
         Enum<?> currentView = getCurrentViewEnum();
 417  0
         if (currentView.name().equals(ProgramSections.VIEW_ALL.name())) {
 418  0
             HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), getViewContext());
 419  
         } else {
 420  0
             showView(currentView);
 421  
         }
 422  0
     }
 423  
 
 424  
     /**
 425  
      * Handles after save work for specializations.
 426  
      */
 427  
     private void handleSpecializations() {
 428  0
         String newVariationId = null;
 429  0
         Data variations = programModel.get(ProgramConstants.VARIATIONS);
 430  0
         for (Data.Property prop : variations) {
 431  0
             String varId = (String) ((Data) prop.getValue()).get(ProgramConstants.ID);
 432  0
             if (!existingVariationIds.contains(varId)) {
 433  0
                 newVariationId = varId;
 434  0
                 existingVariationIds.add(newVariationId);
 435  0
                 break;
 436  
             }
 437  0
         }
 438  0
         if (newVariationId != null) {
 439  0
             eventBus.fireEvent(new SpecializationCreatedEvent(newVariationId));
 440  
         } else {
 441  0
             eventBus.fireEvent(new SpecializationUpdateEvent(variations));
 442  
         }
 443  0
     }
 444  
 
 445  
     private void throwAfterSaveEvent() {
 446  0
         eventBus.fireEvent(new AfterSaveEvent(programModel, this));
 447  0
     }
 448  
 
 449  
     @Override
 450  
     public void onModelLoadedEvent() {
 451  0
         Enum<?> changeSection = ProgramRegistry.getSection();
 452  0
         if (changeSection != null) {
 453  0
             showView(changeSection);
 454  0
             ProgramRegistry.setSection(null);
 455  
         } else {
 456  0
             String id = getStringProperty(ProgramConstants.ID);
 457  0
             if (id == null) {
 458  0
                 showView(ProgramSections.PROGRAM_DETAILS_EDIT);
 459  
             } else {
 460  0
                 showView(ProgramSections.SUMMARY);
 461  
             }
 462  
         }
 463  
 
 464  0
     }
 465  
 
 466  
         @Override
 467  
         public void beforeShow(final Callback<Boolean> onReadyCallback) {
 468  0
                 if(!initialized){
 469  0
                         Application.getApplicationContext().clearCrossConstraintMap(null);
 470  0
                         Application.getApplicationContext().clearPathToFieldMapping(null);
 471  
                 }
 472  
 
 473  0
                 super.beforeShow(onReadyCallback);
 474  0
         }
 475  
 
 476  
         //Before show is called before the model is bound to the widgets. We need to update cross constraints after widget binding
 477  
         //This gets called twice which is not optimal
 478  
         @Override
 479  
         public <V extends Enum<?>> void showView(V viewType,
 480  
                         final Callback<Boolean> onReadyCallback) {
 481  0
                 Callback<Boolean> updateCrossConstraintsCallback = new Callback<Boolean>(){
 482  
                         public void exec(Boolean result) {
 483  0
                                 onReadyCallback.exec(result);
 484  0
                         for(HasCrossConstraints crossConstraint:Application.getApplicationContext().getCrossConstraints(null)){
 485  0
                                 crossConstraint.reprocessWithUpdatedConstraints();
 486  
                         }
 487  0
                         showWarnings();        
 488  0
                         }
 489  
         };
 490  0
                 super.showView(viewType, updateCrossConstraintsCallback);
 491  0
         }
 492  
 
 493  
         //Ensure that the managing bodies section view is updated before the user edits specializations
 494  
         @Override
 495  
         public void beforeViewChange(Enum<?> viewChangingTo, final Callback<Boolean> okToChangeCallback){
 496  0
                 if(LUMViews.VARIATION_EDIT.equals(viewChangingTo)){
 497  0
                         getView(ProgramSections.MANAGE_BODIES_EDIT, new Callback<View>(){
 498  
                                 @Override
 499  
                                 public void exec(final View view) {
 500  0
                                         if(view!=null && view instanceof SectionView){
 501  0
                                                 requestModel(new ModelRequestCallback<DataModel>(){
 502  
                                                         public void onModelReady(DataModel model) {
 503  0
                                                                 ((SectionView)view).updateWidgetData(model);
 504  0
                                                                 okToChangeCallback.exec(true);
 505  0
                                                         }
 506  
                                                         public void onRequestFail(Throwable cause) {
 507  0
                                                                 okToChangeCallback.exec(false);
 508  0
                                                         }
 509  
                                                 });
 510  
                                         }else{
 511  0
                                                 okToChangeCallback.exec(true);
 512  
                                         }
 513  0
                                 }});
 514  
                 }else{
 515  0
                         okToChangeCallback.exec(true);
 516  
                 }
 517  0
                 this.showExport(isExportButtonActive());        // KSLAB-1916
 518  0
         }
 519  
 }