List of usage examples for org.joda.time YearMonth now
public static YearMonth now()
ISOChronology
in the default time zone. From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
private void init() { setupLocaleBasedStaticData(getLocale()); initConverter();//from w w w . j a va 2 s . co m setYearMonthDisplayed(YearMonth.now()); registerRpc(); addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = -8632906562585439165L; @Override public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) { fireEvent(new DateChangeEvent(TuningDateField.this, (LocalDate) getConvertedValue())); } }); }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
protected CalendarItem[] buildMonthItems() { YearMonth calendarFirstMonth = getCalendarFirstMonth(); YearMonth calendarLastMonth = getCalendarLastMonth(); YearMonth currentMonth = YearMonth.now(); int numberOfMonths = Months.monthsBetween(calendarFirstMonth, calendarLastMonth).getMonths() + 1; CalendarItem[] calendarItems = new CalendarItem[numberOfMonths]; YearMonth month = calendarFirstMonth; LocalDate currentValue = getLocalDate(); YearMonth currentYearMonthValue = currentValue == null ? null : new YearMonth(currentValue.getYear(), currentValue.getMonthOfYear()); for (int i = 0; i < numberOfMonths; i++, month = month.plusMonths(1)) { calendarItems[i] = new CalendarItem(); calendarItems[i].setIndex(i);/* w w w.j a v a 2 s .com*/ calendarItems[i].setRelativeDateIndex(month.getMonthOfYear()); calendarItems[i].setEnabled(true); // By default StringBuilder style = new StringBuilder(""); if (month.equals(currentMonth)) { style.append("currentmonth "); } if (currentYearMonthValue != null && month.equals(currentYearMonthValue)) { style.append("selected "); } if (cellItemCustomizer != null) { String generatedStyle = cellItemCustomizer.getStyle(month, this); if (generatedStyle != null) { style.append(generatedStyle); style.append(" "); } String tooltip = cellItemCustomizer.getTooltip(month, this); if (tooltip != null) { calendarItems[i].setTooltip(tooltip); } } if (isMonthEnabled(month)) { calendarItems[i].setEnabled(true); } String computedStyle = style.toString(); if (!computedStyle.isEmpty()) { calendarItems[i].setStyle(computedStyle); } String calendarItemContent = null; if (cellItemCustomizer != null) { calendarItemContent = cellItemCustomizer.renderMonth(currentYearMonthValue, this); } // fallback to default value if (calendarItemContent == null) { calendarItemContent = shortMonthTexts[i]; } calendarItems[i].setText(calendarItemContent); } return calendarItems; }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
protected CalendarItem[] buildYearItems() { int calendarFirstYear = getCalendarFirstYear(); int calendarLastYear = getCalendarLastYear(); int currentYear = YearMonth.now().getYear(); int numberOfYears = calendarLastYear - calendarFirstYear + 1; CalendarItem[] calendarItems = new CalendarItem[numberOfYears]; int year = calendarFirstYear; LocalDate currentValue = getLocalDate(); Integer currentYearValue = currentValue == null ? null : currentValue.getYear(); for (int i = 0; i < numberOfYears; i++, year++) { calendarItems[i] = new CalendarItem(); calendarItems[i].setIndex(i);//w w w. java2s . c om calendarItems[i].setRelativeDateIndex(year); calendarItems[i].setEnabled(true); StringBuilder style = new StringBuilder(""); if (year == currentYear) { style.append("currentyear "); } if (currentYearValue != null && year == currentYearValue) { style.append("selected "); } if (isYearEnabled(year)) { calendarItems[i].setEnabled(true); } if (cellItemCustomizer != null) { String generatedStyle = cellItemCustomizer.getStyle(year, this); if (generatedStyle != null) { style.append(generatedStyle); style.append(" "); } String tooltip = cellItemCustomizer.getTooltip(year, this); if (tooltip != null) { calendarItems[i].setTooltip(tooltip); } } String computedStyle = style.toString(); if (!computedStyle.isEmpty()) { calendarItems[i].setStyle(computedStyle); } String calendarItemContent = null; if (cellItemCustomizer != null) { calendarItemContent = cellItemCustomizer.renderYear(year, this); } // fallback to default value if (calendarItemContent == null) { calendarItemContent = Integer.toString(year); } calendarItems[i].setText(calendarItemContent); } return calendarItems; }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
/** * Called when the calendar is open on client-side *//*from w w w. j a v a 2 s.c o m*/ private void onCalendarOpen() { calendarResolution = CalendarResolution.DAY; LocalDate currentValue = getLocalDate(); if (currentValue != null) { yearMonthDisplayed = new YearMonth(currentValue); } else if (yearMonthDisplayed == null) { yearMonthDisplayed = YearMonth.now(); } fireEvent(new CalendarOpenEvent(this, yearMonthDisplayed)); calendarOpen = true; markAsDirty(); }