Coverage Report - org.kuali.student.common.ui.client.widgets.panels.collapsable.VerticalCollapsableDrawer
 
Classes in this File Line Coverage Branch Coverage Complexity
VerticalCollapsableDrawer
0%
0/21
N/A
1.545
VerticalCollapsableDrawer$1
0%
0/7
0%
0/2
1.545
VerticalCollapsableDrawer$ContentAnimation
0%
0/30
0%
0/10
1.545
VerticalCollapsableDrawer$VerticalCollapsableDrawerBinder
N/A
N/A
1.545
 
 1  
 package org.kuali.student.common.ui.client.widgets.panels.collapsable;
 2  
 
 3  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 4  
 
 5  
 import com.google.gwt.animation.client.Animation;
 6  
 import com.google.gwt.core.client.GWT;
 7  
 import com.google.gwt.event.dom.client.ClickEvent;
 8  
 import com.google.gwt.event.dom.client.ClickHandler;
 9  
 import com.google.gwt.uibinder.client.UiBinder;
 10  
 import com.google.gwt.uibinder.client.UiField;
 11  
 import com.google.gwt.user.client.DOM;
 12  
 import com.google.gwt.user.client.ui.Composite;
 13  
 import com.google.gwt.user.client.ui.DisclosurePanel;
 14  
 import com.google.gwt.user.client.ui.HTMLPanel;
 15  
 import com.google.gwt.user.client.ui.SimplePanel;
 16  
 import com.google.gwt.user.client.ui.Widget;
 17  
 
 18  
 public class VerticalCollapsableDrawer extends Composite{
 19  0
                 private static VerticalCollapsableDrawerBinder uiBinder = GWT
 20  
                 .create(VerticalCollapsableDrawerBinder.class);
 21  
                 
 22  
                 interface VerticalCollapsableDrawerBinder extends
 23  
                         UiBinder<Widget, VerticalCollapsableDrawer> {
 24  
                 }
 25  
 
 26  
                 @UiField
 27  
                 public SimplePanel content;
 28  
                 
 29  
                 @UiField
 30  
                 public KSButton drawerHandle;
 31  
                 
 32  
                 @UiField
 33  
                 public HTMLPanel container;
 34  
                 
 35  0
                 protected boolean isOpen = true;
 36  0
                 private ContentAnimation animation = new ContentAnimation();
 37  
                 
 38  0
                 public VerticalCollapsableDrawer(){
 39  0
                     initialise();
 40  0
                 }
 41  
                 
 42  
                 public void initialise(){
 43  0
                         initWidget(uiBinder.createAndBindUi(this));
 44  0
                         drawerHandle.setText("\u00AB");
 45  0
                         drawerHandle.addClickHandler(new ClickHandler(){
 46  
 
 47  
                                 @Override
 48  
                                 public void onClick(ClickEvent event) {
 49  0
                                         if(isOpen){
 50  0
                                                 close();
 51  0
                                                 drawerHandle.setText("\u00BB");
 52  
                                         }
 53  
                                         else{
 54  0
                                                 open();
 55  0
                                                 drawerHandle.setText("\u00AB");
 56  
                                         }
 57  
                                         
 58  0
                                 }
 59  
                         });
 60  0
                 }
 61  
                 
 62  
                 @Override
 63  
                 protected void onLoad() {
 64  0
                         super.onLoad();
 65  0
                         container.getElementById("collapsePanel").setAttribute("style", "height: " 
 66  
                                         + content.getOffsetHeight() + "px");
 67  
                         //this.getElement().g;
 68  0
                 }
 69  
                 
 70  
                 public void open(){
 71  0
                         isOpen = true;
 72  0
                         animation.setOpen(this, true);
 73  0
                 }
 74  
                 
 75  
                 public void close(){
 76  0
                         isOpen = false;
 77  0
                         animation.setOpen(this, true);
 78  0
                 }
 79  
                 
 80  
                 public void setContent(Widget w){
 81  0
                         content.setWidget(w);
 82  0
                 }
 83  
                 
 84  0
                 private static class ContentAnimation extends Animation {
 85  
                             /**
 86  
                              * Whether the item is being opened or closed.
 87  
                              */
 88  
                             private boolean opening;
 89  
 
 90  
                             /**
 91  
                              * The {@link DisclosurePanel} being affected.
 92  
                              */
 93  
                             private VerticalCollapsableDrawer curPanel;
 94  
 
 95  
                             /**
 96  
                              * Open or close the content.
 97  
                              *
 98  
                              * @param panel the panel to open or close
 99  
                              * @param animate true to animate, false to open instantly
 100  
                              */
 101  
                             public void setOpen(VerticalCollapsableDrawer panel, boolean animate) {
 102  
                               // Immediately complete previous open
 103  0
                               cancel();
 104  
 
 105  
                               // Open the new item
 106  0
                               if (animate) {
 107  0
                                 curPanel = panel;
 108  0
                                 opening = panel.isOpen;
 109  0
                                 run(1000);
 110  
                               } else {
 111  0
                                 panel.content.setVisible(panel.isOpen);
 112  0
                                 if (panel.isOpen) {
 113  
                                   // Special treatment on the visible case to ensure LazyPanel works
 114  0
                                   panel.content.setVisible(true);
 115  
                                 }
 116  
                               }
 117  0
                             }
 118  
 
 119  
                             @Override
 120  
                             protected void onComplete() {
 121  0
                               if (!opening) {
 122  0
                                 curPanel.content.setVisible(false);
 123  
                               }
 124  0
                               DOM.setStyleAttribute(curPanel.content.getElement(), "width",
 125  
                                   "auto");
 126  0
                               DOM.setStyleAttribute(curPanel.content.getElement(), "overflow", "visible");
 127  0
                               curPanel = null;
 128  0
                             }
 129  
 
 130  
                             @Override
 131  
                             protected void onStart() {
 132  0
                               super.onStart();
 133  0
                               DOM.setStyleAttribute(curPanel.content.getElement(), "overflow", "hidden");
 134  0
                               if (opening) {
 135  0
                                 curPanel.content.setVisible(true);
 136  
                                 // Special treatment on the visible case to ensure LazyPanel works
 137  0
                                 curPanel.content.setVisible(true);
 138  
                              }
 139  0
                             }
 140  
 
 141  
                             @Override
 142  
                             protected void onUpdate(double progress) {
 143  0
                               int scrollWidth = DOM.getElementPropertyInt(
 144  
                                   curPanel.content.getElement(), "scrollWidth");
 145  0
                               int width = (int) (progress * scrollWidth);
 146  0
                               if (!opening) {
 147  0
                                 width = scrollWidth - width;
 148  
                               }
 149  0
                               width = Math.max(width, 1);
 150  
 
 151  0
                               DOM.setStyleAttribute(curPanel.content.getElement(), "width",
 152  
                                   width + "px");
 153  0
                               DOM.setStyleAttribute(curPanel.content.getElement(), "height",
 154  
                                   "auto");
 155  0
                             }
 156  
                  }
 157  
                 
 158  
                 
 159  
 }