List of usage examples for org.joda.time YearMonth getMonthOfYear
public int getMonthOfYear()
From source file:org.vaadin.addons.tuningdatefield.InlineTuningDateField.java
License:Apache License
@Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); getState().setControlsEnabled(isControlsEnabled()); getState().setCalendarResolution(calendarResolution); if (calendarResolution.equals(CalendarResolution.DAY)) { YearMonth yearMonthDisplayed = getYearMonthDisplayed(); String displayedMonthText = monthTexts[yearMonthDisplayed.getMonthOfYear() - 1]; getState().setCalendarResolutionText(displayedMonthText + " " + yearMonthDisplayed.getYear()); getState().setWeekHeaderNames(weekDayNames); getState().setCalendarItems(buildDayItems()); } else if (calendarResolution.equals(CalendarResolution.MONTH)) { getState().setCalendarItems(buildMonthItems()); getState().setCalendarResolutionText(Integer.toString(yearMonthDisplayed.getYear())); } else if (calendarResolution.equals(CalendarResolution.YEAR)) { getState().setCalendarItems(buildYearItems()); getState().setCalendarResolutionText(getCalendarFirstYear() + " - " + getCalendarLastYear()); }//from w w w. ja v a 2 s . c o m }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
@Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); // For days of first week that are in previous month // Get first day of week of last week's previous month if (getValue() != null) { ((TuningDateFieldState) getState()).setDisplayedDateText(getValue()); } else {/* w ww . j av a 2s . c om*/ ((TuningDateFieldState) getState()).setDisplayedDateText(null); } ((TuningDateFieldState) getState()).setCalendarOpen(calendarOpen); ((TuningDateFieldState) getState()).setDateTextReadOnly(dateTextReadOnly); ((TuningDateFieldState) getState()).setOpenCalendarOnFocusEnabled(openCalendarOnFocusEnabled); // We send calendar state only if it's open if (calendarOpen) { ((TuningDateFieldState) getState()).setControlsEnabled(controlsEnabled); ((TuningDateFieldState) getState()).setCalendarResolution(calendarResolution); if (calendarResolution.equals(CalendarResolution.DAY)) { YearMonth yearMonthDisplayed = getYearMonthDisplayed(); String displayedMonthText = monthTexts[yearMonthDisplayed.getMonthOfYear() - 1]; ((TuningDateFieldState) getState()) .setCalendarResolutionText(displayedMonthText + " " + yearMonthDisplayed.getYear()); ((TuningDateFieldState) getState()).setWeekHeaderNames(weekDayNames); calendarItems = buildDayItems(); } else if (calendarResolution.equals(CalendarResolution.MONTH)) { calendarItems = buildMonthItems(); ((TuningDateFieldState) getState()) .setCalendarResolutionText(Integer.toString(yearMonthDisplayed.getYear())); } else if (calendarResolution.equals(CalendarResolution.YEAR)) { calendarItems = buildYearItems(); ((TuningDateFieldState) getState()) .setCalendarResolutionText(getCalendarFirstYear() + " - " + getCalendarLastYear()); } ((TuningDateFieldState) getState()).setCalendarItems(calendarItems); } }
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);//from w w w . j a va 2 s .c om 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; }