Coverage Report - org.kuali.student.lum.program.client.widgets.ProgramSideBar
 
Classes in this File Line Coverage Branch Coverage Complexity
ProgramSideBar
0%
0/88
0%
0/16
1.611
ProgramSideBar$1
0%
0/3
N/A
1.611
ProgramSideBar$2
0%
0/5
N/A
1.611
ProgramSideBar$3
0%
0/3
N/A
1.611
ProgramSideBar$4
0%
0/6
0%
0/4
1.611
ProgramSideBar$5
0%
0/1
N/A
1.611
ProgramSideBar$State
0%
0/3
N/A
1.611
ProgramSideBar$Type
0%
0/4
N/A
1.611
 
 1  
 package org.kuali.student.lum.program.client.widgets;
 2  
 
 3  
 import java.util.Date;
 4  
 
 5  
 import org.kuali.student.common.ui.client.application.ViewContext;
 6  
 import org.kuali.student.common.ui.client.configurable.mvc.DefaultWidgetFactory;
 7  
 import org.kuali.student.common.ui.client.configurable.mvc.binding.HasDataValueBinding;
 8  
 import org.kuali.student.common.ui.client.mvc.DataModel;
 9  
 import org.kuali.student.common.ui.client.mvc.HasDataValue;
 10  
 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
 11  
 import org.kuali.student.core.assembly.data.Metadata;
 12  
 import org.kuali.student.core.assembly.data.QueryPath;
 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.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.major.MajorController;
 19  
 import org.kuali.student.lum.program.client.properties.ProgramProperties;
 20  
 
 21  
 import com.google.gwt.event.dom.client.ClickEvent;
 22  
 import com.google.gwt.event.dom.client.ClickHandler;
 23  
 import com.google.gwt.event.shared.HandlerManager;
 24  
 import com.google.gwt.user.client.ui.Anchor;
 25  
 import com.google.gwt.user.client.ui.Composite;
 26  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 27  
 import com.google.gwt.user.client.ui.Label;
 28  
 import com.google.gwt.user.client.ui.SimplePanel;
 29  
 import com.google.gwt.user.client.ui.VerticalPanel;
 30  
 import com.google.gwt.user.client.ui.Widget;
 31  
 
 32  
 /**
 33  
  * @author Igor
 34  
  */
 35  0
 public class ProgramSideBar extends Composite {
 36  
 
 37  0
     private final VerticalPanel content = new VerticalPanel();
 38  
 
 39  0
     private State state = State.VIEW;
 40  
 
 41  
     private Type type;
 42  
 
 43  
     private Label versionLabel;
 44  
     private Anchor viewVersion;
 45  0
     private Label historyLabel = new Label(ProgramProperties.get().sideBar_history());
 46  0
     private Label lastUpdatedDate = new Label();
 47  0
     private SimplePanel scheduledReviewDate = new SimplePanel();
 48  0
     private Label lastReviewDate = new Label();
 49  
     private final HandlerManager eventBus;
 50  
 
 51  
     private ViewContext viewContext;
 52  
 
 53  
     private final SideBarDialogManager dialogManager;
 54  
 
 55  0
     public ProgramSideBar(HandlerManager eventBus, Type type) {
 56  0
         this.eventBus = eventBus;
 57  0
         this.type = type;
 58  0
         dialogManager = new SideBarDialogManager(eventBus);
 59  0
         initWidget(content);
 60  0
         setStyles();
 61  0
         buildLayout();
 62  0
         bind();
 63  0
     }
 64  
 
 65  
     public void initialize(MajorController controller) {
 66  0
         DataModel model = controller.getProgramModel();
 67  0
         dialogManager.configureView(model.getDefinition(), controller);
 68  0
         viewContext = controller.getViewContext();
 69  0
         updateFields(model);
 70  0
     }
 71  
 
 72  
     private void bind() {
 73  0
         eventBus.addHandler(ModelLoadedEvent.TYPE, new ModelLoadedEvent.Handler() {
 74  
             @Override
 75  
             public void onEvent(ModelLoadedEvent event) {
 76  0
                 updateFields(event.getModel());
 77  0
             }
 78  
         });
 79  0
         eventBus.addHandler(AfterSaveEvent.TYPE, new AfterSaveEvent.Handler() {
 80  
             @Override
 81  
             public void onEvent(AfterSaveEvent event) {
 82  0
                 DataModel model = event.getModel();
 83  0
                 dialogManager.configureView(model.getDefinition(), event.getController());
 84  0
                 updateFields(event.getModel());
 85  0
             }
 86  
         });
 87  0
     }
 88  
 
 89  
     private void updateFields(DataModel model) {
 90  0
             setVersion((Long)model.get(ProgramConstants.VERSION),versionLabel);
 91  0
         setDate((Date) model.get(ProgramConstants.LAST_UPDATED_DATE), lastUpdatedDate);
 92  0
         lastReviewDate.setText((String) model.get(ProgramConstants.LAST_REVIEW_DATE));
 93  0
         setWidget(ProgramConstants.SCHEDULED_REVIEW_DATE, scheduledReviewDate, model);
 94  0
     }
 95  
 
 96  
     private void setDate(Date updatedDate, Label lastUpdatedDate) {
 97  0
         if (updatedDate != null) {
 98  0
             lastUpdatedDate.setText(ProgramUtils.df.format(updatedDate));
 99  
         } else {
 100  0
             lastUpdatedDate.setText("");
 101  
         }
 102  0
     }
 103  
 
 104  
     private void setVersion(Long version, Label versionaLabel){
 105  0
             if (version != null){
 106  0
                        viewVersion.setVisible(version >= 1);
 107  0
                     versionLabel.setText(ProgramProperties.get().sideBar_version(String.valueOf(version)));
 108  
             } else {
 109  0
                     versionLabel.setText(ProgramProperties.get().sideBar_version(""));
 110  0
                     viewVersion.setVisible(false);
 111  
             }
 112  0
     }
 113  
 
 114  
     private void setWidget(String path, SimplePanel container, DataModel model) {
 115  0
         Metadata mData = model.getMetadata(QueryPath.parse(path));
 116  
 
 117  
         // CoreProgram and CredentialProgram don't have SCHEDULED_REVIEW_DATE
 118  0
         if (null == mData && ProgramConstants.SCHEDULED_REVIEW_DATE.equals(path)) {
 119  0
             return;
 120  
         }
 121  0
         Widget widget = DefaultWidgetFactory.getInstance().getReadOnlyWidget(model.getMetadata(QueryPath.parse(path)));
 122  0
         HasDataValueBinding.INSTANCE.setWidgetValue((HasDataValue) widget, model, path);
 123  0
         container.setWidget(widget);
 124  0
     }
 125  
 
 126  
 
 127  
     private void buildLayout() {
 128  0
         content.clear();
 129  0
         Label history = new Label(ProgramProperties.get().sideBar_history());
 130  0
         history.addStyleName("KS-Program-History");
 131  0
         content.add(history);
 132  
 
 133  0
         content.add(createVersionPanel());
 134  0
         content.add(createDatePanel(ProgramProperties.get().sideBar_programLastUpdated(), lastUpdatedDate, false));
 135  0
         if (type == Type.MAJOR) {
 136  0
             content.add(createDatePanel(ProgramProperties.get().sideBar_scheduledReviewDate(), scheduledReviewDate, true));
 137  0
             content.add(createDatePanel(ProgramProperties.get().sideBar_lastReviewDate(), lastReviewDate, true));
 138  
         }
 139  0
         content.add(createVersionHistoryPanel());
 140  0
     }
 141  
 
 142  
     private Widget createDatePanel(String title, Widget widget, boolean showEdit) {
 143  0
         VerticalPanel verticalPanel = new VerticalPanel();
 144  0
         HorizontalPanel datePanel = new HorizontalPanel();
 145  0
         datePanel.addStyleName("datePanel");
 146  0
         datePanel.add(widget);
 147  0
         if (state == State.EDIT && showEdit) {
 148  0
             Anchor edit = new Anchor(ProgramProperties.get().common_edit());
 149  0
             edit.addClickHandler(new ClickHandler() {
 150  
 
 151  
                 @Override
 152  
                 public void onClick(ClickEvent event) {
 153  0
                     dialogManager.show();
 154  0
                 }
 155  
             });
 156  0
             datePanel.add(edit);
 157  
         }
 158  0
         verticalPanel.add(new Label(title));
 159  0
         verticalPanel.add(datePanel);
 160  0
         return verticalPanel;
 161  
     }
 162  
 
 163  
     private Widget createHistoryPanel(){
 164  0
             VerticalPanel  verticalPanel = new VerticalPanel();
 165  0
             versionLabel = new Label(ProgramProperties.get().sideBar_version(""));
 166  0
             verticalPanel.add(versionLabel);
 167  0
             return verticalPanel;
 168  
     }
 169  
 
 170  
     private Widget createVersionPanel(){
 171  0
             VerticalPanel  verticalPanel = new VerticalPanel();
 172  0
             versionLabel = new Label(ProgramProperties.get().sideBar_version(""));
 173  0
             verticalPanel.add(versionLabel);
 174  0
             return verticalPanel;
 175  
     }
 176  
 
 177  
     private Widget createVersionHistoryPanel(){
 178  0
             VerticalPanel  verticalPanel = new VerticalPanel();
 179  0
             viewVersion = new Anchor(ProgramProperties.get().sideBar_viewHistory());
 180  0
             viewVersion.addClickHandler(new ClickHandler(){
 181  
                         @Override
 182  
                         public void onClick(ClickEvent event) {
 183  0
                                 switch (type){
 184  0
                                         case MAJOR: HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM_VERSIONS.getLocation()); break;
 185  0
                                         case CORE: HistoryManager.navigate(AppLocations.Locations.VIEW_CORE_VERSIONS.getLocation()); break;
 186  0
                                         case CREDENTIAL: HistoryManager.navigate(AppLocations.Locations.VIEW_BACC_VERSIONS.getLocation()); break;
 187  
                                 }
 188  
 
 189  
 
 190  0
                         }
 191  
 
 192  
             });
 193  
             //viewVersion.setVisible(false);
 194  
 
 195  0
             verticalPanel.add(viewVersion);
 196  
 
 197  0
             return verticalPanel;
 198  
     }
 199  
 
 200  
     public void setState(State state) {
 201  0
         this.state = state;
 202  0
         buildLayout();
 203  0
     }
 204  
 
 205  
     private void setStyles() {
 206  0
         content.addStyleName("sideBar");
 207  0
         content.addStyleName("KS-Program-History-Sidebar");
 208  0
         historyLabel.addStyleName("history");
 209  0
     }
 210  
 
 211  0
     public static enum State {
 212  0
         EDIT,
 213  0
         VIEW
 214  
     }
 215  
 
 216  0
     public static enum Type {
 217  0
         CREDENTIAL,
 218  0
         CORE,
 219  0
         MAJOR
 220  
     }
 221  
 }