PageRenderTime 33ms CodeModel.GetById 16ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/ftr-gwt-library-date/src/main/java/eu/future/earth/gwt/client/date/picker/DatePickerDialog.java

http://ftr-gwt-library.googlecode.com/
Java | 61 lines | 48 code | 13 blank | 0 comment | 7 complexity | 11895a260f227dade85e9771e623adaf MD5 | raw file
 1package eu.future.earth.gwt.client.date.picker;
 2
 3import java.util.Date;
 4
 5import com.google.gwt.event.shared.HandlerRegistration;
 6import com.google.gwt.user.client.DOM;
 7import com.google.gwt.user.client.ui.DecoratedPopupPanel;
 8import com.google.gwt.user.client.ui.Widget;
 9
10import eu.future.earth.gwt.client.FtrGwtDatePickerCss;
11import eu.future.earth.gwt.client.date.picker.DateSelectEvent.DateSelectEventActions;
12
13public class DatePickerDialog extends DecoratedPopupPanel implements DateSelectListener, HasDateSelectHandlers {
14
15	private DatePickerMonthNavigator whole = null;
16
17	public DatePickerDialog(DatePickerRenderer renderer) {
18		super(true);
19		super.addStyleName(FtrGwtDatePickerCss.DIALOG);
20		whole = new DatePickerMonthNavigator(renderer);
21		setWidget(whole);
22		whole.setWidth("250px");
23		whole.addDateSelectEventHandler(this);
24	}
25
26
27	public void addWidgetToPicker(Widget newWidget) {
28		whole.addWidgetToPicker(newWidget);
29	};
30	
31	public void show(Widget below) {
32		if (below == null) {
33			super.show();
34			super.center();
35		} else {
36			super.show();
37			super.setPopupPosition(below.getAbsoluteLeft(), below.getAbsoluteTop() + below.getOffsetHeight() + 10);
38			DOM.scrollIntoView(super.getElement());
39		}
40	}
41
42	public void setSelectedDate(Date newDate) {
43		whole.setSelectedDate(newDate);
44	}
45
46	public HandlerRegistration addDateSelectEventHandler(DateSelectListener handler) {
47		return addHandler(handler, DateSelectEvent.getType());
48	}
49
50	public void handleDateSelectEvent(DateSelectEvent newEvent) {
51		if (newEvent.getCommand() == DateSelectEventActions.SELECT_DAY) {
52			DateSelectEvent.fire(this, newEvent);
53			this.hide();
54		}
55		if (newEvent.getCommand() == DateSelectEventActions.SELECT_NEW_MONTH) {
56			DateSelectEvent.fire(this, newEvent);
57			this.hide();
58		}
59	}
60
61}