Coverage Report - org.kuali.student.lum.program.client.variation.VariationsBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
VariationsBinding
0%
0/59
0%
0/18
2.3
VariationsBinding$1
0%
0/14
0%
0/4
2.3
VariationsBinding$2
0%
0/5
0%
0/2
2.3
 
 1  
 package org.kuali.student.lum.program.client.variation;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import org.kuali.student.common.assembly.data.Data;
 6  
 import org.kuali.student.common.ui.client.application.Application;
 7  
 import org.kuali.student.common.ui.client.application.ViewContext;
 8  
 import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport;
 9  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 10  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 11  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 12  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 13  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel;
 14  
 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
 15  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 16  
 import org.kuali.student.lum.common.client.configuration.Configuration;
 17  
 import org.kuali.student.lum.program.client.ProgramConstants;
 18  
 import org.kuali.student.lum.program.client.ProgramMsgConstants;
 19  
 import org.kuali.student.lum.program.client.ProgramRegistry;
 20  
 import org.kuali.student.lum.program.client.ProgramUtils;
 21  
 import org.kuali.student.lum.program.client.events.UpdateEvent;
 22  
 import org.kuali.student.lum.program.client.major.MajorManager;
 23  
 
 24  
 import com.google.gwt.core.client.GWT;
 25  
 import com.google.gwt.event.dom.client.ClickEvent;
 26  
 import com.google.gwt.event.dom.client.ClickHandler;
 27  
 import com.google.gwt.user.client.Window;
 28  
 import com.google.gwt.user.client.ui.Anchor;
 29  
 import com.google.gwt.user.client.ui.FlexTable;
 30  
 
 31  
 /**
 32  
  * @author Igor
 33  
  */
 34  0
 public class VariationsBinding extends ModelWidgetBindingSupport<FlexTable> {
 35  
 
 36  
     private String url;
 37  
 
 38  
     private boolean editable;
 39  
 
 40  
     private Configuration configuration;
 41  
     
 42  
     /**
 43  
      * Passed into constructor to tell us this is the right hand column
 44  
      * in the specializations section of the summary tab.  We will
 45  
      * disable links in the right hand column using the variable.
 46  
      */
 47  0
     private boolean isRightHandColumn = false;
 48  
 
 49  
     /**
 50  
      * 
 51  
      * This is a special constructor that allows us to differentiate between
 52  
      * the left and right side-by-side comparison columns.  We need to
 53  
      * disable links in the right hand column.
 54  
      * 
 55  
      * @param url
 56  
      * @param editable
 57  
      * @param isRightHandColumn
 58  
      */
 59  0
     public VariationsBinding(String url, boolean editable, boolean isRightHandColumn) {
 60  0
         this.url = url;
 61  0
         this.editable = editable;
 62  0
         this.isRightHandColumn = isRightHandColumn;
 63  0
     }
 64  
     
 65  0
     public VariationsBinding(String url, boolean editable) {
 66  0
         this.url = url;
 67  0
         this.editable = editable;
 68  0
         this.isRightHandColumn = false; // in case this class is reused.
 69  0
     }
 70  
 
 71  
     public VariationsBinding(String url, boolean editable, Configuration configuration) {
 72  0
         this(url, editable);
 73  0
         this.configuration = configuration;
 74  0
         this.isRightHandColumn = false;  // in case this class is reused.
 75  0
     }
 76  
 
 77  
     @Override
 78  
     public void setModelValue(FlexTable table, DataModel model, String path) {
 79  0
         GWT.log("VariationsBinding.setModelValue...", null);
 80  0
     }
 81  
 
 82  
     @Override
 83  
     public void setWidgetValue(final FlexTable table, final DataModel model, String path) {               
 84  0
             table.clear();
 85  0
         final Data variationMap = model.get(path);        
 86  0
         if (variationMap != null) {
 87  0
             int row = 0;
 88  0
             for (final Data.Property property : variationMap) {
 89  0
                 final Data variationData = property.getValue();
 90  0
                 final int currentRow = row;
 91  
                 // If this is the right hand column (the original)
 92  
                 // Disable links and use labels instead
 93  0
                 if (isRightHandColumn == true){
 94  0
                     KSLabel label = new KSLabel(getVariationName(variationData));
 95  0
                     table.setWidget(row, 0, label );
 96  0
                 }
 97  
                 else {
 98  
                     // For left hand column show links
 99  0
                     Anchor anchor = new Anchor(getVariationName(variationData));
 100  0
                     anchor.addClickHandler(new ClickHandler() {
 101  
                         @Override
 102  
                         public void onClick(ClickEvent event) {
 103  0
                             ProgramRegistry.setData(variationData);
 104  0
                             ProgramRegistry.setRow(currentRow);
 105  0
                             ProgramUtils.addCredentialProgramDataToVariation(variationData, model);
 106  0
                             String id = (String) model.get("id");
 107  0
                             ViewContext viewContext = new ViewContext();
 108  0
                             viewContext.setId(id);
 109  0
                             viewContext.setIdType(IdType.OBJECT_ID);
 110  0
                             if(model.get("proposal/id") != null){
 111  
                                 // It is a proposal
 112  0
                                 variationData.set("isProposal", true);
 113  
                             }
 114  0
                             if(variationData.get("id")!=null){
 115  0
                                     viewContext.setAttribute(ProgramConstants.VARIATION_ID, variationData.get("id").toString());
 116  
                             }
 117  0
                             HistoryManager.navigate(url, viewContext);
 118  0
                         }
 119  
                     });
 120  
                     
 121  0
                     table.setWidget(row, 0, anchor);
 122  
                 }
 123  0
                 if (editable) {
 124  0
                     KSButton removeButton = new KSButton(getLabel(ProgramMsgConstants.COMMON_REMOVE));
 125  0
                     table.setWidget(row, 1, removeButton);                                             
 126  0
                     removeButton.addClickHandler(new ClickHandler() {
 127  
 
 128  
                         @Override
 129  
                         public void onClick(ClickEvent event) {
 130  0
                             if (Window.confirm("Are you sure you want to delete specialization?")) {
 131  0
                                 variationMap.remove(new Data.IntegerKey(currentRow));
 132  0
                                 MajorManager.getEventBus().fireEvent(new UpdateEvent());
 133  
                             }
 134  0
                         }
 135  
                     });
 136  0
                     if (configuration != null && configuration.checkPermission(model)) {
 137  0
                         removeButton.setEnabled(false);
 138  
                     }
 139  
 
 140  
                 }
 141  
 
 142  
                 //Set warning message if specialization has warnings
 143  0
                 if (hasWarnings(currentRow)){
 144  0
                     table.getRowFormatter().addStyleName(row, "warning");
 145  0
                     SpanPanel warning = new SpanPanel();
 146  0
                     warning.setHTML("<b> Warning </b> <br/>" + 
 147  
                                     Application.getApplicationContext().getMessage("validation", "validation.variation"));
 148  0
                     table.setWidget(row, 2, warning);
 149  0
                 } else {
 150  0
                         table.getRowFormatter().removeStyleName(row, "warning");
 151  0
                     table.setWidget(row, 2, new KSLabel(""));                        
 152  
                 }
 153  
                 
 154  0
                 row++;
 155  0
             }
 156  
         }
 157  0
     }
 158  
 
 159  
     private String getVariationName(Data data) {
 160  0
         StringBuilder nameBuilder = new StringBuilder();
 161  0
         nameBuilder.append(data.<Object>get(ProgramConstants.LONG_TITLE));
 162  0
         nameBuilder.append(" (").append(data.<Object>get(ProgramConstants.CODE)).append(")");
 163  0
         return nameBuilder.toString();
 164  
     }
 165  
     
 166  
     /**
 167  
      * This checks the validation warnings stored in the app context to see if any warnings exist
 168  
      * on the specialization.
 169  
      * 
 170  
      * @param variationIndex
 171  
      * @return true of variation at variationIndex has any warnings.
 172  
      */
 173  
     private boolean hasWarnings(int variationIndex){
 174  0
             List<ValidationResultInfo> validationWarnings = Application.getApplicationContext().getValidationWarnings();
 175  0
             for (ValidationResultInfo vr:validationWarnings){
 176  0
                     if (vr.getElement().contains(ProgramConstants.VARIATIONS + "/" + variationIndex)){
 177  0
                         return true;
 178  
                     }
 179  
             }
 180  0
             return false;
 181  
     }
 182  
     
 183  
     protected String getLabel(String messageKey) {
 184  0
         return Application.getApplicationContext().getUILabel(ProgramMsgConstants.PROGRAM_MSG_GROUP, messageKey);
 185  
     }
 186  
 }