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

com.googlecode.wicket.kendo.ui.form.datetime.TimePicker Maven / Gradle / Ivy

There is a newer version: 10.0.0-M1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.wicket.kendo.ui.form.datetime;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.model.IModel;

import com.googlecode.wicket.jquery.core.IJQueryWidget;
import com.googlecode.wicket.jquery.core.JQueryBehavior;
import com.googlecode.wicket.jquery.core.Options;
import com.googlecode.wicket.jquery.core.utils.LocaleUtils;
import com.googlecode.wicket.kendo.ui.KendoAbstractBehavior;
import com.googlecode.wicket.kendo.ui.utils.KendoDateTimeUtils;

/**
 * Provides a Kendo UI time-picker
* It should be created on a HTML <input type="text" /> element * * @author Sebastien Briquet - sebfz1 */ public class TimePicker extends DateTextField implements IJQueryWidget { private static final long serialVersionUID = 1L; protected static final String METHOD = "kendoTimePicker"; protected static final String DEFAULT_PATTERN = "h:mm aa"; // default java time pattern Options options; /** * Constructor * @param id the markup id */ public TimePicker(String id) { this(id, DEFAULT_PATTERN, new Options()); } /** * Constructor * @param id the markup id * @param options {@link Options} */ public TimePicker(String id, Options options) { this(id, DEFAULT_PATTERN, options); } /** * Constructor * @param id the markup id * @param pattern a SimpleDateFormat pattern */ public TimePicker(String id, String pattern) { this(id, pattern, new Options()); } /** * Main constructor * @param id the markup id * @param pattern a SimpleDateFormat pattern * @param options {@link Options} */ public TimePicker(String id, String pattern, Options options) { super(id, pattern); this.options = options; } /** * Constructor, which use {@link Locale} and Kengo UI Globalization * @param id the markup id * @param locale the {@link Locale} */ public TimePicker(String id, Locale locale) { this(id, locale, new Options()); } /** * Constructor, which use {@link Locale} and Kengo UI Globalization * @param id the markup id * @param locale the {@link Locale} * @param options the {@link Options} */ public TimePicker(String id, Locale locale, Options options) { this(id, LocaleUtils.getLocaleTimePattern(locale, DEFAULT_PATTERN), options.set("culture", Options.asString(LocaleUtils.getLangageCode(locale)))); } /** * Constructor * @param id the markup id * @param model the {@link IModel} */ public TimePicker(String id, IModel model) { this(id, model, DEFAULT_PATTERN, new Options()); } /** * Constructor * @param id the markup id * @param model the {@link IModel} * @param options {@link Options} */ public TimePicker(String id, IModel model, Options options) { this(id, model, DEFAULT_PATTERN, options); } /** * Constructor * @param id the markup id * @param model the {@link IModel} * @param pattern a SimpleDateFormat pattern */ public TimePicker(String id, IModel model, String pattern) { this(id, model, pattern, new Options()); } /** * Main constructor * @param id the markup id * @param model the {@link IModel} * @param pattern a SimpleDateFormat pattern. * @param options {@link Options} */ public TimePicker(String id, IModel model, String pattern, Options options) { super(id, model, pattern); this.options = options; } /** * Constructor, which use {@link Locale} and Kengo UI Globalization * @param id the markup id * @param model the {@link IModel} * @param locale the {@link Locale} */ public TimePicker(String id, IModel model, Locale locale) { this(id, model, locale, new Options()); } /** * Constructor, which use {@link Locale} and Kengo UI Globalization * @param id the markup id * @param model the {@link IModel} * @param locale the {@link Locale} * @param options the {@link Options} */ public TimePicker(String id, IModel model, Locale locale, Options options) { this(id, model, LocaleUtils.getLocaleTimePattern(locale, DEFAULT_PATTERN), options.set("culture", Options.asString(LocaleUtils.getLangageCode(locale)))); } // Getters // /** * Marked as final. * It is - probably - not consistent to have a pattern different from the display */ @Override public final String getTextFormat() { return super.getTextFormat(); } /** * Gets a string representation given the time pattern in use. * * @return the model object as string */ public String getModelObjectAsString() { Date date = this.getModelObject(); if (date != null) { return new SimpleDateFormat(this.getTextFormat()).format(date); } return ""; } // Events // @Override protected void onInitialize() { super.onInitialize(); this.add(JQueryWidget.newWidgetBehavior(this)); //cannot be in ctor as the markupId may be set manually afterward } @Override public void onConfigure(JQueryBehavior behavior) { if (behavior.getOption("format") == null) { behavior.setOption("format", Options.asString(KendoDateTimeUtils.toPattern(this.getTextFormat()))); } } @Override public void onBeforeRender(JQueryBehavior behavior) { // noop } // IJQueryWidget // @Override public JQueryBehavior newWidgetBehavior(String selector) { return new KendoAbstractBehavior(selector, TimePicker.METHOD, this.options); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy