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