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

com.premiumminds.webapp.wicket.bootstrap.BootstrapDatepicker Maven / Gradle / Ivy

/**
 * Copyright (C) 2014 Premium Minds.
 *
 * This file is part of pm-wicket-utils.
 *
 * pm-wicket-utils is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * pm-wicket-utils is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with pm-wicket-utils. If not, see .
 */
package com.premiumminds.webapp.wicket.bootstrap;

import java.util.Collection;
import java.util.Date;

import org.apache.wicket.Component;
import org.apache.wicket.IGenericComponent;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;

import com.premiumminds.webapp.wicket.bootstrap.datepicker.BootstrapDatePickerBehaviour;

/**
 * Bootstrap Datepicker for Wicket.
 *
 * @author acamilo
 * @see https://github.com/eternicode/bootstrap-datepicker
 */
public class BootstrapDatepicker extends WebMarkupContainer implements IGenericComponent {
	private static final long serialVersionUID = -117683073963817461L;

	private DateTextField dateField;
	
	/**
	 * Instantiates a new bootstrap datepicker.
	 *
	 * @param id the wicket:id
	 */
	public BootstrapDatepicker(String id) {
		super(id);
		add(new BootstrapDatePickerBehaviour() {
			private static final long serialVersionUID = 1L;
		
			@Override
			public Collection getSpecialDates() {
				return BootstrapDatepicker.this.getSpecialDates();
			}
		});
	}
	
	/* (non-Javadoc)
	 * @see org.apache.wicket.Component#onConfigure()
	 */
	@Override
	protected void onConfigure() {
		super.onConfigure();
		
		dateField = getDateTextField();
	}
	
	/* (non-Javadoc)
	 * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
	 */
	@Override
	protected void onComponentTag(ComponentTag tag) {
		super.onComponentTag(tag);
		
		if(dateField!=null){
			tag.put("data-date-format", dateField.getTextFormat().toLowerCase());
		}
	}

	/**
	 * Gets the DateTextField inside this datepicker wrapper.
	 *
	 * @return the date field
	 */
	public DateTextField getDateTextField(){
		for(Component component : visitChildren(DateTextField.class)){
			return (DateTextField) component;
		}
		throw new WicketRuntimeException("BootstrapDatepicker didn't have any DateTextField child!");
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.IGenericComponent#getModel()
	 */
	@Override
	public IModel getModel() {
		return getDateTextField().getModel();
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.IGenericComponent#setModel(org.apache.wicket.model.IModel)
	 */
	@Override
	public void setModel(IModel model) {
		getDateTextField().setModel(model);
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.IGenericComponent#setModelObject(java.lang.Object)
	 */
	@Override
	public void setModelObject(Date object) {
		getDateTextField().setModelObject(object);
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.IGenericComponent#getModelObject()
	 */
	@Override
	public Date getModelObject() {
		return getDateTextField().getModelObject();
	}
	
	
	/**
	 * Gets the special dates for this datepicker
	 *
	 * @return a collection with the special dates
	 */
	public Collection getSpecialDates() {
		return null;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy