| 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 |  |                           | 
  | 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 |  |   | 
  | 83 |  |   | 
  | 84 |  |                              private boolean opening; | 
  | 85 |  |   | 
  | 86 |  |                               | 
  | 87 |  |   | 
  | 88 |  |   | 
  | 89 |  |                              private VerticalCollapsableDrawer curPanel; | 
  | 90 |  |   | 
  | 91 |  |                               | 
  | 92 |  |   | 
  | 93 |  |   | 
  | 94 |  |   | 
  | 95 |  |   | 
  | 96 |  |   | 
  | 97 |  |                              public void setOpen(VerticalCollapsableDrawer panel, boolean animate) { | 
  | 98 |  |                                 | 
  | 99 | 0 |                                cancel(); | 
  | 100 |  |   | 
  | 101 |  |                                 | 
  | 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 |  |                                     | 
  | 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 |  |                                   | 
  | 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 |  |  } |