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