http://git-wip-us.apache.org/repos/asf/wicket/blob/2bb684c1/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java ---------------------------------------------------------------------- diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java deleted file mode 100644 index 6b09e7a..0000000 --- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java +++ /dev/null @@ -1,890 +0,0 @@ -/* - * 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 org.apache.wicket.extensions.yui.calendar; - -import java.text.DateFormatSymbols; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.wicket.Application; -import org.apache.wicket.Component; -import org.apache.wicket.WicketRuntimeException; -import org.apache.wicket.ajax.AjaxEventBehavior; -import org.apache.wicket.behavior.Behavior; -import org.apache.wicket.core.request.handler.IPartialPageRequestHandler; -import org.apache.wicket.datetime.markup.html.form.DateTextField; -import org.apache.wicket.extensions.yui.YuiLib; -import org.apache.wicket.markup.head.IHeaderResponse; -import org.apache.wicket.markup.head.OnDomReadyHeaderItem; -import org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider; -import org.apache.wicket.request.Response; -import org.apache.wicket.request.cycle.RequestCycle; -import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler; -import org.apache.wicket.request.resource.JavaScriptResourceReference; -import org.apache.wicket.request.resource.PackageResourceReference; -import org.apache.wicket.request.resource.ResourceReference; -import org.apache.wicket.util.convert.IConverter; -import org.apache.wicket.util.convert.converter.DateConverter; -import org.apache.wicket.util.lang.Objects; -import org.apache.wicket.util.string.Strings; -import org.apache.wicket.util.template.PackageTextTemplate; -import org.apache.wicket.util.template.TextTemplate; -import org.joda.time.DateTime; - -/** - * Pops up a YUI calendar component so that the user can select a date. On selection, the date is - * set in the component it is coupled to, after which the popup is closed again. This behavior can - * only be used with components that either implement {@link ITextFormatProvider} or that use - * {@link DateConverter} configured with an instance of {@link SimpleDateFormat} (like Wicket's - * default configuration has).<br/> - * - * To use, simply add a new instance to your component, which would typically a TextField, like - * {@link DateTextField}.<br/> - * - * The CalendarNavigator can be configured by overriding {@link #configure(java.util.Map, org.apache.wicket.markup.head.IHeaderResponse, java.util.Map)} and setting the - * property or by returning <code>true</code> for {@link #enableMonthYearSelection()}. - * - * @see <a - * href="http://developer.yahoo.com/yui/calendar/">http://developer.yahoo.com/yui/calendar/</a> - * - * @author eelcohillenius - */ -public class DatePicker extends Behavior -{ - - /** - * Exception thrown when the bound component does not produce a format this date picker can work - * with. - */ - private static final class UnableToDetermineFormatException extends WicketRuntimeException - { - private static final long serialVersionUID = 1L; - - public UnableToDetermineFormatException() - { - super("This behavior can only be added to components that either implement " + - ITextFormatProvider.class.getName() + - " AND produce a non-null format, or that use" + - " converters that this DatePicker can use to determine" + - " the pattern being used. Alternatively, you can extend " + - " the DatePicker and override getDatePattern to provide your own."); - } - } - - /** - * Format to be used when configuring YUI calendar. Can be used when using the - * "selected" property. - */ - // See wicket-1988: SimpleDateFormat is not thread safe. Do not use static final - // See wicket-2525: SimpleDateFormat consumes a lot of memory - public static String FORMAT_DATE = "MM/dd/yyyy"; - - /** - * For specifying which page (month/year) to show in the calendar, use this format for the date. - * This is to be used together with the property "pagedate" - */ - // See wicket-1988: SimpleDateFormat is not thread safe. Do not use static final - // See wicket-2525: SimpleDateFormat consumes a lot of memory - public static String FORMAT_PAGEDATE = "MM/yyyy"; - - private static final ResourceReference YUI = new JavaScriptResourceReference(YuiLib.class, ""); - - private static final ResourceReference WICKET_DATE = new JavaScriptResourceReference( - DatePicker.class, "wicket-date.js"); - - private static final long serialVersionUID = 1L; - - /** The target component. */ - private Component component; - - private boolean showOnFieldClick = false; - - /** - * A setting that decides whether to close the date picker when the user clicks somewhere else - * on the document. - */ - private boolean autoHide = false; - - /** - * The string to use for the close button label. - */ - private String closeLabel = ""; - - /** - * Construct. - */ - public DatePicker() - { - } - - /** - * {@inheritDoc} - */ - @Override - public void bind(final Component component) - { - this.component = component; - checkComponentProvidesDateFormat(component); - component.setOutputMarkupId(true); - } - - /** - * {@inheritDoc} - */ - @Override - public void afterRender(final Component component) - { - super.afterRender(component); - - // Append the span and img icon right after the rendering of the - // component. Not as pretty as working with a panel etc, but works - // for behaviors and is more efficient - Response response = component.getResponse(); - response.write("\n<span class=\"yui-skin-sam\"> <span style=\""); - - if (renderOnLoad()) - { - response.write("display:block;"); - } - else - { - response.write("display:none;"); - response.write("position:absolute;"); - } - - response.write("z-index: 99999;\" id=\""); - response.write(getEscapedComponentMarkupId()); - response.write("Dp\"></span><img style=\""); - response.write(getIconStyle()); - response.write("\" id=\""); - response.write(getIconId()); - response.write("\" src=\""); - CharSequence iconUrl = getIconUrl(); - response.write(Strings.escapeMarkup(iconUrl != null ? iconUrl.toString() : "")); - response.write("\" alt=\""); - CharSequence alt = getIconAltText(); - response.write(Strings.escapeMarkup((alt != null) ? alt.toString() : "")); - response.write("\" title=\""); - CharSequence title = getIconTitle(); - response.write(Strings.escapeMarkup((title != null) ? title.toString() : "")); - response.write("\"/>"); - - if (renderOnLoad()) - { - response.write("<br style=\"clear:left;\"/>"); - } - response.write("</span>"); - } - - /** - * Controls whether or not datepicker will contribute YUI libraries to the page as part of its - * rendering lifecycle. - * - * There may be cases when the user wants to use their own version of YUI contribution code, in - * those cases this method should be overridden to return <code>false</code>. - * - * @return a flag whether to contribute YUI libraries to the page. {@code true} by default. - */ - protected boolean includeYUILibraries() - { - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public void renderHead(Component component, IHeaderResponse response) - { - super.renderHead(component, response); - - if (includeYUILibraries()) - { - YuiLib.load(response); - } - - renderHeadInit(response); - - // variables for the initialization script - Map<String, Object> variables = new HashMap<>(); - String widgetId = getEscapedComponentMarkupId(); - variables.put("componentId", getComponentMarkupId()); - variables.put("widgetId", widgetId); - variables.put("datePattern", getDatePattern()); - variables.put("fireChangeEvent", notifyComponentOnDateSelected()); - variables.put("alignWithIcon", alignWithIcon()); - variables.put("hideOnSelect", hideOnSelect()); - variables.put("showOnFieldClick", showOnFieldClick()); - variables.put("autoHide", autoHide()); - variables.put("closeLabel", closeLabel()); - - String script = getAdditionalJavaScript(); - if (script != null) - { - variables.put("additionalJavascript", - Strings.replaceAll(script, "${calendar}", "YAHOO.wicket." + widgetId + "DpJs")); - } - - // print out the initialization properties - Map<String, Object> p = new LinkedHashMap<>(); - configure(p, response, variables); - if (!p.containsKey("navigator") && enableMonthYearSelection()) - { - p.put("navigator", Boolean.TRUE); - } - - if (enableMonthYearSelection() && p.containsKey("pages") && - Objects.longValue(p.get("pages")) > 1) - { - throw new IllegalStateException( - "You cannot use a CalendarGroup with month/year selection!"); - } - - // ${calendarInit} - StringBuilder calendarInit = new StringBuilder(); - appendMapping(p, calendarInit); - variables.put("calendarInit", calendarInit.toString()); - - // render initialization script with the variables interpolated - TextTemplate datePickerJs = new PackageTextTemplate(DatePicker.class, "DatePicker.js"); - datePickerJs.interpolate(variables); - response.render(OnDomReadyHeaderItem.forScript(datePickerJs.asString())); - - // remove previously generated markup (see onRendered) via javascript in - // ajax requests to not render the yui calendar multiple times - component.getRequestCycle().find(IPartialPageRequestHandler.class).ifPresent(target -> { - String escapedComponentMarkupId = getEscapedComponentMarkupId(); - String javascript = "var e = Wicket.$('" + escapedComponentMarkupId + "Dp" + - "'); if (e != null && typeof(e.parentNode) != 'undefined' && " + - "typeof(e.parentNode.parentNode != 'undefined')) {" + - "e.parentNode.parentNode.removeChild(e.parentNode);" + "YAHOO.wicket." + - escapedComponentMarkupId + "DpJs.destroy(); delete YAHOO.wicket." + - escapedComponentMarkupId + "DpJs;}"; - - target.prependJavaScript(javascript); - }); - } - - /** - * Renders yui & wicket calendar js module loading. It is done only once per page. - * - * @param response - * header response - */ - protected void renderHeadInit(IHeaderResponse response) - { - String key = "DatePickerInit.js"; - if (response.wasRendered(key)) - { - return; - } - - // variables for YUILoader - Map<String, Object> variables = new HashMap<>(); - variables.put("basePath", - Strings.stripJSessionId(RequestCycle.get().urlFor(YUI, null).toString()) + "/"); - variables.put("Wicket.DateTimeInit.DatePath", RequestCycle.get().urlFor(WICKET_DATE, null)); - - if (Application.get().usesDevelopmentConfig()) - { - variables.put("filter", "filter: \"RAW\","); - variables.put("allowRollup", false); - } - else - { - variables.put("filter", ""); - variables.put("allowRollup", true); - } - - TextTemplate template = new PackageTextTemplate(DatePicker.class, key); - response.render(OnDomReadyHeaderItem.forScript(template.asString(variables))); - - response.markRendered(key); - } - - /** - * Check that this behavior can get a date format out of the component it is coupled to. It - * checks whether {@link #getDatePattern()} produces a non-null value. If that method returns - * null, and exception will be thrown - * - * @param component - * the component this behavior is being coupled to - * @throws UnableToDetermineFormatException - * if this date picker is unable to determine a format. - */ - private void checkComponentProvidesDateFormat(final Component component) - { - if (getDatePattern() == null) - { - throw new UnableToDetermineFormatException(); - } - } - - /** - * Set widget property if the array is null and has a length greater than 0. - * - * @param widgetProperties - * @param key - * @param array - */ - private void setWidgetProperty(final Map<String, Object> widgetProperties, final String key, - final String[] array) - { - if (array != null && array.length > 0) - { - widgetProperties.put(key, array); - } - } - - /** - * Whether to position the date picker relative to the trigger icon. - * - * @return If true, the date picker is aligned with the left position of the icon, and with the - * top right under. If false, the date picker will skip positioning and will let you do - * the positioning yourself. Returns true by default. - */ - protected boolean alignWithIcon() - { - return true; - } - - /** - * Gives overriding classes the option of adding (or even changing/ removing) configuration - * properties for the javascript widget. See <a - * href="http://developer.yahoo.com/yui/calendar/">the widget's documentation</a> for the - * available options. If you want to override/ remove properties, you should call - * super.configure(properties) first. If you don't call that, be aware that you will have to - * call {@link #localize(java.util.Map, org.apache.wicket.markup.head.IHeaderResponse, java.util.Map)} manually if you like localized strings to be added. - * - * @param widgetProperties - * the current widget properties - * @param response - * the header response - * @param initVariables - * variables passed to the Wicket.DateTime.init() js method - */ - protected void configure(final Map<String, Object> widgetProperties, - final IHeaderResponse response, final Map<String, Object> initVariables) - { - widgetProperties.put("close", true); - - // localize date fields - localize(widgetProperties, response, initVariables); - - Object modelObject = component.getDefaultModelObject(); - // null and cast check - if (modelObject instanceof Date) - { - Date date = (Date)modelObject; - widgetProperties.put("selected", new SimpleDateFormat(FORMAT_DATE).format(date)); - widgetProperties.put("pagedate", new SimpleDateFormat(FORMAT_PAGEDATE).format(date)); - } - } - - /** - * Filter all empty elements (workaround for {@link DateFormatSymbols} returning arrays with - * empty elements). - * - * @param stringArray - * array to filter - * @return filtered array (without null or empty string elements) - */ - protected final String[] filterEmpty(String[] stringArray) - { - if (stringArray == null) - { - return null; - } - - List<String> list = new ArrayList<>(stringArray.length); - for (String string : stringArray) - { - if (!Strings.isEmpty(string)) - { - list.add(string); - } - } - return list.toArray(new String[list.size()]); - } - - /** - * Gets the id of the component that the calendar widget will get attached to. - * - * @return The DOM id of the component - */ - protected final String getComponentMarkupId() - { - return component.getMarkupId(); - } - - /** - * Gets the date pattern to use for putting selected values in the coupled component. - * - * @return The date pattern - */ - protected String getDatePattern() - { - String format = null; - if (component instanceof ITextFormatProvider) - { - format = ((ITextFormatProvider)component).getTextFormat(); - // it is possible that components implement ITextFormatProvider but - // don't provide a format - } - - if (format == null) - { - IConverter<?> converter = component.getConverter(DateTime.class); - if (!(converter instanceof DateConverter)) - { - converter = component.getConverter(Date.class); - } - format = ((SimpleDateFormat)((DateConverter)converter).getDateFormat(component.getLocale())).toPattern(); - } - - return format; - } - - /** - * Gets the escaped DOM id that the calendar widget will get attached to. All non word - * characters (\W) will be removed from the string. - * - * @return The DOM id of the calendar widget - same as the component's markup id + 'Dp'} - */ - protected final String getEscapedComponentMarkupId() - { - return component.getMarkupId().replaceAll("\\W", ""); - } - - /** - * Gets the id of the icon that triggers the popup. - * - * @return The id of the icon - */ - protected final String getIconId() - { - return getEscapedComponentMarkupId() + "Icon"; - } - - /** - * Gets the style of the icon that triggers the popup. - * - * @return The style of the icon, e.g. 'cursor: point' etc. - */ - protected String getIconStyle() - { - return "cursor: pointer; border: none;"; - } - - /** - * Gets the title attribute of the datepicker icon - * - * @return text - */ - protected CharSequence getIconTitle() - { - return ""; - } - - /** - * Gets the icon alt text for the datepicker icon - * - * @return text - */ - protected CharSequence getIconAltText() - { - return ""; - } - - /** - * Gets the url for the popup button. Users can override to provide their own icon URL. - * - * @return the url to use for the popup button/ icon - */ - protected CharSequence getIconUrl() - { - return RequestCycle.get().urlFor( - new ResourceReferenceRequestHandler(new PackageResourceReference(DatePicker.class, - "icon1.gif"))); - } - - /** - * Gets the locale that should be used to configure this widget. - * - * @return By default the locale of the bound component. - */ - protected Locale getLocale() - { - return component.getLocale(); - } - - /** - * Configure the localized strings for the datepicker widget. This implementation uses - * {@link DateFormatSymbols} and some slight string manipulation to get the strings for months - * and week days. Also, the first week day is set according to the {@link Locale} returned by - * {@link #getLocale()}. It should work well for most locales. - * <p> - * This method is called from {@link #configure(java.util.Map, org.apache.wicket.markup.head.IHeaderResponse, java.util.Map)} and can be overridden if - * you want to customize setting up the localized strings but are happy with the rest of - * {@link #configure(java.util.Map, org.apache.wicket.markup.head.IHeaderResponse, java.util.Map)}'s behavior. Note that you can call (overridable) - * method {@link #getLocale()} to get the locale that should be used for setting up the widget. - * </p> - * <p> - * See YUI Calendar's <a href="http://developer.yahoo.com/yui/examples/calendar/germany/1.html"> - * German</a> and <a - * href="http://developer.yahoo.com/yui/examples/calendar/japan/1.html">Japanese</a> examples - * for more info. - * </p> - * - * @param widgetProperties - * the current widget properties - * @param response - * the header response - * @param initVariables - * variables passed to the Wicket.DateTime.init() js method - */ - protected void localize(Map<String, Object> widgetProperties, IHeaderResponse response, - Map<String, Object> initVariables) - { - Locale locale = getLocale(); - String key = "Wicket.DateTimeInit.CalendarI18n[\"" + locale.toString() + "\"]"; - initVariables.put("i18n", key); - - if (response.wasRendered(key)) - { - return; - } - - DateFormatSymbols dfSymbols = DateFormatSymbols.getInstance(locale); - if (dfSymbols == null) - { - dfSymbols = new DateFormatSymbols(locale); - } - - Map<String, Object> i18nVariables = new LinkedHashMap<>(); - setWidgetProperty(i18nVariables, "MONTHS_SHORT", filterEmpty(dfSymbols.getShortMonths())); - setWidgetProperty(i18nVariables, "MONTHS_LONG", filterEmpty(dfSymbols.getMonths())); - setWidgetProperty(i18nVariables, "WEEKDAYS_MEDIUM", - filterEmpty(dfSymbols.getShortWeekdays())); - setWidgetProperty(i18nVariables, "WEEKDAYS_LONG", filterEmpty(dfSymbols.getWeekdays())); - - i18nVariables.put("START_WEEKDAY", getFirstDayOfWeek(locale)); - - if (Locale.SIMPLIFIED_CHINESE.equals(locale) || Locale.TRADITIONAL_CHINESE.equals(locale)) - { - setWidgetProperty(i18nVariables, "WEEKDAYS_1CHAR", - filterEmpty(substring(dfSymbols.getShortWeekdays(), 2, 1))); - i18nVariables.put("WEEKDAYS_SHORT", - filterEmpty(substring(dfSymbols.getShortWeekdays(), 2, 1))); - } - else - { - setWidgetProperty(i18nVariables, "WEEKDAYS_1CHAR", - filterEmpty(substring(dfSymbols.getShortWeekdays(), 0, 1))); - setWidgetProperty(i18nVariables, "WEEKDAYS_SHORT", - filterEmpty(substring(dfSymbols.getShortWeekdays(), 0, 2))); - } - - StringBuilder i18n = new StringBuilder(key); - i18n.append('='); - appendMapping(i18nVariables, i18n); - i18n.append(';'); - - response.render(OnDomReadyHeaderItem.forScript(i18n.toString())); - - response.wasRendered(key); - } - - /** - * Gets the first day of week of a given locale. - * - * @return By default the first day of week accordingly to Calendar class. - */ - protected int getFirstDayOfWeek(Locale locale) - { - return Calendar.getInstance(locale).getFirstDayOfWeek() - 1; - } - - /** - * Whether to notify the associated component when a date is selected. Notifying is done by - * calling the associated component's onchange JavaScript event handler. You can for instance - * attach an {@link AjaxEventBehavior} to that component to get a call back to the server. The - * default is true. - * - * @return if true, notifies the associated component when a date is selected - */ - protected boolean notifyComponentOnDateSelected() - { - return true; - } - - /** - * Makes a copy of the provided array and for each element copy the substring 0..len to the new - * array - * - * @param array - * array to copy from - * @param len - * size of substring for each element to copy - * @return copy of the array filled with substrings. - */ - protected final String[] substring(final String[] array, final int len) - { - return substring(array, 0, len); - } - - /** - * Makes a copy of the provided array and for each element copy the substring 0..len to the new - * array - * - * @param array - * array to copy from - * @param start - * start position of the substring - * @param len - * size of substring for each element to copy - * @return copy of the array filled with substrings. - */ - protected final String[] substring(final String[] array, final int start, final int len) - { - if (array != null) - { - String[] copy = new String[array.length]; - for (int i = 0; i < array.length; i++) - { - String el = array[i]; - if (el != null) - { - if (el.length() > (start + len)) - { - copy[i] = el.substring(start, start + len); - } - else - { - copy[i] = el; - } - } - } - return copy; - } - return null; - } - - /** - * Indicates whether plain text is rendered or two select boxes are used to allow direct - * selection of month and year. - * - * @return <code>true</code> if select boxes should be rendered to allow month and year - * selection.<br/> - * <code>false</code> to render just plain text. - */ - protected boolean enableMonthYearSelection() - { - return false; - } - - /** - * Indicates whether the calendar should be hidden after a date was selected. - * - * @return <code>true</code> (default) if the calendar should be hidden after the date selection <br/> - * <code>false</code> if the calendar should remain visible after the date selection. - */ - protected boolean hideOnSelect() - { - return true; - } - - /** - * Indicates whether the calendar should be shown when corresponding text input is clicked. - * - * @return <code>true</code> <br/> - * <code>false</code> (default) - */ - protected boolean showOnFieldClick() - { - return showOnFieldClick; - } - - /** - * @param show - * a flag indicating whether to show the picker on click event - * @return {@code this} instance to be able to chain calls - * @see {@link #showOnFieldClick()} - */ - public DatePicker setShowOnFieldClick(boolean show) - { - showOnFieldClick = show; - return this; - } - - - /** - * Indicates whether the calendar should be hidden when the user clicks on an area of the - * document outside of the dialog. - * - * @return <code>true</code> <br/> - * <code>false</code> (default) - */ - protected boolean autoHide() - { - return autoHide; - } - - /** - * @param autoHide - * a flag indicating whether to hide the picker on click event - * @return {@code this} instance to be able to chain calls - * @see {@link #autoHide()} - */ - public DatePicker setAutoHide(boolean autoHide) - { - this.autoHide = autoHide; - return this; - } - - /** - * The string to use for the close button label. - * - * @return label - */ - protected String closeLabel() - { - return closeLabel; - } - - /** - * @param closeLabel - * The string to use for the close button label. - */ - public void setCloseLabel(String closeLabel) - { - this.closeLabel = closeLabel; - } - - /** - * Indicates whether the calendar should be rendered after it has been loaded. - * - * @return <code>true</code> if the calendar should be rendered after it has been loaded.<br/> - * <code>false</code> (default) if it's initially hidden. - */ - protected boolean renderOnLoad() - { - return false; - } - - /** - * Override this method to further customize the YUI Calendar with additional JavaScript code. - * The code returned by this method is executed right after the Calendar has been constructed - * and initialized. To refer to the actual Calendar DOM object, use <code>${calendar}</code> in - * your code.<br/> - * See <a href="http://developer.yahoo.com/yui/calendar/">the widget's documentation</a> for - * more information about the YUI Calendar.<br/> - * Example: - * - * <pre> - * protected String getAdditionalJavaScript() - * { - * return "${calendar}.addRenderer(\"10/3\", ${calendar}.renderCellStyleHighlight1);"; - * } - * </pre> - * - * @return a String containing additional JavaScript code - */ - protected String getAdditionalJavaScript() - { - return ""; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isEnabled(final Component component) - { - return component.isEnabledInHierarchy(); - } - - /** - * - * @param map - * the key-value pairs to be serialized - * @param json - * the buffer holding the constructed json - */ - private void appendMapping(final Map<String, Object> map, final StringBuilder json) - { - json.append('{'); - for (Iterator<Entry<String, Object>> i = map.entrySet().iterator(); i.hasNext();) - { - Entry<String, Object> entry = i.next(); - json.append(entry.getKey()); - Object value = entry.getValue(); - if (value instanceof CharSequence) - { - json.append(":\""); - json.append(Strings.toEscapedUnicode(value.toString())); - json.append('"'); - } - else if (value instanceof CharSequence[]) - { - json.append(":["); - CharSequence[] valueArray = (CharSequence[])value; - for (int j = 0; j < valueArray.length; j++) - { - CharSequence tmpValue = valueArray[j]; - if (j > 0) - { - json.append(','); - } - if (tmpValue != null) - { - json.append('"'); - json.append(Strings.toEscapedUnicode(tmpValue.toString())); - json.append('"'); - } - } - json.append(']'); - } - else if (value instanceof Map) - { - json.append(':'); - @SuppressWarnings("unchecked") - Map<String, Object> nmap = (Map<String, Object>)value; - appendMapping(nmap, json); - } - else - { - json.append(':'); - json.append(Strings.toEscapedUnicode(String.valueOf(value))); - } - if (i.hasNext()) - { - json.append(','); - } - } - json.append('}'); - } -}
http://git-wip-us.apache.org/repos/asf/wicket/blob/2bb684c1/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.js ---------------------------------------------------------------------- diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.js b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.js deleted file mode 100644 index e40e0c2..0000000 --- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.js +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ -Wicket.DateTimeInit.CalendarAdd(function() { - Wicket.DateTime.init2("${widgetId}", "${componentId}", ${calendarInit}, "${datePattern}", - ${alignWithIcon}, ${fireChangeEvent}, ${hideOnSelect}, ${showOnFieldClick}, ${i18n}, ${autoHide}, "${closeLabel}"); - ${additionalJavascript} -}); http://git-wip-us.apache.org/repos/asf/wicket/blob/2bb684c1/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePickerInit.js ---------------------------------------------------------------------- diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePickerInit.js b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePickerInit.js deleted file mode 100644 index 61b4056..0000000 --- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePickerInit.js +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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. - */ -if (typeof(Wicket) === 'undefined') { - window.Wicket = {}; -} -if (typeof(Wicket.DateTimeInit) === 'undefined') { - Wicket.DateTimeInit = {}; -} - -Wicket.DateTimeInit.CalendarInits = []; -Wicket.DateTimeInit.CalendarInitFinished = false; -Wicket.DateTimeInit.CalendarI18n = {}; -Wicket.DateTimeInit.CalendarAdd = function(initFn) { - if (Wicket.DateTimeInit.CalendarInitFinished) { - // when a DatePicker is added via ajax, the loader is already finished, so - // we call the init function directly. - initFn(); - } else { - // when page is rendered, all calendar components will be initialized after - // the required js libraries have been loaded. - Wicket.DateTimeInit.CalendarInits.push(initFn); - } -}; - -Wicket.DateTimeInit.YuiLoader = new YAHOO.util.YUILoader({ - base: "${basePath}", - ${filter} - allowRollup: ${allowRollup}, - require: ["wicket-date"], - onSuccess: function() { - Wicket.DateTimeInit.CalendarInitFinished = true; - while (Wicket.DateTimeInit.CalendarInits.length > 0) { - Wicket.DateTimeInit.CalendarInits.pop()(); - } - } -}); -Wicket.DateTimeInit.YuiLoader.addModule({ - name: "wicket-date", - type: "js", - requires: ["calendar"], - fullpath: "${Wicket.DateTimeInit.DatePath}" -}); -Wicket.DateTimeInit.YuiLoader.insert(); http://git-wip-us.apache.org/repos/asf/wicket/blob/2bb684c1/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.html ---------------------------------------------------------------------- diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.html b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.html deleted file mode 100644 index c714db3..0000000 --- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.html +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - 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. ---> -<wicket:panel xmlns:wicket="http://wicket.apache.org"> - <span style="white-space: nowrap;"> - <input type="text" wicket:id="date" size="12" /> - <input type="text" wicket:id="hours" size="2" maxlength="2" /> - <span wicket:id="hoursSeparator"> :</span> - <input type="text" wicket:id="minutes" size="2" maxlength="2" /> - <select wicket:id="amOrPmChoice"></select> - </span> -</wicket:panel> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/2bb684c1/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java ---------------------------------------------------------------------- diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java deleted file mode 100644 index ecab7b6..0000000 --- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java +++ /dev/null @@ -1,616 +0,0 @@ -/* - * 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 org.apache.wicket.extensions.yui.calendar; - -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.Map; -import java.util.TimeZone; - -import org.apache.wicket.Session; -import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; -import org.apache.wicket.core.request.ClientInfo; -import org.apache.wicket.datetime.markup.html.form.DateTextField; -import org.apache.wicket.markup.head.IHeaderResponse; -import org.apache.wicket.markup.html.WebMarkupContainer; -import org.apache.wicket.markup.html.form.DropDownChoice; -import org.apache.wicket.markup.html.form.FormComponentPanel; -import org.apache.wicket.markup.html.form.TextField; -import org.apache.wicket.model.IModel; -import org.apache.wicket.model.Model; -import org.apache.wicket.model.PropertyModel; -import org.apache.wicket.protocol.http.request.WebClientInfo; -import org.apache.wicket.util.convert.IConverter; -import org.apache.wicket.util.convert.converter.IntegerConverter; -import org.apache.wicket.validation.validator.RangeValidator; -import org.joda.time.DateTimeFieldType; -import org.joda.time.DateTimeZone; -import org.joda.time.MutableDateTime; -import org.joda.time.format.DateTimeFormat; - -/** - * Works on a {@link java.util.Date} object. Displays a date field and a {@link DatePicker}, a field - * for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field - * depends on the time format of this {@link DateTimeField}'s {@link Locale}, as does the visibility - * of the AM/PM field (see {@link DateTimeField#use12HourFormat}). - * <p> - * <strong>Ajaxifying the DateTimeField</strong>: If you want to update a DateTimeField with an - * {@link AjaxFormComponentUpdatingBehavior}, you have to attach it to the contained - * {@link DateTextField} by overriding {@link #newDateTextField(String, PropertyModel)} and calling - * {@link #processInput()}: - * - * <pre>{@code - * DateTimeField dateTimeField = new DateTimeField(...) { - * protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel) - * { - * DateTextField dateField = super.newDateTextField(id, dateFieldModel); - * dateField.add(new AjaxFormComponentUpdatingBehavior("change") { - * protected void onUpdate(AjaxRequestTarget target) { - * processInput(); // let DateTimeField process input too - * - * ... - * } - * }); - * return recorder; - * } - * } - * }</pre> - * - * @author eelcohillenius - * @see DateField for a variant with just the date field and date picker - */ -public class DateTimeField extends FormComponentPanel<Date> -{ - /** - * Enumerated type for different ways of handling the render part of requests. - */ - public static enum AM_PM { - /** */ - AM("AM"), - - /** */ - PM("PM"); - - /** */ - private String value; - - AM_PM(final String name) - { - value = name; - } - - /** - * @see java.lang.Enum#toString() - */ - @Override - public String toString() - { - return value; - } - } - - private static final long serialVersionUID = 1L; - - // Component-IDs - protected static final String DATE = "date"; - protected static final String HOURS = "hours"; - protected static final String MINUTES = "minutes"; - protected static final String AM_OR_PM_CHOICE = "amOrPmChoice"; - - // PropertyModel string to access getAmOrPm - private static final String AM_OR_PM = "amOrPm"; - - private static final IConverter<Integer> MINUTES_CONVERTER = new IntegerConverter() { - protected NumberFormat newNumberFormat(Locale locale) { - return new DecimalFormat("00"); - } - }; - - // The dropdown list for AM/PM and it's associated model object - private DropDownChoice<AM_PM> amOrPmChoice; - private AM_PM amOrPm = AM_PM.AM; - - // The date TextField and it's associated model object - // Note that any time information in date will be ignored - private DateTextField dateField; - private Date date; - - // The TextField for "hours" and it's associated model object - private TextField<Integer> hoursField; - private Integer hours; - - // The TextField for "minutes" and it's associated model object - private TextField<Integer> minutesField; - private Integer minutes; - - /** - * Construct. - * - * @param id - */ - public DateTimeField(final String id) - { - this(id, null); - } - - /** - * Construct. - * - * @param id - * @param model - */ - public DateTimeField(final String id, final IModel<Date> model) - { - super(id, model); - - // Sets the type that will be used when updating the model for this component. - setType(Date.class); - - // Create and add the date TextField - PropertyModel<Date> dateFieldModel = new PropertyModel<>(this, DATE); - add(dateField = newDateTextField(DATE, dateFieldModel)); - - // Add a date picker to the date TextField - dateField.add(newDatePicker()); - - // Create and add the "hours" TextField - add(hoursField = newHoursTextField(HOURS, new PropertyModel<Integer>(this, HOURS), - Integer.class)); - - // Create and add the "minutes" TextField - add(minutesField = newMinutesTextField(MINUTES, new PropertyModel<Integer>(this, MINUTES), - Integer.class)); - - // Create and add the "AM/PM" Listbox - add(amOrPmChoice = new DropDownChoice<AM_PM>(AM_OR_PM_CHOICE, new PropertyModel<AM_PM>( - this, AM_OR_PM), Arrays.asList(AM_PM.values()))); - - add(new WebMarkupContainer("hoursSeparator") - { - private static final long serialVersionUID = 1L; - - @Override - public boolean isVisible() - { - return minutesField.determineVisibility(); - } - }); - } - - /** - * create a new {@link TextField} instance for hours to be added to this panel. - * - * @param id - * the component id - * @param model - * model that should be used by the {@link TextField} - * @param type - * the type of the text field - * @return a new text field instance - */ - protected TextField<Integer> newHoursTextField(final String id, IModel<Integer> model, Class<Integer> type) { - TextField<Integer> hoursTextField = new TextField<>(id, model, type); - hoursTextField.add(getMaximumHours() == 24 ? RangeValidator.range(0, 23) : RangeValidator - .range(1, 12)); - hoursTextField.setLabel(new Model<>(HOURS)); - return hoursTextField; - } - - /** - * create a new {@link TextField} instance for minutes to be added to this panel. - * - * @param id - * the component id - * @param model - * model that should be used by the {@link TextField} - * @param type - * the type of the text field - * @return a new text field instance - */ - protected TextField<Integer> newMinutesTextField(final String id, IModel<Integer> model, - Class<Integer> type) - { - TextField<Integer> minutesField = new TextField<Integer>(id, model, type) - { - private static final long serialVersionUID = 1L; - - @Override - protected IConverter<?> createConverter(Class<?> type) - { - if (Integer.class.isAssignableFrom(type)) - { - return MINUTES_CONVERTER; - } - return null; - } - }; - minutesField.add(new RangeValidator<>(0, 59)); - minutesField.setLabel(new Model<>(MINUTES)); - return minutesField; - } - - /** - * - * @return The date TextField - */ - protected final DateTextField getDateTextField() - { - return dateField; - } - - /** - * Gets the amOrPm model object of the drop down choice. - * - * @return amOrPm - * - * @deprecated valid during rendering only - */ - public final AM_PM getAmOrPm() - { - return amOrPm; - } - - /** - * Gets the date model object for the date TextField. Any associated time information will be - * ignored. - * - * @return date - * - * @deprecated valid during rendering only - */ - public final Date getDate() - { - return date; - } - - /** - * Gets the hours model object for the TextField - * - * @return hours - * - * @deprecated valid during rendering only - */ - public final Integer getHours() - { - return hours; - } - - /** - * Gets the minutes model object for the TextField - * - * @return minutes - * - * @deprecated valid during rendering only - */ - public final Integer getMinutes() - { - return minutes; - } - - /** - * Gives overriding classes the option of adding (or even changing/ removing) configuration - * properties for the javascript widget. See <a - * href="http://developer.yahoo.com/yui/calendar/">the widget's documentation</a> for the - * available options. If you want to override/ remove properties, you should call - * super.configure(properties) first. If you don't call that, be aware that you will have to - * call {@link #configure(java.util.Map)} manually if you like localized strings to be added. - * - * @param widgetProperties - * the current widget properties - */ - protected void configure(Map<String, Object> widgetProperties) - { - } - - @Override - public String getInput() - { - // since we override convertInput, we can let this method return a value - // that is just suitable for error reporting - return dateField.getInput() + ", " + hoursField.getInput() + ":" + minutesField.getInput(); - } - - /** - * Sets the amOrPm model object associated with the drop down choice. - * - * @param amOrPm - * amOrPm - */ - public final void setAmOrPm(final AM_PM amOrPm) - { - this.amOrPm = amOrPm; - } - - /** - * Sets the date model object associated with the date TextField. It does not affect hours or - * minutes. - * - * @param date - * date - */ - public final void setDate(final Date date) - { - this.date = date; - } - - /** - * Sets hours. - * - * @param hours - * hours - */ - public final void setHours(final Integer hours) - { - this.hours = hours; - } - - /** - * Sets minutes. - * - * @param minutes - * minutes - */ - public final void setMinutes(final Integer minutes) - { - this.minutes = minutes; - } - - /** - * Gets the client's time zone. - * - * @return The client's time zone or null - */ - protected TimeZone getClientTimeZone() - { - ClientInfo info = Session.get().getClientInfo(); - if (info instanceof WebClientInfo) - { - return ((WebClientInfo)info).getProperties().getTimeZone(); - } - return null; - } - - /** - * Sets the converted input, which is an instance of {@link Date}, possibly null. It combines - * the inputs of the nested date, hours, minutes and am/pm fields and constructs a date from it. - * <p> - * Note that overriding this method is a better option than overriding {@link #updateModel()} - * like the first versions of this class did. The reason for that is that this method can be - * used by form validators without having to depend on the actual model being updated, and this - * method is called by the default implementation of {@link #updateModel()} anyway (so we don't - * have to override that anymore). - */ - @Override - public void convertInput() - { - try - { - // Get the converted input values - Date dateFieldInput = dateField.getConvertedInput(); - Integer hoursInput = hoursField.getConvertedInput(); - Integer minutesInput = minutesField.getConvertedInput(); - AM_PM amOrPmInput = amOrPmChoice.getConvertedInput(); - - if (dateFieldInput == null) - { - return; - } - - // Get year, month and day ignoring any timezone of the Date object - Calendar cal = Calendar.getInstance(); - cal.setTime(dateFieldInput); - int year = cal.get(Calendar.YEAR); - int month = cal.get(Calendar.MONTH) + 1; - int day = cal.get(Calendar.DAY_OF_MONTH); - int hours = (hoursInput == null ? 0 : hoursInput % 24); - int minutes = (minutesInput == null ? 0 : minutesInput); - - // Use the input to create a date object with proper timezone - MutableDateTime date = new MutableDateTime(year, month, day, hours, minutes, 0, 0, - DateTimeZone.forTimeZone(getClientTimeZone())); - - // Adjust for halfday if needed - if (use12HourFormat()) - { - int halfday = (amOrPmInput == AM_PM.PM ? 1 : 0); - date.set(DateTimeFieldType.halfdayOfDay(), halfday); - date.set(DateTimeFieldType.hourOfHalfday(), hours % 12); - } - - // The date will be in the server's timezone - setConvertedInput(newDateInstance(date.getMillis())); - } - catch (RuntimeException e) - { - DateTimeField.this.error(e.getMessage()); - invalid(); - } - } - - /** - * A factory method for the DateTextField's model object. - * - * @return any specialization of java.util.Date - */ - protected Date newDateInstance() - { - return new Date(); - } - - /** - * A factory method for the DateTextField's model object. - * - * @param time - * the time in milliseconds - * @return any specialization of java.util.Date - */ - protected Date newDateInstance(long time) - { - return new Date(time); - } - - /** - * create a new {@link DateTextField} instance to be added to this panel. - * - * @param id - * the component id - * @param dateFieldModel - * model that should be used by the {@link DateTextField} - * @return a new date text field instance - */ - protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel) - { - return DateTextField.forShortStyle(id, dateFieldModel, false); - } - - /** - * @see org.apache.wicket.Component#onBeforeRender() - */ - @Override - protected void onBeforeRender() - { - dateField.setRequired(isRequired()); - hoursField.setRequired(isRequired()); - minutesField.setRequired(isRequired()); - - boolean use12HourFormat = use12HourFormat(); - amOrPmChoice.setVisible(use12HourFormat); - - Date modelObject = (Date)getDefaultModelObject(); - if (modelObject == null) - { - date = null; - hours = null; - minutes = null; - } - else - { - MutableDateTime mDate = new MutableDateTime(modelObject); - // convert date to the client's time zone if we have that info - TimeZone zone = getClientTimeZone(); - if (zone != null) - { - mDate.setZone(DateTimeZone.forTimeZone(zone)); - } - - date = mDate.toDateTime().toLocalDate().toDate(); - - if (use12HourFormat) - { - int hourOfHalfDay = mDate.get(DateTimeFieldType.hourOfHalfday()); - hours = hourOfHalfDay == 0 ? 12 : hourOfHalfDay; - } - else - { - hours = mDate.get(DateTimeFieldType.hourOfDay()); - } - - amOrPm = (mDate.get(DateTimeFieldType.halfdayOfDay()) == 0) ? AM_PM.AM : AM_PM.PM; - minutes = mDate.getMinuteOfHour(); - } - - super.onBeforeRender(); - } - - /** - * Change a date in another timezone - * - * @param date - * The input date. - * @param zone - * The target timezone. - * @return A new converted date. - */ - public static Date changeTimeZone(Date date, TimeZone zone) - { - Calendar first = Calendar.getInstance(zone); - first.setTimeInMillis(date.getTime()); - - Calendar output = Calendar.getInstance(); - output.set(Calendar.YEAR, first.get(Calendar.YEAR)); - output.set(Calendar.MONTH, first.get(Calendar.MONTH)); - output.set(Calendar.DAY_OF_MONTH, first.get(Calendar.DAY_OF_MONTH)); - output.set(Calendar.HOUR_OF_DAY, first.get(Calendar.HOUR_OF_DAY)); - output.set(Calendar.MINUTE, first.get(Calendar.MINUTE)); - output.set(Calendar.SECOND, first.get(Calendar.SECOND)); - output.set(Calendar.MILLISECOND, first.get(Calendar.MILLISECOND)); - - return output.getTime(); - } - - /** - * Checks whether the current {@link Locale} uses the 12h or 24h time format. This method can be - * overridden to e.g. always use 24h format. - * - * @return true, if the current {@link Locale} uses the 12h format.<br/> - * false, otherwise - */ - protected boolean use12HourFormat() - { - String pattern = DateTimeFormat.patternForStyle("-S", getLocale()); - return pattern.indexOf('a') != -1 || pattern.indexOf('h') != -1 - || pattern.indexOf('K') != -1; - } - - /** - * @return either 12 or 24, depending on the hour format of the current {@link Locale} - */ - private int getMaximumHours() - { - return getMaximumHours(use12HourFormat()); - } - - /** - * Convenience method (mainly for optimization purposes), in case {@link #use12HourFormat()} has - * already been stored in a local variable and thus doesn't need to be computed again. - * - * @param use12HourFormat - * the hour format to use - * @return either 12 or 24, depending on the parameter <code>use12HourFormat</code> - */ - private int getMaximumHours(boolean use12HourFormat) - { - return use12HourFormat ? 12 : 24; - } - - /** - * The DatePicker that gets added to the DateTimeField component. Users may override this method - * with a DatePicker of their choice. - * - * @return a new {@link DatePicker} instance - */ - protected DatePicker newDatePicker() - { - return new DatePicker() - { - private static final long serialVersionUID = 1L; - - @Override - protected void configure(final Map<String, Object> widgetProperties, - final IHeaderResponse response, final Map<String, Object> initVariables) - { - super.configure(widgetProperties, response, initVariables); - - DateTimeField.this.configure(widgetProperties); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/2bb684c1/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/TimeField.java ---------------------------------------------------------------------- diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/TimeField.java b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/TimeField.java deleted file mode 100644 index 3d98b31..0000000 --- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/TimeField.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 org.apache.wicket.extensions.yui.calendar; - -import java.util.Date; -import java.util.Locale; - -import org.apache.wicket.model.IModel; - -/** - * Works on a {@link java.util.Date} object. Displays a field for hours and a field for minutes, and - * an AM/PM field. The format (12h/24h) of the hours field depends on the time format of this - * {@link TimeField}'s {@link Locale}, as does the visibility of the AM/PM field (see - * {@link TimeField#use12HourFormat}). - * - * @author eelcohillenius - * @see DateField for a variant with just the date field and date picker - */ -public class TimeField extends DateTimeField -{ - private static final long serialVersionUID = 1L; - - /** - * Construct. - * - * @param id - * the component id - */ - public TimeField(String id) - { - this(id, null); - } - - /** - * Construct. - * - * @param id - * the component id - * @param model - * the component's model - */ - public TimeField(String id, IModel<Date> model) - { - super(id, model); - - getDateTextField().setVisibilityAllowed(false); - } - - @Override - public void convertInput() - { - Date modelObject = (Date)getDefaultModelObject(); - getDateTextField().setConvertedInput(modelObject != null ? modelObject : newDateInstance()); - super.convertInput(); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/2bb684c1/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/assets/skins/sam/calendar.css ---------------------------------------------------------------------- diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/assets/skins/sam/calendar.css b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/assets/skins/sam/calendar.css deleted file mode 100644 index 3e932f4..0000000 --- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/assets/skins/sam/calendar.css +++ /dev/null @@ -1,8 +0,0 @@ -/* -Copyright (c) 2011, Yahoo! Inc. All rights reserved. -Code licensed under the BSD License: -http://developer.yahoo.com/yui/license.html -version: 2.9.0 -*/ -.yui-calcontainer{position:relative;float:left;_overflow:hidden}.yui-calcontainer iframe{position:absolute;border:0;margin:0;padding:0;z-index:0;width:100%;height:100%;left:0;top:0}.yui-calcontainer iframe.fixedsize{width:50em;height:50em;top:-1px;left:-1px}.yui-calcontainer.multi .groupcal{z-index:1;float:left;position:relative}.yui-calcontainer .title{position:relative;z-index:1}.yui-calcontainer .close-icon{position:absolute;z-index:1;text-indent:-10000em;overflow:hidden}.yui-calendar{position:relative}.yui-calendar .calnavleft{position:absolute;z-index:1;text-indent:-10000em;overflow:hidden}.yui-calendar .calnavright{position:absolute;z-index:1;text-indent:-10000em;overflow:hidden}.yui-calendar .calheader{position:relative;width:100%;text-align:center}.yui-calcontainer .yui-cal-nav-mask{position:absolute;z-index:2;margin:0;padding:0;width:100%;height:100%;_width:0;_height:0;left:0;top:0;display:none}.yui-calcontainer .yui-cal-nav{position:absolute;z-index:3;top:0;display:none}.y ui-calcontainer .yui-cal-nav .yui-cal-nav-btn{display:-moz-inline-box;display:inline-block}.yui-calcontainer .yui-cal-nav .yui-cal-nav-btn button{display:block;*display:inline-block;*overflow:visible;border:0;background-color:transparent;cursor:pointer}.yui-calendar .calbody a:hover{background:inherit}p#clear{clear:left;padding-top:10px}.yui-skin-sam .yui-calcontainer{background-color:#f2f2f2;border:1px solid #808080;padding:10px}.yui-skin-sam .yui-calcontainer.multi{padding:0 5px 0 5px}.yui-skin-sam .yui-calcontainer.multi .groupcal{background-color:transparent;border:0;padding:10px 5px 10px 5px;margin:0}.yui-skin-sam .yui-calcontainer .title{background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 0;border-bottom:1px solid #ccc;font:100% sans-serif;color:#000;font-weight:bold;height:auto;padding:.4em;margin:0 -10px 10px -10px;top:0;left:0;text-align:left}.yui-skin-sam .yui-calcontainer.multi .title{margin:0 -5px 0 -5px}.yui-skin-sam .yui-calcontainer.withtitle{padding-to p:0}.yui-skin-sam .yui-calcontainer .calclose{background:url(../../../../assets/skins/sam/sprite.png) no-repeat 0 -300px;width:25px;height:15px;top:.4em;right:.4em;cursor:pointer}.yui-skin-sam .yui-calendar{border-spacing:0;border-collapse:collapse;font:100% sans-serif;text-align:center;margin:0}.yui-skin-sam .yui-calendar .calhead{background:transparent;border:0;vertical-align:middle;padding:0}.yui-skin-sam .yui-calendar .calheader{background:transparent;font-weight:bold;padding:0 0 .6em 0;text-align:center}.yui-skin-sam .yui-calendar .calheader img{border:0}.yui-skin-sam .yui-calendar .calnavleft{background:url(../../../../assets/skins/sam/sprite.png) no-repeat 0 -450px;width:25px;height:15px;top:0;bottom:0;left:-10px;margin-left:.4em;cursor:pointer}.yui-skin-sam .yui-calendar .calnavright{background:url(../../../../assets/skins/sam/sprite.png) no-repeat 0 -500px;width:25px;height:15px;top:0;bottom:0;right:-10px;margin-right:.4em;cursor:pointer}.yui-skin-sam .yui-calendar .calweek dayrow{height:2em}.yui-skin-sam .yui-calendar .calweekdayrow th{padding:0;border:0}.yui-skin-sam .yui-calendar .calweekdaycell{color:#000;font-weight:bold;text-align:center;width:2em}.yui-skin-sam .yui-calendar .calfoot{background-color:#f2f2f2}.yui-skin-sam .yui-calendar .calrowhead,.yui-skin-sam .yui-calendar .calrowfoot{color:#a6a6a6;font-size:85%;font-style:normal;font-weight:normal;border:0}.yui-skin-sam .yui-calendar .calrowhead{text-align:right;padding:0 2px 0 0}.yui-skin-sam .yui-calendar .calrowfoot{text-align:left;padding:0 0 0 2px}.yui-skin-sam .yui-calendar td.calcell{border:1px solid #ccc;background:#fff;padding:1px;height:1.6em;line-height:1.6em;text-align:center;white-space:nowrap}.yui-skin-sam .yui-calendar td.calcell a{color:#06c;display:block;height:100%;text-decoration:none}.yui-skin-sam .yui-calendar td.calcell.today{background-color:#000}.yui-skin-sam .yui-calendar td.calcell.today a{background-color:#fff}.yui-skin-sam .yui-calendar td.calcell.oom{background-col or:#ccc;color:#a6a6a6;cursor:default}.yui-skin-sam .yui-calendar td.calcell.oom a{color:#a6a6a6}.yui-skin-sam .yui-calendar td.calcell.selected{background-color:#fff;color:#000}.yui-skin-sam .yui-calendar td.calcell.selected a{background-color:#b3d4ff;color:#000}.yui-skin-sam .yui-calendar td.calcell.calcellhover{background-color:#426fd9;color:#fff;cursor:pointer}.yui-skin-sam .yui-calendar td.calcell.calcellhover a{background-color:#426fd9;color:#fff}.yui-skin-sam .yui-calendar td.calcell.previous{color:#e0e0e0}.yui-skin-sam .yui-calendar td.calcell.restricted{text-decoration:line-through}.yui-skin-sam .yui-calendar td.calcell.highlight1{background-color:#cf9}.yui-skin-sam .yui-calendar td.calcell.highlight2{background-color:#9cf}.yui-skin-sam .yui-calendar td.calcell.highlight3{background-color:#fcc}.yui-skin-sam .yui-calendar td.calcell.highlight4{background-color:#cf9}.yui-skin-sam .yui-calendar a.calnav{border:1px solid #f2f2f2;padding:0 4px;text-decoration:none;color:#000;zoom :1}.yui-skin-sam .yui-calendar a.calnav:hover{background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 0;border-color:#a0a0a0;cursor:pointer}.yui-skin-sam .yui-calcontainer .yui-cal-nav-mask{background-color:#000;opacity:.25;filter:alpha(opacity=25)}.yui-skin-sam .yui-calcontainer .yui-cal-nav{font-family:arial,helvetica,clean,sans-serif;font-size:93%;border:1px solid #808080;left:50%;margin-left:-7em;width:14em;padding:0;top:2.5em;background-color:#f2f2f2}.yui-skin-sam .yui-calcontainer.withtitle .yui-cal-nav{top:4.5em}.yui-skin-sam .yui-calcontainer.multi .yui-cal-nav{width:16em;margin-left:-8em}.yui-skin-sam .yui-calcontainer .yui-cal-nav-y,.yui-skin-sam .yui-calcontainer .yui-cal-nav-m,.yui-skin-sam .yui-calcontainer .yui-cal-nav-b{padding:5px 10px 5px 10px}.yui-skin-sam .yui-calcontainer .yui-cal-nav-b{text-align:center}.yui-skin-sam .yui-calcontainer .yui-cal-nav-e{margin-top:5px;padding:5px;background-color:#edf5ff;border-top:1px solid black;display:none}.yui-skin-s am .yui-calcontainer .yui-cal-nav label{display:block;font-weight:bold} -.yui-skin-sam .yui-calcontainer .yui-cal-nav-mc{width:100%;_width:auto}.yui-skin-sam .yui-calcontainer .yui-cal-nav-y input.yui-invalid{background-color:#ffee69;border:1px solid #000}.yui-skin-sam .yui-calcontainer .yui-cal-nav-yc{width:4em}.yui-skin-sam .yui-calcontainer .yui-cal-nav .yui-cal-nav-btn{border:1px solid #808080;background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 0;background-color:#ccc;margin:auto .15em}.yui-skin-sam .yui-calcontainer .yui-cal-nav .yui-cal-nav-btn button{padding:0 8px;font-size:93%;line-height:2;*line-height:1.7;min-height:2em;*min-height:auto;color:#000}.yui-skin-sam .yui-calcontainer .yui-cal-nav .yui-cal-nav-btn.yui-default{border:1px solid #304369;background-color:#426fd9;background:url(../../../../assets/skins/sam/sprite.png) repeat-x 0 -1400px}.yui-skin-sam .yui-calcontainer .yui-cal-nav .yui-cal-nav-btn.yui-default button{color:#fff}
