Skip to content

Commit

Permalink
Introduce DateTimeFile and InlineDateTimeField. (#8218)
Browse files Browse the repository at this point in the history
* Introduce DateTimeFile and InlineDateTimeField.

Fixes #8132

* Correct and provide declarative tests.

* Provide a date converter and UI tests.
  • Loading branch information
Denis committed Jan 19, 2017
1 parent dafc831 commit f42b965
Show file tree
Hide file tree
Showing 70 changed files with 3,728 additions and 86 deletions.
Expand Up @@ -421,11 +421,21 @@ public void setResolution(R resolution) {
this.resolution = resolution;
}

private boolean isReadonly() {
/**
* Checks whether the widget is not editable (read-only).
*
* @return {@code true} if the widget is read-only
*/
protected boolean isReadonly() {
return parent.isReadonly();
}

private boolean isEnabled() {
/**
* Checks whether the widget is enabled.
*
* @return {@code true} is the widget is enabled
*/
protected boolean isEnabled() {
return parent.isEnabled();
}

Expand Down Expand Up @@ -583,10 +593,26 @@ private void updateControlButtonRangeStyles(boolean needsMonth) {

}

private DateTimeService getDateTimeService() {
/**
* Returns date time service for the widget.
*
* @see #setDateTimeService(DateTimeService)
*
* @return date time service
*/
protected DateTimeService getDateTimeService() {
return dateTimeService;
}

/**
* Returns the date field which this panel is attached to.
*
* @return the "parent" date field
*/
protected VDateField<R> getDateField() {
return parent;
}

public void setDateTimeService(DateTimeService dateTimeService) {
this.dateTimeService = dateTimeService;
}
Expand Down Expand Up @@ -721,7 +747,7 @@ private void buildCalendarBody() {
setCellSpacing(0);
getFlexCellFormatter().setColSpan(1, 0, 5);
getFlexCellFormatter().setStyleName(1, 0,
parent.getStylePrimaryName() + "-calendarpanel-body");
getDateField().getStylePrimaryName() + "-calendarpanel-body");

days.getFlexCellFormatter().setStyleName(headerRow, weekColumn,
"v-week");
Expand All @@ -731,15 +757,16 @@ private void buildCalendarBody() {
isShowISOWeekNumbers());

days.getRowFormatter().setStyleName(headerRow,
parent.getStylePrimaryName() + "-calendarpanel-weekdays");
getDateField().getStylePrimaryName()
+ "-calendarpanel-weekdays");

if (isShowISOWeekNumbers()) {
days.getFlexCellFormatter().setStyleName(headerRow, weekColumn,
"v-first");
days.getFlexCellFormatter().setStyleName(headerRow,
firstWeekdayColumn, "");
days.getRowFormatter().addStyleName(headerRow,
parent.getStylePrimaryName()
getDateField().getStylePrimaryName()
+ "-calendarpanel-weeknumbers");
} else {
days.getFlexCellFormatter().setStyleName(headerRow, weekColumn, "");
Expand Down Expand Up @@ -792,8 +819,8 @@ private void buildCalendarBody() {
Date dayDate = (Date) curr.clone();
Day day = new Day(dayDate);

day.setStyleName(
parent.getStylePrimaryName() + "-calendarpanel-day");
day.setStyleName(getDateField().getStylePrimaryName()
+ "-calendarpanel-day");

if (!isDateInsideRange(dayDate, getResolution(this::isDay))) {
day.addStyleDependentName(CN_OUTSIDE_RANGE);
Expand Down Expand Up @@ -828,7 +855,8 @@ private void buildCalendarBody() {
isShowISOWeekNumbers());

if (isShowISOWeekNumbers()) {
final String baseCssClass = parent.getStylePrimaryName()
final String baseCssClass = getDateField()
.getStylePrimaryName()
+ "-calendarpanel-weeknumber";
String weekCssClass = baseCssClass;

Expand Down Expand Up @@ -880,7 +908,7 @@ public void renderCalendar(boolean updateDate) {
*/
protected void doRenderCalendar(boolean updateDate) {
super.setStylePrimaryName(
parent.getStylePrimaryName() + "-calendarpanel");
getDateField().getStylePrimaryName() + "-calendarpanel");

if (focusedDate == null) {
Date now = new Date();
Expand All @@ -896,7 +924,7 @@ protected void doRenderCalendar(boolean updateDate) {
}

final boolean needsMonth = !isYear(getResolution());
boolean needsBody = isDay(getResolution());
boolean needsBody = isBelowMonth(resolution);
buildCalendarHeader(needsMonth);
clearCalendarBody(!needsBody);
if (needsBody) {
Expand Down Expand Up @@ -1976,8 +2004,8 @@ public void setYear(int year) {
}

private void setLabel() {
if (parent instanceof VAbstractPopupCalendar) {
((VAbstractPopupCalendar) parent).setFocusedDate(this);
if (getDateField() instanceof VAbstractPopupCalendar) {
((VAbstractPopupCalendar) getDateField()).setFocusedDate(this);
}
}
}
Expand Down
Expand Up @@ -23,14 +23,13 @@
/**
* A client side implementation for inline date field.
*/
public abstract class VAbstractDateFieldCalendar<R extends Enum<R>>
public abstract class VAbstractDateFieldCalendar<PANEL extends VAbstractCalendarPanel<R>, R extends Enum<R>>
extends VDateField<R> {

/** For internal use only. May be removed or replaced in the future. */
public final VAbstractCalendarPanel<R> calendarPanel;
public final PANEL calendarPanel;

public VAbstractDateFieldCalendar(VAbstractCalendarPanel<R> panel,
R resolution) {
public VAbstractDateFieldCalendar(PANEL panel, R resolution) {
super(resolution);
calendarPanel = panel;
calendarPanel.setParentField(this);
Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.vaadin.client.ui;

import java.util.Date;
import java.util.Locale;

import com.google.gwt.aria.client.Id;
import com.google.gwt.aria.client.LiveValue;
Expand Down Expand Up @@ -63,15 +62,15 @@
* <code>setCalendarPanel(VAbstractCalendarPanel panel)</code> method.
*
*/
public abstract class VAbstractPopupCalendar<R extends Enum<R>>
public abstract class VAbstractPopupCalendar<PANEL extends VAbstractCalendarPanel<R>, R extends Enum<R>>
extends VAbstractTextualDate<R>
implements Field, ClickHandler, CloseHandler<PopupPanel>, SubPartAware {

/** For internal use only. May be removed or replaced in the future. */
public final Button calendarToggle = new Button();

/** For internal use only. May be removed or replaced in the future. */
public VAbstractCalendarPanel<R> calendar;
public PANEL calendar;

/** For internal use only. May be removed or replaced in the future. */
public final VOverlay popup;
Expand Down Expand Up @@ -100,8 +99,7 @@ public abstract class VAbstractPopupCalendar<R extends Enum<R>>

private final String CALENDAR_TOGGLE_ID = "popupButton";

public VAbstractPopupCalendar(VAbstractCalendarPanel<R> calendarPanel,
R resolution) {
public VAbstractPopupCalendar(PANEL calendarPanel, R resolution) {
super(resolution);

calendarToggle.setText("");
Expand Down Expand Up @@ -230,8 +228,7 @@ public void updateValue(Date newDate) {
if (!calendar.isYear(getCurrentResolution())) {
getClient().updateVariable(getId(),
getResolutionVariable(
calendar.getResolution(calendar::isMonth))
.toLowerCase(Locale.ENGLISH),
calendar.getResolution(calendar::isMonth)),
newDate.getMonth() + 1, false);
if (!calendar.isMonth(getCurrentResolution())) {
getClient().updateVariable(getId(),
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/java/com/vaadin/client/ui/VDateField.java
Expand Up @@ -230,11 +230,11 @@ public Stream<R> getResolutions() {
*
* @see #setCurrentDate(Map)
*
* @param dateVaules
* @param dateValues
* a map with date values to convert into a date
* @return the date based on the dateValues map
*/
protected abstract Date getDate(Map<R, Integer> dateVaules);
protected abstract Date getDate(Map<R, Integer> dateValues);

/**
* Returns all available resolutions as an array.
Expand Down
Expand Up @@ -28,7 +28,7 @@
*
*/
public class VDateFieldCalendar
extends VAbstractDateFieldCalendar<DateResolution> {
extends VAbstractDateFieldCalendar<VDateCalendarPanel, DateResolution> {

public VDateFieldCalendar() {
super(GWT.create(VDateCalendarPanel.class), DateResolution.YEAR);
Expand Down

0 comments on commit f42b965

Please sign in to comment.