Coverage Report - org.kuali.student.lum.lu.ui.dependency.client.widgets.DependencyResultPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
DependencyResultPanel
0%
0/61
0%
0/20
1.833
DependencyResultPanel$1
0%
0/4
0%
0/2
1.833
DependencyResultPanel$2
0%
0/4
0%
0/2
1.833
DependencyResultPanel$DependencySection
0%
0/33
0%
0/12
1.833
DependencyResultPanel$DependencySection$1
0%
0/3
N/A
1.833
DependencyResultPanel$DependencySection$2
0%
0/3
N/A
1.833
DependencyResultPanel$DependencyTypeSection
0%
0/29
0%
0/10
1.833
 
 1  
 package org.kuali.student.lum.lu.ui.dependency.client.widgets;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.HashMap;
 5  
 import java.util.List;
 6  
 
 7  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 8  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 9  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 10  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 11  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel;
 12  
 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout;
 13  
 import org.kuali.student.common.ui.client.widgets.search.CollapsablePanel;
 14  
 
 15  
 import com.google.gwt.event.dom.client.ClickEvent;
 16  
 import com.google.gwt.event.dom.client.ClickHandler;
 17  
 import com.google.gwt.user.client.ui.Composite;
 18  
 import com.google.gwt.user.client.ui.FlowPanel;
 19  
 import com.google.gwt.user.client.ui.Widget;
 20  
 
 21  
 public class DependencyResultPanel extends Composite{
 22  
 
 23  0
         protected KSLabel headerLabel = new KSLabel();
 24  
         
 25  0
         protected VerticalFieldLayout dependencySectionContainer = new VerticalFieldLayout();
 26  
         
 27  0
         protected HashMap<String, DependencySection> dependencySections = new HashMap<String, DependencySection>();
 28  
         
 29  
         //Map of all dependency types in all sections, keyed by "Dependency Section Name"."Dependency Type Name"
 30  0
         protected HashMap<String, DependencyTypeSection> dependencyTypeSections = new HashMap<String, DependencyTypeSection>();
 31  
 
 32  
         
 33  0
         public DependencyResultPanel(){
 34  0
                 this.initWidget(dependencySectionContainer);
 35  0
                 dependencySectionContainer.addWidget(headerLabel);
 36  0
                 dependencySectionContainer.addStyleName("ks-dependency-results");
 37  0
         }
 38  
         
 39  
         public void addSection(String sectionName, String sectionTitle){
 40  0
             DependencySection section = new DependencySection(sectionTitle);  
 41  0
             dependencySectionContainer.add(section);
 42  0
             dependencySections.put(sectionName, section);
 43  0
     }
 44  
     
 45  
     /**
 46  
      * @param section
 47  
      * @param collapsableSectionName
 48  
      */
 49  
         public DependencyTypeSection addDependencyTypeSection(String sectionName, String sectionTypeName, Widget sectionHeader){
 50  0
                 String typeSectionKey = sectionName + "." + sectionTypeName;
 51  0
             DependencyTypeSection typeSection = new DependencyTypeSection(sectionHeader);
 52  0
             dependencyTypeSections.put(typeSectionKey, typeSection);
 53  0
             DependencySection section = dependencySections.get(sectionName);
 54  0
             section.addWidget(typeSection);
 55  0
             return typeSection;
 56  
     }
 57  
         
 58  
         public DependencyTypeSection getDependencyTypeSection(String sectionName, String sectionTypeName){
 59  0
                 String typeSectionKey = sectionName + "." + sectionTypeName;
 60  0
                 return dependencyTypeSections.get(typeSectionKey);        
 61  
         }
 62  
         
 63  
     public void setHeaderTitle(String title){
 64  
             //TODO: This may need to be replaced with document to surface handle print/export
 65  0
             SectionTitle sectionTitle = SectionTitle.generateH2Title(title);
 66  0
                 dependencySectionContainer.setLayoutTitle(sectionTitle);
 67  0
                 dependencySectionContainer.underlineTitle(true);
 68  
             
 69  0
             KSButton expandLabel = new KSButton("Expand All", ButtonStyle.DEFAULT_ANCHOR);                                
 70  0
                 KSButton collapseLabel = new KSButton("Collapse All", ButtonStyle.DEFAULT_ANCHOR);
 71  
 
 72  0
                 FlowPanel expandArea = new FlowPanel();
 73  0
                 expandArea.add(expandLabel);
 74  0
                 expandArea.add(new SpanPanel(" | "));
 75  0
                 expandArea.add(collapseLabel);
 76  0
                 dependencySectionContainer.addWidget(expandArea);
 77  
                 
 78  0
                 expandLabel.addClickHandler(new ClickHandler(){
 79  
                         public void onClick(ClickEvent event) {
 80  0
                                 for (DependencySection section:dependencySections.values()){
 81  0
                                         section.expandAll();
 82  
                                 }
 83  0
                         }                
 84  
                 });                
 85  
 
 86  0
                 collapseLabel.addClickHandler(new ClickHandler(){
 87  
                         public void onClick(ClickEvent event) {
 88  0
                                 for (DependencySection section:dependencySections.values()){
 89  0
                                         section.collapseAll();
 90  
                                 }
 91  0
                         }                
 92  
                 });
 93  
                                 
 94  0
     }
 95  
     
 96  
     /**
 97  
      * Call this to finalize the dependency widgets once all data has been loaded.
 98  
      */
 99  
     public void finishLoad(){
 100  
             //This is to update the counts for dependencies
 101  0
             for (DependencyTypeSection typeSection:dependencyTypeSections.values()){
 102  0
                     typeSection.finishLoad();
 103  
             }
 104  
             
 105  
             //Don't show any sections that don't have dependencies
 106  0
             for (DependencySection section:dependencySections.values()){
 107  0
                            section.setVisible(section.dependencyTypeSections.size() > 0);
 108  
             }
 109  0
     }
 110  
 
 111  
         public static class DependencySection extends VerticalFieldLayout{
 112  0
                 protected FlowPanel header = new FlowPanel(); 
 113  
 
 114  
                 //List of dependency types within this section
 115  0
                 List<DependencyTypeSection> dependencyTypeSections = new ArrayList<DependencyTypeSection>();
 116  
                 
 117  0
                 public DependencySection(String title){
 118  0
                     SectionTitle sectionTitle = SectionTitle.generateH4Title(title);                    
 119  0
                     sectionTitle.addStyleName("ks-dependency-section-title");
 120  0
                     header.add(sectionTitle);
 121  0
                     header.addStyleName("header-underline");
 122  0
                     header.addStyleName("ks-dependency-section-header");
 123  0
                     this.setTitleWidget(header);
 124  0
                     this.addStyleName("ks-dependency-section");
 125  
                     
 126  0
                         KSButton expandLabel = new KSButton("Expand All", ButtonStyle.DEFAULT_ANCHOR);                                
 127  0
                         KSButton collapseLabel = new KSButton("Collapse All", ButtonStyle.DEFAULT_ANCHOR);
 128  
                         
 129  0
                         expandLabel.addClickHandler(new ClickHandler(){
 130  
                                 public void onClick(ClickEvent event) {
 131  0
                                         DependencySection.this.expandAll();
 132  0
                                 }                
 133  
                         });                
 134  
 
 135  0
                         collapseLabel.addClickHandler(new ClickHandler(){
 136  
                                 public void onClick(ClickEvent event) {
 137  0
                                         DependencySection.this.collapseAll();
 138  0
                                 }                
 139  
                         });                
 140  
 
 141  0
                         header.add(expandLabel);
 142  0
                         header.add(new SpanPanel(" | "));
 143  0
                         header.add(collapseLabel);
 144  
                                                 
 145  0
                 }
 146  
                                 
 147  
                 
 148  
                 @Override
 149  
                 public String addWidget(Widget widget) {
 150  0
                         dependencyTypeSections.add((DependencyTypeSection)widget);
 151  0
                         return super.addWidget(widget);
 152  
                 }
 153  
 
 154  
 
 155  
                 public void expandAll(){
 156  0
                         for (DependencyTypeSection typeSection:dependencyTypeSections){
 157  0
                                 if (!typeSection.isOpen()){
 158  0
                                         typeSection.open();
 159  
                                 }
 160  
                         }
 161  0
                 }
 162  
                 
 163  
                 public void collapseAll(){
 164  0
                         for (DependencyTypeSection typeSection:dependencyTypeSections){
 165  0
                                 typeSection.close();
 166  
                         }                        
 167  0
                 }
 168  
                 
 169  
                 protected void setVisibility(){
 170  
                         //If all children elements (dependency types) in this section is not visible, the entire
 171  
                         //section should not be showing.
 172  0
                         int visibleCount = 0;
 173  0
                         for (DependencyTypeSection typeSection:dependencyTypeSections){
 174  0
                                 if (typeSection.isVisible()){
 175  0
                                         visibleCount++;
 176  
                                 }
 177  
                         }
 178  0
                         this.setVisible(visibleCount > 0);
 179  0
                 }
 180  
         }
 181  
 
 182  
         public static class DependencyTypeSection extends CollapsablePanel{
 183  
 
 184  0
                 protected FlowPanel content = new FlowPanel();
 185  0
                 KSLabel countLabel = new KSLabel();
 186  
                 
 187  0
                 List<CollapsablePanel> dependencyItems = new ArrayList<CollapsablePanel>();
 188  
                 
 189  0
                 public DependencyTypeSection(Widget label) {
 190  0
                         this.init(label, content, isOpen, true, ImagePosition.ALIGN_LEFT);
 191  0
                     content.addStyleName("ks-dependency-type-section");
 192  0
                         super.linkPanel.add(countLabel);
 193  0
                 }
 194  
                                                 
 195  
                 public void finishLoad(){
 196  0
                         int numItems = dependencyItems.size();
 197  0
                         countLabel.setText("(" + numItems + "):");
 198  0
                         if (numItems <= 5){
 199  0
                                 super.content.setVisible(true);
 200  0
                                 super.isOpen = true;
 201  0
                                 super.setImageState();
 202  
                         }
 203  0
                 }
 204  
                 
 205  
                 public void addDependencyItem(Widget label, Widget details){
 206  0
                         CollapsablePanel depItem = null;
 207  0
                         if (details != null){
 208  0
                                 depItem = new CollapsablePanel(label, details, false, true, ImagePosition.ALIGN_LEFT);
 209  
                         } else {
 210  0
                                 depItem = new CollapsablePanel(label, new SpanPanel(), false, false, ImagePosition.ALIGN_LEFT);
 211  
                         }
 212  0
                         content.add(depItem);
 213  0
                         dependencyItems.add(depItem);
 214  0
                 }
 215  
 
 216  
                 public void expandAll(){
 217  0
                         for (CollapsablePanel depItem:dependencyItems){
 218  0
                                 if (!depItem.isOpen()){
 219  0
                                         depItem.open();
 220  
                                 }
 221  
                         }
 222  0
                 }
 223  
                 
 224  
                 public void collapseAll(){
 225  0
                         for (CollapsablePanel depItem:dependencyItems){
 226  0
                                 depItem.close();
 227  
                         }                        
 228  0
                 }
 229  
         }
 230  
 
 231  
         public void hide(String dependencySection, String dependencyType){                
 232  0
                 DependencyTypeSection typeSection = dependencyTypeSections.get(dependencySection + "." + dependencyType);
 233  0
                 if (typeSection != null){
 234  0
                         typeSection.setVisible(false);
 235  0
                         DependencySection section = dependencySections.get(dependencySection);
 236  0
                         section.setVisibility();
 237  
                 }
 238  0
         }
 239  
         
 240  
         public void show(String dependencySection, String dependencyType){
 241  0
                 DependencyTypeSection typeSection = dependencyTypeSections.get(dependencySection + "." + dependencyType);
 242  0
                 if (typeSection != null){
 243  0
                         typeSection.setVisible(true);
 244  0
                         DependencySection section = dependencySections.get(dependencySection);
 245  0
                         section.setVisibility();                        
 246  
                 }
 247  0
         }
 248  
         
 249  
         public void hideAll(){
 250  0
                 for (DependencyTypeSection typeSection:dependencyTypeSections.values()){
 251  0
                         typeSection.setVisible(false);
 252  
                 }
 253  0
                 for (DependencySection section:dependencySections.values()){
 254  0
                         section.setVisible(false);
 255  
                 }
 256  0
         }
 257  
 
 258  
         public void showAll(){
 259  0
                 for (DependencyTypeSection typeSection:dependencyTypeSections.values()){
 260  0
                         typeSection.setVisible(true);
 261  
                 }
 262  0
                 for (DependencySection section:dependencySections.values()){
 263  0
                         section.setVisible(section.dependencyTypeSections.size() > 0);
 264  
                 }                
 265  0
         }
 266  
 
 267  
 }