001/* 002 * Copyright 2012 GWT-Bootstrap 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.github.gwtbootstrap.datetimepicker.client.ui; 017 018import java.util.Date; 019 020import com.github.gwtbootstrap.client.ui.AppendButton; 021import com.github.gwtbootstrap.client.ui.base.AddOn; 022import com.github.gwtbootstrap.client.ui.base.HasAlternateSize; 023import com.github.gwtbootstrap.client.ui.base.HasIcon; 024import com.github.gwtbootstrap.client.ui.base.HasVisibility; 025import com.github.gwtbootstrap.client.ui.base.HasVisibleHandlers; 026import com.github.gwtbootstrap.client.ui.constants.AlternateSize; 027import com.github.gwtbootstrap.client.ui.constants.BaseIconType; 028import com.github.gwtbootstrap.client.ui.constants.IconPosition; 029import com.github.gwtbootstrap.client.ui.constants.IconSize; 030import com.github.gwtbootstrap.client.ui.constants.IconType; 031import com.github.gwtbootstrap.client.ui.event.HiddenHandler; 032import com.github.gwtbootstrap.client.ui.event.HideHandler; 033import com.github.gwtbootstrap.client.ui.event.ShowHandler; 034import com.github.gwtbootstrap.client.ui.event.ShownHandler; 035import com.github.gwtbootstrap.datetimepicker.client.ui.base.DateTimeBoxBase; 036import com.github.gwtbootstrap.datetimepicker.client.ui.base.HasAllDateTimePickerHandlers; 037import com.github.gwtbootstrap.datetimepicker.client.ui.base.HasDateFormat; 038import com.github.gwtbootstrap.datetimepicker.client.ui.base.HasViewMode; 039import com.google.gwt.editor.client.IsEditor; 040import com.google.gwt.editor.client.adapters.TakesValueEditor; 041import com.google.gwt.event.dom.client.ChangeHandler; 042import com.google.gwt.event.dom.client.HasChangeHandlers; 043import com.google.gwt.event.logical.shared.HasValueChangeHandlers; 044import com.google.gwt.event.logical.shared.ValueChangeHandler; 045import com.google.gwt.event.shared.HandlerRegistration; 046import com.google.gwt.i18n.client.DateTimeFormat; 047import com.google.gwt.user.client.ui.HasValue; 048import com.google.gwt.user.client.ui.ValueBoxBase.TextAlignment; 049 050/** 051 * DateTimeBoxAppended component. 052 * 053 * @author Carlos Alexandro Becker 054 * @author Alain Penders 055 * @since 2.1.1.0 056 */ 057public class DateTimeBoxAppended 058 extends AppendButton implements HasValue<Date>, 059 HasDateFormat, HasIcon, HasValueChangeHandlers<Date>, HasVisibility, 060 HasChangeHandlers, HasVisibleHandlers, HasAllDateTimePickerHandlers, 061 HasAlternateSize, IsEditor<TakesValueEditor<Date>> { 062 063 /** 064 * An 'adapter' to change some aspects of the behavior of datepickerbase. 065 */ 066 private class DateTimeBoxAppendedAdapter 067 extends DateTimeBoxBase { 068 @Override 069 protected void configure() { 070 DateTimeBoxAppended that = DateTimeBoxAppended.this; 071 that.addStyleName("date"); 072 super.configure(that); 073 } 074 } 075 076 private final DateTimeBoxAppendedAdapter box; 077 private AddOn icon; 078 { 079 this.box = new DateTimeBoxAppendedAdapter(); 080 icon = new AddOn(); 081 icon.setIcon(IconType.TH); 082 add(box); 083 add(icon); 084 } 085 086 087 /** 088 * {@inheritDoc} 089 */ 090 @Override 091 public Date getValue() { 092 return box.getValue(); 093 } 094 095 /** 096 * {@inheritDoc} 097 */ 098 @Override 099 public void setValue(Date value) { 100 box.setValue(value); 101 } 102 103 /** 104 * {@inheritDoc} 105 */ 106 @Override 107 public void setValue(Date value, boolean fireEvents) { 108 box.setValue(value, fireEvents); 109 } 110 111 /** 112 * {@inheritDoc} 113 */ 114 @Override 115 public void setAlternateSize(AlternateSize size) { 116 box.setAlternateSize(size); 117 } 118 119 public void setAlignment(TextAlignment align) { 120 box.setAlignment(align); 121 } 122 123 /** 124 * {@inheritDoc} 125 */ 126 @Override 127 public HandlerRegistration addValueChangeHandler( 128 ValueChangeHandler<Date> dateValueChangeHandler) { 129 return box.addValueChangeHandler(dateValueChangeHandler); 130 } 131 132 /** 133 * {@inheritDoc} 134 */ 135 @Override 136 public void setFormat(String format) { 137 box.setFormat(format); 138 } 139 140 /** 141 * {@inheritDoc} 142 */ 143 @Override 144 public void setIcon(IconType type) { 145 setBaseIcon(type); 146 } 147 148 /** 149 * {@inheritDoc} 150 */ 151 @Override 152 public void setBaseIcon(BaseIconType type) { 153 icon.setBaseIcon(type); 154 } 155 156 /** 157 * {@inheritDoc} 158 */ 159 @Override 160 public void setIconSize(IconSize size) { 161 icon.setIconSize(size); 162 } 163 164 /** 165 * {@inheritDoc} 166 */ 167 @Override 168 public void setCustomIconStyle(String customIconStyle) { 169 icon.setCustomIconStyle(customIconStyle); 170 } 171 172 /** 173 * {@inheritDoc} 174 * 175 * @deprecated 176 */ 177 @Override 178 public void setIconPosition(IconPosition position) { 179 icon.setIconPosition(position); 180 } 181 182 /** 183 * {@inheritDoc} 184 */ 185 @Override 186 public void setAutoClose(boolean autoclose) { 187 box.setAutoClose(autoclose); 188 } 189 190 /** 191 * {@inheritDoc} 192 */ 193 @Override 194 public void setEndDate(String date) { 195 box.setEndDate(date); 196 } 197 198 /** 199 * {@inheritDoc} 200 */ 201 @Override 202 public void setEndDate_(Date date) { 203 box.setEndDate_(date); 204 } 205 206 /** 207 * {@inheritDoc} 208 */ 209 @Override 210 public void setLanguage(String language) { 211 box.setLanguage(language); 212 } 213 214 /** 215 * {@inheritDoc} 216 */ 217 @Override 218 public void setStartDate(String date) { 219 box.setStartDate(date); 220 } 221 222 /** 223 * {@inheritDoc} 224 */ 225 @Override 226 public void setStartDate_(Date date) { 227 box.setStartDate_(date); 228 } 229 230 /** 231 * {@inheritDoc} 232 */ 233 @Override 234 public void setMinView(ViewMode mode) { 235 box.setMinView(mode); 236 } 237 238 /** 239 * {@inheritDoc} 240 */ 241 @Override 242 public void setMinView(String mode) { 243 box.setMinView(mode); 244 } 245 246 /** 247 * {@inheritDoc} 248 */ 249 @Override 250 public void setMaxView(ViewMode mode) { 251 box.setMaxView(mode); 252 } 253 254 /** 255 * {@inheritDoc} 256 */ 257 @Override 258 public void setMaxView(String mode) { 259 box.setMaxView(mode); 260 } 261 262 /** 263 * {@inheritDoc} 264 */ 265 @Override 266 public void setStartView(ViewMode mode) { 267 box.setStartView(mode); 268 } 269 270 /** 271 * {@inheritDoc} 272 */ 273 @Override 274 public void setStartView(String mode) { 275 box.setStartView(mode); 276 } 277 278 /** 279 * {@inheritDoc} 280 */ 281 @Override 282 public void setWeekStart(int start) { 283 box.setWeekStart(start); 284 } 285 286 /** 287 * {@inheritDoc} 288 */ 289 @Override 290 public TakesValueEditor<Date> asEditor() { 291 return box.asEditor(); 292 } 293 294 /** 295 * {@inheritDoc} 296 */ 297 @Override 298 public HandlerRegistration addHideHandler(HideHandler handler) { 299 return box.addHideHandler(handler); 300 } 301 302 /** 303 * {@inheritDoc} 304 */ 305 @Override 306 public HandlerRegistration addHiddenHandler(HiddenHandler handler) { 307 return box.addHiddenHandler(handler); 308 } 309 310 /** 311 * {@inheritDoc} 312 */ 313 @Override 314 public HandlerRegistration addShowHandler(ShowHandler handler) { 315 return box.addShowHandler(handler); 316 } 317 318 /** 319 * {@inheritDoc} 320 */ 321 @Override 322 public HandlerRegistration addShownHandler(ShownHandler handler) { 323 return box.addShownHandler(handler); 324 } 325 326 /** 327 * {@inheritDoc} 328 */ 329 @Override 330 public HandlerRegistration addChangeHandler(ChangeHandler handler) { 331 return box.addChangeHandler(handler); 332 } 333 334 /** 335 * {@inheritDoc} 336 */ 337 @Override 338 public void show() { 339 box.show(); 340 } 341 342 /** 343 * {@inheritDoc} 344 */ 345 @Override 346 public void hide() { 347 box.hide(); 348 } 349 350 /** 351 * {@inheritDoc} 352 */ 353 @Override 354 public void toggle() { 355 box.toggle(); 356 } 357 358 /** 359 * @see com.google.gwt.user.client.ui.ValueBoxBase#isReadOnly() 360 */ 361 public boolean isReadOnly() { 362 return box.isReadOnly(); 363 } 364 365 /** 366 * @see com.google.gwt.user.client.ui.ValueBoxBase#setReadOnly(boolean) 367 */ 368 public void setReadOnly(boolean readonly) { 369 box.setReadOnly(readonly); 370 } 371 372 373 @Override 374 public void setDaysOfWeekDisabled(String value) { 375 box.setDaysOfWeekDisabled(value); 376 } 377 378 379 @Override 380 public void setMinuteStep(int minutes) { 381 box.setMinuteStep(minutes); 382 } 383 384 385 @Override 386 public void setShowTodayButton(boolean show) { 387 box.setShowTodayButton(show); 388 } 389 390 391 @Override 392 public void setHighlightToday(boolean highlight) { 393 box.setHighlightToday(highlight); 394 } 395}