/** * Constructs a new <code>DateField</code> with the given caption and * initial text contents. The editor constructed this way will not be bound * to a Property unless * {@link Property.Viewer#setPropertyDataSource(Property)} is called to bind * it. * * @param caption * the caption <code>String</code> for the editor. * @param value * the Date value. */ public DateField(String caption, Date value) { setValue(value); setCaption(caption); }
@Override public void changeVariables(Object source, Map<String, Object> variables) { if (getValue() == null) { settingInitialValue = true; } super.changeVariables(source, variables); settingInitialValue = false; }
@Override public void addFocusListener(FocusListener listener) { addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener, FocusListener.focusMethod); }
if (!isReadOnly() && (variables.containsKey("year") || variables.containsKey("month") || variables.containsKey("day") || variables.containsKey("hour") final Date oldDate = getValue(); Date newDate = null; final Calendar cal = getCalendar(); && !"".equals(dateString)) { try { Date parsedDate = handleUnparsableDateString(dateString); setValue(parsedDate, true); markAsDirty(); } catch (Converter.ConversionException e) { setValue(null); } finally { preventValueChangeEvent = false; fireValueChange(false); notifyFormOfValidityChange(); markAsDirty(); setValue(newDate, true); } else if (!uiHasValidDateString) { // oldDate ==
private void updateValue(boolean nullTheValue) { if (nullTheValue) { fromField.setValue(null); toField.setValue(null); } else { cancelReset = true; } /* Truncate the from and to dates */ Resolution res = decorator != null ? decorator.getDateFieldResolution(propertyId) : DEFAULT_RESOLUTION; if (res == null) { res = DEFAULT_RESOLUTION; } fromValue = truncateDate(fromField.getValue(), res, true); toValue = truncateDate(toField.getValue(), res, false); setValue(new DateInterval(fromValue, toValue)); DateFilterPopup.this.content.setPopupVisible(false); }
final Locale l = getLocale(); if (l != null) { target.addAttribute("locale", l.toString()); if (getDateFormat() != null) { target.addAttribute("format", dateFormat); if (!isLenient()) { target.addAttribute("strict", true); isShowISOWeekNumbers()); target.addAttribute("parsable", uiHasValidDateString); final Calendar calendar = getCalendar(); final Date currentDate = getValue();
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); if (design.hasAttr("value") && !design.attr("value").isEmpty()) { Date date = DesignAttributeHandler.getFormatter() .parse(design.attr("value"), Date.class); // formatting will return null if it cannot parse the string if (date == null) { Logger.getLogger(DateField.class.getName()).info( "cannot parse " + design.attr("value") + " as date"); } this.setValue(date, false, true); } }
fromField.setLocale(getLocaleFailsafe()); toField.setLocale(getLocaleFailsafe()); fromField.setCaption(fromCaption); toField.setCaption(toCaption); set.setCaption(setCaption); clear.setCaption(clearCaption); fromField.setResolution(resolution); toField.setResolution(resolution); fromField.setDateFormat(dateFormatPattern); toField.setDateFormat(dateFormatPattern);
final TimeZone currentTimeZone = getTimeZone(); if (currentTimeZone != null) { newCal.setTimeZone(currentTimeZone); final Date currentDate = getValue(); if (currentDate != null) { newCal.setTime(currentDate);
final DateField df = new DateField(); df.setResolution(DateField.RESOLUTION_DAY); return df;
private void updateCaption(boolean nullTheCaption) { if (nullTheCaption) { if (decorator != null && decorator.getAllItemsVisibleString() != null) { content.setCaption(decorator.getAllItemsVisibleString()); } else { content.setCaption(null); } } else { SimpleDateFormat sdf = new SimpleDateFormat(dateFormatPattern); content.setCaption((fromField.getValue() == null ? "" : sdf.format(fromField.getValue())) + " - " + (toField.getValue() == null ? "" : sdf.format(toField.getValue()))); } }
/** * Constructs an empty <code>DateField</code> with caption. * * @param caption * the caption of the datefield. */ public DateField(String caption) { setCaption(caption); }
@Override protected Component initContent() { if (content == null) { content = new PopupButton(null); content.setWidth(100, Unit.PERCENTAGE); setImmediate(true); buildPopup(); setStyleName("datefilterpopup"); setFilterDecorator(decorator); updateCaption(true); content.addPopupVisibilityListener(event -> { if (cancelReset || event.getPopupButton().isPopupVisible()) { fromValue = fromField.getValue(); toValue = toField.getValue(); cancelReset = false; return; } fromField.setValue(fromValue); toField.setValue(toValue); cancelReset = false; }); } return content; }
@Override public void setValue(DateInterval newFieldValue) throws com.vaadin.v7.data.Property.ReadOnlyException, ConversionException { if (newFieldValue == null) { newFieldValue = new DateInterval(null, null); } fromField.setValue(newFieldValue.getFrom()); toField.setValue(newFieldValue.getTo()); super.setValue(newFieldValue); updateCaption(newFieldValue.isNull()); }
/** * Constructs a new <code>DateField</code> that's bound to the specified * <code>Property</code> and has the given caption <code>String</code>. * * @param caption * the caption <code>String</code> for the editor. * @param dataSource * the Property to be edited with this editor. */ public DateField(String caption, Property dataSource) { this(dataSource); setCaption(caption); }
@Override protected void setValue(Date newValue, boolean repaintIsNotNeeded) throws ReadOnlyException { if (settingInitialValue && getResolution().ordinal() > Resolution.HOUR.ordinal()) { if (getInitialTimeMode() == InitialTimeMode.START_OF_DAY) { newValue.setHours(0); newValue.setMinutes(0); newValue.setSeconds(0); newValue.setTime( newValue.getTime() - newValue.getTime() % 1000l); } else if (getInitialTimeMode() == InitialTimeMode.END_OF_DAY) { newValue.setHours(23); newValue.setMinutes(59); newValue.setSeconds(59); newValue.setTime( newValue.getTime() - newValue.getTime() % 1000l + 999l); } } super.setValue(newValue, repaintIsNotNeeded); }
/** * Simulates receiving a date change from the client, via #changeVariables instead of #setValue (performs additional conversions) */ protected static void enterDate(DateField field, int year, Month month, int dayOfMonth, int hour, int minute) { field.changeVariables(null, ImmutableMap.of( "year", year, "month", month.getValue(), "day", dayOfMonth, "hour", hour, "min", minute)); }
@Override public void addBlurListener(BlurListener listener) { addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener, BlurListener.blurMethod); }
@Test public void validationFailsIfRequiredFieldIsEmpty() throws Exception { // GIVEN dateFieldDefinition.setRequired(true); createField(); DateField dateField = getSubFieldWithType(DateField.class); dateField.setValue(null); // WHEN boolean isValid = compositeField.isValid(); // THEN assertFalse(isValid); }