Added: incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/DateTimeField.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/DateTimeField.java?view=auto&rev=511645 ============================================================================== --- incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/DateTimeField.java (added) +++ incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/DateTimeField.java Sun Feb 25 14:32:17 2007 @@ -0,0 +1,285 @@ +/* + * 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 wicket.extensions.yui.calendar; + +import java.util.Arrays; +import java.util.Date; +import java.util.TimeZone; + +import org.joda.time.DateTimeFieldType; +import org.joda.time.DateTimeZone; +import org.joda.time.MutableDateTime; + +import wicket.MarkupContainer; +import wicket.Session; +import wicket.datetime.markup.html.form.DateTextField; +import wicket.markup.html.form.DropDownChoice; +import wicket.markup.html.form.FormComponentPanel; +import wicket.markup.html.form.TextField; +import wicket.model.IModel; +import wicket.model.PropertyModel; +import wicket.protocol.http.request.WebClientInfo; +import wicket.request.ClientInfo; +import wicket.validation.validator.NumberValidator; + +/** + * Works on a [EMAIL PROTECTED] java.util.Date} object. Displays a date field and a date + * picker, a field for hours and a field for minutes, and a AM/ PM field. + * + * @author eelcohillenius + * @see DateField for a variant with just the date field and date picker + */ +// TODO AM/PM should really be locale dependent; some locales have 12 hour +// systems with AM/PM, others have 24 hour systems +public class DateTimeField extends FormComponentPanel { + + /** + * Enumerated type for different ways of handling the render part of + * requests. + */ + private static enum AM_PM { + + AM, PM; + } + + private static final long serialVersionUID = 1L; + + private AM_PM amOrPm = AM_PM.AM; + + private DropDownChoice amOrPmChoice; + + private MutableDateTime date; + + private DateTextField dateField; + + private Integer hours; + + private TextField hoursField; + + private Integer minutes; + + private TextField minutesField; + + /** + * Construct. + * + * @param parent + * @param id + */ + public DateTimeField(MarkupContainer parent, String id) { + super(parent, id); + init(); + } + + /** + * Construct. + * + * @param parent + * @param id + * @param model + */ + public DateTimeField(MarkupContainer parent, String id, IModel model) { + super(parent, id, model); + init(); + } + + /** + * Gets amOrPm. + * + * @return amOrPm + */ + public AM_PM getAmOrPm() { + return amOrPm; + } + + /** + * Gets date. + * + * @return date + */ + public Date getDate() { + return (date != null) ? date.toDate() : null; + } + + /** + * Gets hours. + * + * @return hours + */ + public Integer getHours() { + return hours; + } + + /** + * Gets minutes. + * + * @return minutes + */ + public Integer getMinutes() { + return minutes; + } + + /** + * Sets amOrPm. + * + * @param amOrPm + * amOrPm + */ + public void setAmOrPm(AM_PM amOrPm) { + this.amOrPm = amOrPm; + } + + /** + * Sets date. + * + * @param date + * date + */ + public void setDate(Date date) { + this.date = (date != null) ? new MutableDateTime(date) : null; + } + + /** + * Sets hours. + * + * @param hours + * hours + */ + public void setHours(Integer hours) { + this.hours = hours; + } + + /** + * Sets minutes. + * + * @param minutes + * minutes + */ + public void setMinutes(Integer minutes) { + this.minutes = minutes; + } + + /** + * @see wicket.markup.html.form.FormComponent#updateModel() + */ + public void updateModel() { + + dateField.updateModel(); + hoursField.updateModel(); + minutesField.updateModel(); + amOrPmChoice.updateModel(); + + if (date != null) { + + try { + TimeZone zone = getClientTimeZone(); + if (zone != null) { + date.setZone(DateTimeZone.forTimeZone(zone)); + } + + if (hours != null) { + date.set(DateTimeFieldType.hourOfHalfday(), hours + .intValue()); + date.setMinuteOfHour((minutes != null) ? minutes.intValue() + : 0); + } + if (amOrPm == AM_PM.PM) { + date.set(DateTimeFieldType.halfdayOfDay(), 1); + } else { + date.set(DateTimeFieldType.halfdayOfDay(), 0); + } + + // the date will be in the server's timezone + Date d = date.toDate(); + setModelObject(d); + + } catch (RuntimeException e) { + DateTimeField.this.error(e.getMessage()); + invalid(); + } + + } else { + setModelObject(null); + } + } + + /** + * Gets the client's time zone. + * + * @return The client's time zone or null + */ + private TimeZone getClientTimeZone() { + ClientInfo info = Session.get().getClientInfo(); + if (info instanceof WebClientInfo) { + return ((WebClientInfo) info).getProperties().getTimeZone(); + } + return null; + } + + private void init() { + + setType(Date.class); + dateField = DateTextField.forShortStyle(this, "date", + new PropertyModel(this, "date")); + dateField.add(new DatePicker()); + // add(new CalendarPopup("picker", dateField)); + hoursField = new TextField(this, "hours", new PropertyModel(this, + "hours"), Integer.class); + hoursField.add(NumberValidator.range(0, 12)); + minutesField = new TextField(this, "minutes", new PropertyModel(this, + "minutes"), Integer.class); + minutesField.add(NumberValidator.range(0, 60)); + amOrPmChoice = new DropDownChoice(this, "amOrPmChoice", + new PropertyModel(this, "amOrPm"), Arrays + .asList(AM_PM.values())); + } + + /** + * @see wicket.Component#onAttach() + */ + protected void onAttach() { + + Date d = (Date) getModelObject(); + if (d != null) { + date = new MutableDateTime(d); + } else { + date = null; + } + + if (date != null) { + + // convert date to the client's time zone if we have that info + TimeZone zone = getClientTimeZone(); + // instantiate with the previously set date + if (zone != null) { + date.setZone(DateTimeZone.forTimeZone(zone)); + } + + hours = new Integer(date.get(DateTimeFieldType.hourOfHalfday())); + minutes = new Integer(date.getMinuteOfHour()); + amOrPm = (date.get(DateTimeFieldType.halfdayOfDay()) == 0) ? AM_PM.AM + : AM_PM.PM; + + // we don't really have to reset the date field to the server's + // timezone, as it's the same milis from EPOCH anyway, and toDate + // will always get the Date object initialized for the time zone + // of the server + } + + super.onAttach(); + } +}
Added: incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/VERSION URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/VERSION?view=auto&rev=511645 ============================================================================== --- incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/VERSION (added) +++ incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/VERSION Sun Feb 25 14:32:17 2007 @@ -0,0 +1,2 @@ +http://developer.yahoo.com/yui/ +version: 0.12.2 \ No newline at end of file Added: incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calendar.css URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calendar.css?view=auto&rev=511645 ============================================================================== --- incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calendar.css (added) +++ incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calendar.css Sun Feb 25 14:32:17 2007 @@ -0,0 +1,191 @@ +/* +Copyright (c) 2006, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +Version 0.12 +*/ + +.yui-calcontainer { + position:relative; + padding:5px; + background-color:#F7F9FB; + border:1px solid #7B9EBD; + float:left; + overflow:hidden; +} + +.yui-calcontainer iframe { + position:absolute; + border:none; + margin:0;padding:0; + left:-1px; + top:-1px; + z-index:0; + width:50em; + height:50em; +} + +.yui-calcontainer.multi { + padding:0; +} + +.yui-calcontainer.multi .groupcal { + padding:5px; + background-color:transparent; + z-index:1; + float:left; + position:relative; + border:none; +} + +.yui-calcontainer .title { + font:100% sans-serif; + color:#000; + font-weight:bold; + margin-bottom:5px; + height:25px; + position:absolute; + top:3px;left:5px; + z-index:1; +} + +.yui-calcontainer .close-icon { + position:absolute; + right:3px; + top:3px; + border:none; + z-index:1; +} + +/* Calendar element styles */ + +.yui-calendar { + font:100% sans-serif; + text-align:center; + border-spacing:0; + border-collapse:separate; + position:relative; +} + +.yui-calcontainer.withtitle { + padding-top:1.5em; +} + +.yui-calendar .calnavleft { + position:absolute; + background-repeat:no-repeat; + cursor:pointer; + top:2px; + bottom:0; + width:9px; + height:12px; + left:2px; + z-index:1; +} + +.yui-calendar .calnavright { + position:absolute; + background-repeat:no-repeat; + cursor:pointer; + top:2px; + bottom:0; + width:9px; + height:12px; + right:2px; + z-index:1; +} + +.yui-calendar td.calcell { + padding:.1em .2em; + border:1px solid #E0E0E0; + text-align:center; +} + +.yui-calendar td.calcell a { + color:#003DB8; + text-decoration:none; +} + +.yui-calendar td.calcell.today { + border:1px solid #000; +} + +.yui-calendar td.calcell.oom { + cursor:default; + color:#999; + background-color:#EEE; + border:1px solid #E0E0E0; +} + +.yui-calendar td.calcell.selected { + color:#003DB8; + background-color:#FFF19F; + border:1px solid #FF9900; +} + +.yui-calendar td.calcell.calcellhover { + cursor:pointer; + color:#FFF; + background-color:#FF9900; + border:1px solid #FF9900; +} + +.yui-calendar td.calcell.calcellhover a { + color:#FFF; +} + +.yui-calendar td.calcell.restricted { + text-decoration:line-through; +} + +.yui-calendar td.calcell.previous { + color:#CCC; +} + +.yui-calendar td.calcell.highlight1 { background-color:#CCFF99; } +.yui-calendar td.calcell.highlight2 { background-color:#99CCFF; } +.yui-calendar td.calcell.highlight3 { background-color:#FFCCCC; } +.yui-calendar td.calcell.highlight4 { background-color:#CCFF99; } + +.yui-calendar .calhead { + border:1px solid #E0E0E0; + vertical-align:middle; + background-color:#FFF; +} + +.yui-calendar .calheader { + position:relative; + width:100%; + text-align:center; +} + +.yui-calendar .calheader img { + border:none; +} + +.yui-calendar .calweekdaycell { + color:#666; + font-weight:normal; + text-align:center; + width:1.5em; +} + +.yui-calendar .calfoot { + background-color:#EEE; +} + +.yui-calendar .calrowhead, .yui-calendar .calrowfoot { + color:#666; + font-size:9px; + font-style:italic; + font-weight:normal; + width:15px; +} + +.yui-calendar .calrowhead { + border-right-width:2px; +} + +/*Specific changes for calendar running under fonts/reset */ +.yui-calendar a:hover {background:inherit;} +p#clear {clear:left; padding-top:10px;} Added: incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/callt.gif URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/callt.gif?view=auto&rev=511645 ============================================================================== Binary file - no diff available. Propchange: incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/callt.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calrt.gif URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calrt.gif?view=auto&rev=511645 ============================================================================== Binary file - no diff available. Propchange: incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calrt.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calx.gif URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calx.gif?view=auto&rev=511645 ============================================================================== Binary file - no diff available. Propchange: incubator/wicket/trunk/wicket-datetime/src/main/java/wicket/extensions/yui/calendar/assets/calx.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream
