2828
2929public class MaterialDatePicker extends FocusPanel {
3030
31+ /**
32+ * Delegate interface for handling picker events.
33+ */
34+ public interface MaterialDatePickerDelegate {
35+
36+ /**
37+ * Called as soon as a click occurs on the calendar widget. !EXPERIMENTAL!
38+ * @param currDate which is currently selected.
39+ */
40+ void onCalendarClick (Date currDate );
41+ }
42+
3143 private HTMLPanel panel ;
3244 private Date date ;
3345 private String placeholder ;
3446 private String id ;
47+ private MaterialDatePickerDelegate delegate ;
48+
3549 public MaterialDatePicker () {
3650
3751 }
@@ -45,6 +59,7 @@ protected void onAttach() {
4559 panel = new HTMLPanel ("<input placeholder='" +placeholder +"' type='date' id='" +id +"' class='datepicker'>" );
4660 this .add (panel );
4761 initDatePicker (id );
62+ initClickHandler (id , this );
4863 }
4964
5065 public static native String getDatePickerValue (String id )/*-{
@@ -59,6 +74,27 @@ private static native void setDatePickerValue(String value, String id)/*-{
5974 public static native void initDatePicker (String id )/*-{
6075 $wnd.jQuery('#' + id).pickadate();
6176 }-*/ ;
77+
78+ native void initClickHandler (String id , MaterialDatePicker picker ) /*-{
79+ $wnd.jQuery('.picker__wrap').bind('click',function(){
80+ [email protected] ::notifyDelegate()(); 81+ });
82+ }-*/ ;
83+
84+ /**
85+ * A delegate which implements handling of events from date picker.
86+ * @param delegate which will be notified on picker events.
87+ * @see MaterialDatePickerDelegate
88+ */
89+ public void setDelegate (MaterialDatePickerDelegate delegate ) {
90+ this .delegate = delegate ;
91+ }
92+
93+ void notifyDelegate () {
94+ if (delegate != null ) {
95+ delegate .onCalendarClick (getDate ());
96+ }
97+ }
6298
6399
64100
0 commit comments