List of usage examples for com.google.gwt.event.dom.client FocusHandler FocusHandler
FocusHandler
From source file:com.bearsoft.gwt.ui.widgets.DateTimeBox.java
public DateTimeBox(DateTimePicker aPicker, Date date, DateBox.Format format) { initWidget(container);/*from www.j a v a 2 s . c o m*/ picker = aPicker; container.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); container.getElement().getStyle().setPosition(Style.Position.RELATIVE); container.getElement().addClassName("date-time-field"); field = new DecoratedDateBox(picker, date, format); field.setFireNullValues(true); box = field.getTextBox(); box.getElement().getStyle().setOutlineStyle(Style.OutlineStyle.NONE); box.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { Date newValue = getValue(); if (value == null ? newValue != null : !value.equals(newValue)) { value = newValue; updateTimeValue(value, true); ValueChangeEvent.fire(DateTimeBox.this, newValue); } } }); box.addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { switch (event.getNativeKeyCode()) { case KeyCodes.KEY_ENTER: case KeyCodes.KEY_TAB: Date newValue = field.getValue(); if (value == null ? newValue != null : !value.equals(newValue)) { value = newValue; updateTimeValue(value, true); ValueChangeEvent.fire(DateTimeBox.this, newValue); } break; } } }); field.getDatePicker().addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { if (!settingValueFromJs) { settingValueToJs = true; Date datePart = event.getValue(); Date timePart = picker.getTimePicker().getValue(); Date newValue; if (timePart == null) { newValue = new Date(datePart.getTime()); } else { newValue = new Date(datePart.getTime() + timePart.getTime()); } if (value == null ? newValue != null : !value.equals(newValue)) { value = newValue; field.setValue(value, true); updateTimeValue(value, true); picker.getTimePicker().setValue(value); ValueChangeEvent.fire(DateTimeBox.this, newValue); } settingValueToJs = false; } } }); picker.getTimePicker().addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { if (!settingValueFromJs) { settingValueToJs = true; Date timePart = picker.getTimePicker().getValue(); Date datePart = field.getValue(); if (timePart == null) { return; } CalendarUtil.resetTime(datePart); value = new Date(datePart.getTime() + timePart.getTime()); field.setValue(value, true); ValueChangeEvent.fire(DateTimeBox.this, value); settingValueToJs = false; } } }); fieldWrapper.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); fieldWrapper.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); fieldWrapper.getElement().getStyle().setTop(0, Style.Unit.PX); fieldWrapper.getElement().getStyle().setHeight(100, Style.Unit.PCT); fieldWrapper.getElement().getStyle().setLeft(0, Style.Unit.PX); fieldWrapper.getElement().getStyle().setBorderWidth(0, Style.Unit.PX); fieldWrapper.getElement().getStyle().setMargin(0, Style.Unit.PX); fieldWrapper.getElement().getStyle().setPadding(0, Style.Unit.PX); CommonResources.INSTANCE.commons().ensureInjected(); fieldWrapper.getElement().addClassName(CommonResources.INSTANCE.commons().borderSized()); field.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); field.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); field.getElement().getStyle().setTop(0, Style.Unit.PX); field.getElement().getStyle().setHeight(100, Style.Unit.PCT); field.getElement().getStyle().setLeft(0, Style.Unit.PX); field.getElement().getStyle().setWidth(100, Style.Unit.PCT); field.getElement().getStyle().setBorderWidth(0, Style.Unit.PX); field.getElement().getStyle().setMargin(0, Style.Unit.PX); field.getElement().getStyle().setPadding(0, Style.Unit.PX); field.getElement().getStyle().setBackgroundColor("inherit"); field.getElement().getStyle().setColor("inherit"); fieldWrapper.setWidget(field); right.getElement().addClassName("date-select"); right.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); right.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); right.getElement().getStyle().setTop(0, Style.Unit.PX); right.getElement().getStyle().setHeight(100, Style.Unit.PCT); right.getElement().getStyle().setRight(0, Style.Unit.PX); CommonResources.INSTANCE.commons().ensureInjected(); right.getElement().addClassName(CommonResources.INSTANCE.commons().unselectable()); popup.setStyleName("dateBoxPopup"); popup.setAutoHideEnabled(true); container.add(fieldWrapper); container.add(right); right.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (!isReadonly()) { popup.setWidget(field.getDatePicker()); popup.showRelativeTo(right); } } }, ClickEvent.getType()); organizeFieldWrapperRight(); getElement().<XElement>cast().addResizingTransitionEnd(this); if (field.getTextBox() instanceof HasKeyDownHandlers) { ((HasKeyDownHandlers) field.getTextBox()).addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { KeyDownEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } if (field.getTextBox() instanceof HasKeyUpHandlers) { ((HasKeyUpHandlers) field.getTextBox()).addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { KeyUpEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } if (field.getTextBox() instanceof HasKeyPressHandlers) { ((HasKeyPressHandlers) field.getTextBox()).addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { KeyPressEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } if (field.getTextBox() instanceof HasFocusHandlers) { ((HasFocusHandlers) field.getTextBox()).addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { FocusEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } if (field.getTextBox() instanceof HasBlurHandlers) { ((HasBlurHandlers) field.getTextBox()).addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { BlurEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } changeViewPresentation(); }
From source file:com.bearsoft.gwt.ui.widgets.DecoratorBox.java
public void setWidget(HasValue<T> w) { if (decorated != w) { if (changeValueHandler != null) { changeValueHandler.removeHandler(); }//w w w .jav a 2 s .co m if (keyDownHandler != null) keyDownHandler.removeHandler(); if (keyUpHandler != null) keyUpHandler.removeHandler(); if (keyPressHandler != null) keyPressHandler.removeHandler(); if (focusHandler != null) focusHandler.removeHandler(); if (blurHandler != null) blurHandler.removeHandler(); if (decorated instanceof Widget) { ((Widget) decorated).removeFromParent(); } decorated = w; if (decorated != null) { changeValueHandler = decorated.addValueChangeHandler(new ValueChangeHandler<T>() { @Override public void onValueChange(ValueChangeEvent<T> event) { fireValueChangeEvent(); } }); if (decorated instanceof Widget) { CommonResources.INSTANCE.commons().ensureInjected(); ((Widget) decorated).getElement() .addClassName(CommonResources.INSTANCE.commons().borderSized()); Style style = ((Widget) decorated).getElement().getStyle(); style.setBorderWidth(0, Style.Unit.PX); style.setPadding(0, Style.Unit.PX); style.setMargin(0, Style.Unit.PX); style.setPosition(Style.Position.ABSOLUTE); style.setDisplay(Style.Display.INLINE_BLOCK); style.setLeft(0, Style.Unit.PX); style.setTop(0, Style.Unit.PX); style.setHeight(100, Style.Unit.PCT); style.setWidth(100, Style.Unit.PCT); style.setOutlineStyle(Style.OutlineStyle.NONE); style.setBackgroundColor("inherit"); style.setColor("inherit"); contentWrapper.setWidget((Widget) decorated); } if (decorated instanceof HasKeyDownHandlers) { keyDownHandler = ((HasKeyDownHandlers) decorated).addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { KeyDownEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this); } }); } if (decorated instanceof HasKeyUpHandlers) { keyUpHandler = ((HasKeyUpHandlers) decorated).addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { KeyUpEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this); } }); } if (decorated instanceof HasKeyPressHandlers) { keyPressHandler = ((HasKeyPressHandlers) decorated).addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { KeyPressEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this); } }); } if (decorated instanceof HasFocusHandlers) { focusHandler = ((HasFocusHandlers) decorated).addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { DecoratorBox.this.getElement().addClassName(DECORATOR_FOCUSED_CLASS_NAME); FocusEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this); } }); } if (decorated instanceof HasBlurHandlers) { blurHandler = ((HasBlurHandlers) decorated).addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { DecoratorBox.this.getElement().removeClassName(DECORATOR_FOCUSED_CLASS_NAME); BlurEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this); } }); } } } }
From source file:com.bearsoft.gwt.ui.widgets.SpinnerBox.java
public SpinnerBox(ValueBox<T> aField) { initWidget(container);/*from w ww .java 2 s. c o m*/ container.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); container.getElement().getStyle().setPosition(Style.Position.RELATIVE); container.getElement().addClassName("spin-field"); field = aField; field.addValueChangeHandler(new ValueChangeHandler<T>() { @Override public void onValueChange(ValueChangeEvent<T> event) { ValueChangeEvent.fire(SpinnerBox.this, getValue()); } }); if (field instanceof HasKeyDownHandlers) { ((HasKeyDownHandlers) field).addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { KeyDownEvent.fireNativeEvent(event.getNativeEvent(), SpinnerBox.this); } }); } if (field instanceof HasKeyUpHandlers) { ((HasKeyUpHandlers) field).addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { KeyUpEvent.fireNativeEvent(event.getNativeEvent(), SpinnerBox.this); } }); } if (field instanceof HasKeyPressHandlers) { ((HasKeyPressHandlers) field).addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { KeyPressEvent.fireNativeEvent(event.getNativeEvent(), SpinnerBox.this); } }); } if (field instanceof HasFocusHandlers) { ((HasFocusHandlers) field).addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { FocusEvent.fireNativeEvent(event.getNativeEvent(), SpinnerBox.this); } }); } if (field instanceof HasBlurHandlers) { ((HasBlurHandlers) field).addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { BlurEvent.fireNativeEvent(event.getNativeEvent(), SpinnerBox.this); } }); } left.getElement().addClassName("spin-left"); left.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); left.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); left.getElement().getStyle().setTop(0, Style.Unit.PX); left.getElement().getStyle().setHeight(100, Style.Unit.PCT); left.getElement().getStyle().setLeft(0, Style.Unit.PX); fieldWrapper.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); fieldWrapper.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); fieldWrapper.getElement().getStyle().setTop(0, Style.Unit.PX); fieldWrapper.getElement().getStyle().setHeight(100, Style.Unit.PCT); fieldWrapper.getElement().getStyle().setBorderWidth(0, Style.Unit.PX); fieldWrapper.getElement().getStyle().setMargin(0, Style.Unit.PX); fieldWrapper.getElement().getStyle().setPadding(0, Style.Unit.PX); CommonResources.INSTANCE.commons().ensureInjected(); fieldWrapper.getElement().addClassName(CommonResources.INSTANCE.commons().borderSized()); field.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); field.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); field.getElement().getStyle().setTop(0, Style.Unit.PX); field.getElement().getStyle().setHeight(100, Style.Unit.PCT); field.getElement().getStyle().setLeft(0, Style.Unit.PX); field.getElement().getStyle().setWidth(100, Style.Unit.PCT); field.getElement().getStyle().setBorderWidth(0, Style.Unit.PX); field.getElement().getStyle().setMargin(0, Style.Unit.PX); field.getElement().getStyle().setPadding(0, Style.Unit.PX); fieldWrapper.setWidget(field); right.getElement().addClassName("spin-right"); right.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); right.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); right.getElement().getStyle().setTop(0, Style.Unit.PX); right.getElement().getStyle().setHeight(100, Style.Unit.PCT); right.getElement().getStyle().setRight(0, Style.Unit.PX); CommonResources.INSTANCE.commons().ensureInjected(); left.getElement().addClassName(CommonResources.INSTANCE.commons().unselectable()); right.getElement().addClassName(CommonResources.INSTANCE.commons().unselectable()); container.add(left); container.add(fieldWrapper); container.add(right); left.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (!isReadonly()) { decrement(); } } }, ClickEvent.getType()); right.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (!isReadonly()) { increment(); } } }, ClickEvent.getType()); organaizeFieldWrapperLeftRight(); getElement().<XElement>cast().addResizingTransitionEnd(this); }
From source file:com.brazoft.foundation.gwt.client.ui.Datepicker.java
License:Apache License
private void init(DateFormat format) { this.style().position(Position.RELATIVE); this.format = format; this.formatMobile = DateTimeFormat.getFormat("yyyy-MM-dd"); this.input = new TextBox(); this.add(this.input); this.editable(); if (MobileUtil.isMobileSafari()) { this.input.input().getElement().setAttribute("type", "date"); return;/*from ww w. j av a 2 s. co m*/ } this.input.onFocus(new FocusHandler() { @Override public void onFocus(FocusEvent event) { Datepicker.this.show(); } }); this.input.onBlur(new BlurHandler() { @Override public void onBlur(BlurEvent event) { if (Datepicker.this.panel.isSelected()) { return; } Datepicker.this.hide(); } }); this.panel = new MonthPanel(); this.panel.onSelection(new EventHandler<Date>() { @Override public void onEvent(Event<Date> e) { Datepicker.this.value(e.data()); Datepicker.this.hide(); } }).onNext(this.doFocus).onPrevious(this.doFocus); this.add(this.picker.add(this.panel)).hide(); }
From source file:com.dawg6.web.dhcalc.client.BaseSpinner.java
License:Open Source License
/** * @wbp.parser.constructor/*from w w w.java 2 s . c om*/ */ protected BaseSpinner(ValueBox<T> box, String text, T min, T max, T increment) { this.box = box; this.min = min; this.max = max; this.increment = increment; box.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { keyPressed(); } }); box.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { normalize(); } }); box.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { normalize(); } }); box.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { normalize(); } }); HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.setStyleName("spinner"); horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); initWidget(horizontalPanel); down = new Button(); down.setText("-"); down.setStyleName("spinnerDownButton"); horizontalPanel.add(down); down.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { increment(-1); } }); box.setStyleName("spinnerBox"); box.setText(text); horizontalPanel.add(box); box.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { BaseSpinner.this.box.selectAll(); } }); up = new Button(); up.setText("+"); up.setStyleName("spinnerUpButton"); horizontalPanel.add(up); up.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { increment(1); } }); }
From source file:com.dianaui.universal.core.client.ui.DateTimeBox.java
License:Apache License
public DateTimeBox(final DateTimeFormat format) { super(Document.get().createTextInputElement(), new DateTimeFormatRenderer(format), new DateTimeFormatParser(format)); addStyleName(Styles.FORM_CONTROL);/*from w w w.j av a 2s . c om*/ picker.addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { setValue(event.getValue(), true); } }); picker.addShownHandler(new ShownHandler() { @Override public void onShown(ShownEvent event) { int left = getAbsoluteLeft(); int top = getAbsoluteTop(); boolean showOnTop = false; if (position == PopupPosition.BOTTOM_CENTER) { left += (getOffsetWidth() - picker.getOffsetWidth()) / 2; } else if (position == PopupPosition.BOTTOM_RIGHT) { left += (getOffsetWidth() - picker.getOffsetWidth()); } else if (position == PopupPosition.TOP_LEFT) { showOnTop = true; } else if (position == PopupPosition.TOP_CENTER) { showOnTop = true; left += (getOffsetWidth() - picker.getOffsetWidth()) / 2; } else if (position == PopupPosition.TOP_RIGHT) { showOnTop = true; left += (getOffsetWidth() - picker.getOffsetWidth()); } if (showOnTop) { picker.getWidget(0).addStyleName(Styles.TOP); picker.getWidget(0).removeStyleName(Styles.BOTTOM); top -= picker.getOffsetHeight(); } else { picker.getWidget(0).addStyleName(Styles.BOTTOM); picker.getWidget(0).removeStyleName(Styles.TOP); top += getOffsetHeight(); } picker.setPosition(left, top); } }); addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { picker.show(); } }); addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) picker.hide(); } }); }
From source file:com.dianaui.universal.core.client.ui.gwt.RichTextArea.java
License:Apache License
public RichTextArea() { addStyleName(Styles.FORM_CONTROL);/*from w w w . j a va2 s . c o m*/ addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { removeStyleName("focus"); } }); addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { addStyleName("focus"); } }); }
From source file:com.dianaui.universal.core.client.ui.Popover.java
License:Apache License
private void activateTrigger() { if (inHandler != null) { inHandler.removeHandler();/*from w w w. j ava 2 s .c o m*/ } if (outHandler != null) { outHandler.removeHandler(); outHandler = null; } if (detachHandler != null) { detachHandler.removeHandler(); } if (trigger == Trigger.DEFAULT || trigger == Trigger.HOVER) { widget.sinkEvents(Event.ONMOUSEOVER); widget.sinkEvents(Event.ONMOUSEOUT); inHandler = widget.addHandler(new MouseOverHandler() { @Override public void onMouseOver(MouseOverEvent event) { show(); } }, MouseOverEvent.getType()); outHandler = widget.addHandler(new MouseOutHandler() { @Override public void onMouseOut(MouseOutEvent event) { hide(); } }, MouseOutEvent.getType()); } else if (trigger == Trigger.CLICK) { widget.sinkEvents(Event.ONCLICK); inHandler = widget.addHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { toggle(); } }, ClickEvent.getType()); } else if (trigger == Trigger.FOCUS) { widget.sinkEvents(Event.ONFOCUS); widget.sinkEvents(Event.ONBLUR); inHandler = widget.addHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { show(); } }, FocusEvent.getType()); outHandler = widget.addHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { hide(); } }, BlurEvent.getType()); } detachHandler = widget.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent event) { if (!event.isAttached()) { hide(); } } }); }
From source file:com.dianaui.universal.core.client.ui.TimeBox.java
License:Apache License
public TimeBox(DateTimeFormat format) { super(Document.get().createTextInputElement(), new DateTimeFormatRenderer(format), new DateTimeFormatParser(format)); addStyleName(Styles.FORM_CONTROL);/*w ww . jav a 2 s . c o m*/ picker.addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { setValue(event.getValue(), true); } }); picker.addShownHandler(new ShownHandler() { @Override public void onShown(ShownEvent event) { int left = getAbsoluteLeft(); int top = getAbsoluteTop(); boolean showOnTop = false; if (position == PopupPosition.BOTTOM_CENTER) { left += (getOffsetWidth() - picker.getOffsetWidth()) / 2; } else if (position == PopupPosition.BOTTOM_RIGHT) { left += (getOffsetWidth() - picker.getOffsetWidth()); } else if (position == PopupPosition.TOP_LEFT) { showOnTop = true; } else if (position == PopupPosition.TOP_CENTER) { showOnTop = true; left += (getOffsetWidth() - picker.getOffsetWidth()) / 2; } else if (position == PopupPosition.TOP_RIGHT) { showOnTop = true; left += (getOffsetWidth() - picker.getOffsetWidth()); } if (showOnTop) { picker.getWidget(0).addStyleName(Styles.TOP); picker.getWidget(0).removeStyleName(Styles.BOTTOM); top -= picker.getOffsetHeight(); } else { picker.getWidget(0).addStyleName(Styles.BOTTOM); picker.getWidget(0).removeStyleName(Styles.TOP); top += getOffsetHeight(); } picker.setPosition(left, top); } }); addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { picker.show(); } }); addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_TAB) picker.hide(); } }); }
From source file:com.eas.widgets.boxes.DateTimeBox.java
public DateTimeBox(DateTimePicker aPicker, Date date, DateBox.Format format) { initWidget(container);//w ww. j av a2s.c o m datePicker = aPicker; timePicker = aPicker.getTimePicker(); container.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); container.getElement().getStyle().setPosition(Style.Position.RELATIVE); container.getElement().addClassName("date-time-field"); field = new CustomDateBox(datePicker, date, format); field.setFireNullValues(true); field.setStyleName("form-control"); box = field.getTextBox(); box.getElement().getStyle().setOutlineStyle(Style.OutlineStyle.NONE); field.addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { Date newValue = event.getValue(); if (value == null ? newValue != null : !value.equals(newValue)) { value = newValue; timePicker.setValue(value, false); datePicker.setValue(value, false); ValueChangeEvent.fire(DateTimeBox.this, newValue); } } }); datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { Date datePart = event.getValue(); Date timePart = timePicker.getValue(); if (value == null && (new Date(0)).equals(timePart)) { Date currentTime = new Date(); Date currentDate = new Date(currentTime.getTime()); CalendarUtil.resetTime(currentDate); timePart = new Date(currentTime.getTime() - currentDate.getTime()); } Date newValue; if (timePart == null) { newValue = datePart; } else { newValue = new Date(datePart.getTime() + timePart.getTime()); } if (value == null ? newValue != null : !value.equals(newValue)) { value = newValue; field.setValue(value, false); timePicker.setValue(value, false); ValueChangeEvent.fire(DateTimeBox.this, newValue); } } }); timePicker.addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { Date timePart = timePicker.getValue(); Date datePart = field.getValue(); CalendarUtil.resetTime(datePart); value = new Date(datePart.getTime() + timePart.getTime()); field.setValue(value, false); datePicker.setValue(value, false); ValueChangeEvent.fire(DateTimeBox.this, value); } }); CommonResources.INSTANCE.commons().ensureInjected(); field.getElement().addClassName(CommonResources.INSTANCE.commons().borderSized()); field.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); field.getElement().getStyle().setPosition(Style.Position.ABSOLUTE); field.getElement().getStyle().setTop(0, Style.Unit.PX); field.getElement().getStyle().setHeight(100, Style.Unit.PCT); field.getElement().getStyle().setBottom(0, Style.Unit.PX); field.getElement().getStyle().setLeft(0, Style.Unit.PX); field.getElement().getStyle().setWidth(100, Style.Unit.PCT); field.getElement().getStyle().setMargin(0, Style.Unit.PX); field.getElement().getStyle().setBackgroundColor("inherit"); field.getElement().getStyle().setColor("inherit"); field.getElement().addClassName("date-time-box"); right.getElement().addClassName("date-select"); right.getElement().getStyle().setDisplay(Style.Display.INLINE_BLOCK); right.getElement().getStyle().setHeight(100, Style.Unit.PCT); right.getElement().getStyle().setPosition(Style.Position.RELATIVE); CommonResources.INSTANCE.commons().ensureInjected(); right.getElement().addClassName(CommonResources.INSTANCE.commons().unselectable()); popup.setStyleName("date-box-popup"); popup.setAutoHideEnabled(true); container.add(field); container.add(right); right.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (!isReadonly()) { datePicker.setCurrentMonth(value != null ? value : new Date()); popup.setWidget(datePicker); popup.showRelativeTo(right); } } }, ClickEvent.getType()); redecorate(); getElement().<XElement>cast().addResizingTransitionEnd(this); if (field.getTextBox() instanceof HasKeyDownHandlers) { ((HasKeyDownHandlers) field.getTextBox()).addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { KeyDownEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } if (field.getTextBox() instanceof HasKeyUpHandlers) { ((HasKeyUpHandlers) field.getTextBox()).addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { KeyUpEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } if (field.getTextBox() instanceof HasKeyPressHandlers) { ((HasKeyPressHandlers) field.getTextBox()).addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { KeyPressEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } if (field.getTextBox() instanceof HasFocusHandlers) { ((HasFocusHandlers) field.getTextBox()).addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { FocusEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } if (field.getTextBox() instanceof HasBlurHandlers) { ((HasBlurHandlers) field.getTextBox()).addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { BlurEvent.fireNativeEvent(event.getNativeEvent(), DateTimeBox.this); } }); } changeViewPresentation(); }