Coverage Report - org.kuali.student.lum.program.client.widgets.SummaryActionPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
SummaryActionPanel
0%
0/59
0%
0/10
1.278
SummaryActionPanel$1
0%
0/4
N/A
1.278
SummaryActionPanel$2
0%
0/4
N/A
1.278
SummaryActionPanel$3
0%
0/3
N/A
1.278
SummaryActionPanel$4
0%
0/3
N/A
1.278
SummaryActionPanel$5
0%
0/3
N/A
1.278
SummaryActionPanel$6
0%
0/6
N/A
1.278
SummaryActionPanel$7
0%
0/3
N/A
1.278
 
 1  
 package org.kuali.student.lum.program.client.widgets;
 2  
 
 3  
 import com.google.gwt.event.dom.client.ClickEvent;
 4  
 import com.google.gwt.event.dom.client.ClickHandler;
 5  
 import com.google.gwt.event.shared.HandlerManager;
 6  
 import com.google.gwt.user.client.ui.*;
 7  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
 8  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 9  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 10  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 11  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 12  
 import org.kuali.student.common.ui.client.widgets.KSLightBox;
 13  
 import org.kuali.student.lum.program.client.ProgramConstants;
 14  
 import org.kuali.student.lum.program.client.ProgramStatus;
 15  
 import org.kuali.student.lum.program.client.ProgramUtils;
 16  
 import org.kuali.student.lum.program.client.events.AfterSaveEvent;
 17  
 import org.kuali.student.lum.program.client.events.ModelLoadedEvent;
 18  
 import org.kuali.student.lum.program.client.events.StateChangeEvent;
 19  
 import org.kuali.student.lum.program.client.properties.ProgramProperties;
 20  
 
 21  
 /**
 22  
  * @author Igor
 23  
  */
 24  0
 public class SummaryActionPanel extends Composite {
 25  
 
 26  0
     private final HorizontalPanel content = new HorizontalPanel();
 27  
 
 28  0
     private final KSButton approveButton = new KSButton(ProgramProperties.get().button_approve());
 29  
 
 30  0
     private final KSButton activateButton = new KSButton(ProgramProperties.get().button_activate(), ButtonStyle.SECONDARY);
 31  
 
 32  0
     private final Anchor exitAnchor = new Anchor(ProgramProperties.get().link_backCurriculum());
 33  
 
 34  0
     private final KSLightBox activateDialog = new KSLightBox();
 35  
     private Section activateSection;
 36  
 
 37  
     private DataModel dataModel;
 38  
 
 39  
     private HandlerManager eventBus;
 40  
 
 41  0
     public SummaryActionPanel(Section activateSection, HandlerManager eventBus) {
 42  0
         initWidget(content);
 43  0
         this.activateSection = activateSection;
 44  0
         this.eventBus = eventBus;
 45  0
         buildLayout();
 46  0
         setStyles();
 47  0
         bind();
 48  0
     }
 49  
 
 50  
     private void bind() {
 51  0
         eventBus.addHandler(AfterSaveEvent.TYPE, new AfterSaveEvent.Handler() {
 52  
             @Override
 53  
             public void onEvent(AfterSaveEvent event) {
 54  0
                 dataModel = event.getModel();
 55  0
                 processStatus();
 56  0
             }
 57  
         });
 58  0
         eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() {
 59  
             @Override
 60  
             public void onEvent(ModelLoadedEvent event) {
 61  0
                 dataModel = event.getModel();
 62  0
                 processStatus();
 63  0
             }
 64  
         });
 65  0
         approveButton.addClickHandler(new ClickHandler() {
 66  
             @Override
 67  
             public void onClick(ClickEvent event) {
 68  0
                 processButtonClick(ProgramStatus.APPROVED);
 69  0
             }
 70  
         });
 71  0
         activateButton.addClickHandler(new ClickHandler() {
 72  
             @Override
 73  
             public void onClick(ClickEvent event) {
 74  0
                 processActivateClick();
 75  0
             }
 76  
         });
 77  0
         exitAnchor.addClickHandler(new ClickHandler() {
 78  
             @Override
 79  
             public void onClick(ClickEvent event) {
 80  0
                 HistoryManager.navigate("/HOME/CURRICULUM_HOME");
 81  0
             }
 82  
         });
 83  0
     }
 84  
 
 85  
     private void processStatus() {
 86  0
         processStatus(ProgramStatus.of(dataModel.<String>get(ProgramConstants.STATE)));
 87  0
     }
 88  
 
 89  
     private void processButtonClick(ProgramStatus status) {
 90  0
         eventBus.fireEvent(new StateChangeEvent(status));
 91  0
     }
 92  
 
 93  
     private void processActivateClick() {
 94  0
         String versionFromId = dataModel.get(ProgramConstants.VERSION_FROM_ID);
 95  0
         if (versionFromId != null) {
 96  0
             activateSection.updateWidgetData(dataModel);
 97  0
             activateDialog.show();
 98  
         } else {
 99  0
             processButtonClick(ProgramStatus.ACTIVE);
 100  
         }
 101  0
     }
 102  
 
 103  
     private void processStatus(ProgramStatus programStatus) {
 104  0
         if (programStatus == ProgramStatus.DRAFT) {
 105  0
             enableButtons(true, false);
 106  0
         } else if (programStatus == ProgramStatus.APPROVED) {
 107  0
             enableButtons(false, true);
 108  0
         } else if (programStatus == ProgramStatus.ACTIVE) {
 109  0
             enableButtons(false, false);
 110  0
         } else if (programStatus == ProgramStatus.SUPERSEDED) {
 111  0
             enableButtons(false, false);
 112  
         }
 113  0
     }
 114  
 
 115  
     private void setStyles() {
 116  0
         content.addStyleName("programActionPanel");
 117  0
         content.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
 118  0
     }
 119  
 
 120  
     private void buildLayout() {
 121  0
         content.add(approveButton);
 122  0
         content.add(activateButton);
 123  0
         content.add(exitAnchor);
 124  
 
 125  0
         buildActivateDialog();
 126  0
     }
 127  
 
 128  
     private void buildActivateDialog() {
 129  0
         FlowPanel panel = new FlowPanel();
 130  
 
 131  0
         panel.add((Widget) activateSection);
 132  
 
 133  0
         KSButton activate = new KSButton("Activate", new ClickHandler() {
 134  
             public void onClick(ClickEvent event) {
 135  0
                 activateSection.updateModel(dataModel);
 136  0
                 ProgramUtils.setPreviousStatus(dataModel, ProgramStatus.SUPERSEDED.getValue());
 137  0
                 processButtonClick(ProgramStatus.ACTIVE);
 138  0
                 activateDialog.hide();
 139  0
             }
 140  
         });
 141  0
         activateDialog.addButton(activate);
 142  
 
 143  0
         KSButton cancel = new KSButton("Cancel", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler() {
 144  
             public void onClick(ClickEvent event) {
 145  0
                 activateDialog.hide();
 146  0
             }
 147  
         });
 148  0
         activateDialog.addButton(cancel);
 149  
 
 150  0
         activateDialog.setWidget(panel);
 151  0
     }
 152  
 
 153  
     private void enableButtons(boolean enableApprove, boolean enableActivate) {
 154  0
         approveButton.setEnabled(enableApprove);
 155  0
         activateButton.setEnabled(enableActivate);
 156  0
     }
 157  
 
 158  
     private ProgramStatus getStatus() {
 159  0
         return ProgramStatus.of(dataModel.<String>get(ProgramConstants.STATE));
 160  
     }
 161  
 }