All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.future.earth.gwt.client.date.picker.DatePickerMonthNavigator Maven / Gradle / Ivy

There is a newer version: 3.3
Show newest version
package eu.future.earth.gwt.client.date.picker;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.google.gwt.dom.client.Style.Float;
import com.google.gwt.dom.client.Style.TextAlign;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

import eu.future.earth.gwt.client.FtrGwtDatePickerCss;
import eu.future.earth.gwt.client.date.picker.DateSelectEvent.DateSelectEventActions;
import eu.future.earth.gwt.client.ui.button.UiType;

public class DatePickerMonthNavigator extends FlowPanel implements ClickHandler, DateSelectListener, HasDateSelectHandlers {

	private FlowPanel topPanel = new FlowPanel();

	private FlowPanel itemsPanel = new FlowPanel();

	private DatePickerMonthPanel datapanel = null;

	private final Label prev = new Label();

	private final Label next = new Label();

	private Label current = new Label("");

	private List toAdd = new ArrayList();

	private final UiType type;

	public DatePickerMonthNavigator(DatePickerRenderer renderer, UiType newType) {
		super();

		FlowPanel navigator = new FlowPanel();
		navigator.getElement().getStyle().setHeight(10, Unit.PCT);
		super.add(navigator);
		type = newType;

		datapanel = new DatePickerMonthPanel(renderer);
		datapanel.getElement().getStyle().setHeight(90, Unit.PCT);
		super.add(datapanel);

		SimplePanel wrapperPrev = new SimplePanel(prev);
		SimplePanel wrapperNext = new SimplePanel(next);
		wrapperPrev.addStyleName("arrow-w");
		wrapperNext.addStyleName("arrow-e");
		wrapperNext.addStyleName("next");
		wrapperPrev.addStyleName("prev");

		wrapperPrev.getElement().getStyle().setFloat(Float.LEFT);
		wrapperNext.getElement().getStyle().setFloat(Float.RIGHT);
		navigator.add(wrapperPrev);
		navigator.add(wrapperNext);
		navigator.add(current);
		current.getElement().getStyle().setTextAlign(TextAlign.CENTER);
		super.setStyleName(FtrGwtDatePickerCss.MONTH_SELECT);
		navigator.setStyleName(FtrGwtDatePickerCss.MONTH_NAV);
		// navigator.setHeight("18px");
		if (UiType.Touch.equals(type)) {
			navigator.addStyleName("touch");
		} else {

		}

		// super.setCellHeight(navigator, "18px");

		datapanel.addDateSelectEventHandler(this);
		next.addClickHandler(this);
		prev.addClickHandler(this);
		current.addClickHandler(this);
		prev.addStyleName(FtrGwtDatePickerCss.IMAGE_BUTTON);
		next.addStyleName(FtrGwtDatePickerCss.IMAGE_BUTTON);

		current.setText(datapanel.getDisplayText());
	}

	public void addWidgetToPicker(Widget newWidget) {
		if (toAdd.isEmpty()) {
			super.add(topPanel);
			topPanel.add(itemsPanel);
		}
		toAdd.add(newWidget);
		itemsPanel.add(newWidget);
		if (newWidget instanceof HasDateSelectHandlers) {
			HasDateSelectHandlers real = (HasDateSelectHandlers) newWidget;
			real.addDateSelectEventHandler(this);
		}
	};

	public Date getFirstDateShow() {
		return datapanel.getFirstDateShow();
	}

	public void rebuildPanel() {
		datapanel.buildPanel();
	}

	public Date getLastDateShow() {
		return datapanel.getLastDateShow();
	}

	public void setSelectedDate(Date newDate) {
		datapanel.setSelectedDate(newDate);
		current.setText(datapanel.getDisplayText());
	}

	public void onClick(ClickEvent event) {
		if (event.getSource() == prev) {
			datapanel.prev();
			current.setText(datapanel.getDisplayText());
			DateSelectEvent.fire(this, datapanel.getCurrent(), DateSelectEventActions.NAVIGATE_MONTH);
		}

		if (event.getSource() == next) {
			datapanel.next();
			current.setText(datapanel.getDisplayText());
			DateSelectEvent.fire(this, datapanel.getCurrent(), DateSelectEventActions.NAVIGATE_MONTH);
		}
		if (event.getSource() == current) {
			DateSelectEvent.fire(this, datapanel.getCurrent(), DateSelectEventActions.SELECT_NEW_MONTH);
		}

	}

	public Date getSelected() {
		return datapanel.getCurrent();
	}

	public void handleDateSelectEvent(DateSelectEvent newEvent) {
		if (newEvent.getSource() == datapanel) {

		} else {
			setSelectedDate(newEvent.getDate());
		}
		DateSelectEvent.fire(this, newEvent.getDate(), newEvent.getCommand());

	}

	public HandlerRegistration addDateSelectEventHandler(DateSelectListener handler) {
		return addHandler(handler, DateSelectEvent.getType());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy