From 3ef30789d6ac773eed7346dcaa670426fa6f662c Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 10 Jan 2017 12:22:34 +0200 Subject: Refactor AbstractDateField. (#8146) First round for #8132. --- .../ui/datefield/AbstractDateFieldState.java | 48 +++++++++++++++ .../datefield/AbstractTextualDateFieldState.java | 26 +++++++++ .../vaadin/shared/ui/datefield/DateFieldState.java | 34 ----------- .../vaadin/shared/ui/datefield/DateResolution.java | 68 ++++++++++++++++++++++ .../shared/ui/datefield/DateTimeResolution.java | 27 +++++++++ .../shared/ui/datefield/InlineDateFieldState.java | 2 +- .../shared/ui/datefield/LocalDateFieldState.java | 26 +++++++++ .../ui/datefield/LocalDateTimeFieldState.java | 26 +++++++++ .../com/vaadin/shared/ui/datefield/Resolution.java | 67 --------------------- .../shared/ui/datefield/TextualDateFieldState.java | 23 +++----- 10 files changed, 230 insertions(+), 117 deletions(-) create mode 100644 shared/src/main/java/com/vaadin/shared/ui/datefield/AbstractDateFieldState.java create mode 100644 shared/src/main/java/com/vaadin/shared/ui/datefield/AbstractTextualDateFieldState.java delete mode 100644 shared/src/main/java/com/vaadin/shared/ui/datefield/DateFieldState.java create mode 100644 shared/src/main/java/com/vaadin/shared/ui/datefield/DateResolution.java create mode 100644 shared/src/main/java/com/vaadin/shared/ui/datefield/DateTimeResolution.java create mode 100644 shared/src/main/java/com/vaadin/shared/ui/datefield/LocalDateFieldState.java create mode 100644 shared/src/main/java/com/vaadin/shared/ui/datefield/LocalDateTimeFieldState.java delete mode 100644 shared/src/main/java/com/vaadin/shared/ui/datefield/Resolution.java (limited to 'shared') diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/AbstractDateFieldState.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/AbstractDateFieldState.java new file mode 100644 index 0000000000..12a0ebd367 --- /dev/null +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/AbstractDateFieldState.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.datefield; + +import java.util.Date; + +import com.vaadin.shared.AbstractFieldState; +import com.vaadin.shared.annotations.NoLayout; + +/** + * Shared state for the AbstractDateField component. + * + * @author Vaadin Ltd + * + */ +public class AbstractDateFieldState extends AbstractFieldState { + + { + primaryStyleName = "v-datefield"; + } + + /* + * Start range that has been cleared, depending on the resolution of the + * date field + */ + @NoLayout + public Date rangeStart = null; + + /* + * End range that has been cleared, depending on the resolution of the date + * field + */ + @NoLayout + public Date rangeEnd = null; +} diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/AbstractTextualDateFieldState.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/AbstractTextualDateFieldState.java new file mode 100644 index 0000000000..843c453f39 --- /dev/null +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/AbstractTextualDateFieldState.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.datefield; + +/** + * Shared state for the AbstractLocalDateField component. + * + * @author Vaadin Ltd + * + */ +public class AbstractTextualDateFieldState extends AbstractDateFieldState { + +} diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/DateFieldState.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/DateFieldState.java deleted file mode 100644 index 4566096e9a..0000000000 --- a/shared/src/main/java/com/vaadin/shared/ui/datefield/DateFieldState.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.shared.ui.datefield; - -import com.vaadin.shared.annotations.DelegateToWidget; -import com.vaadin.shared.annotations.NoLayout; - -public class DateFieldState extends TextualDateFieldState { - public static final String DESCRIPTION_FOR_ASSISTIVE_DEVICES = "Arrow down key opens calendar element for choosing the date"; - - { - primaryStyleName = "v-datefield"; - } - - public boolean textFieldEnabled = true; - @NoLayout - public String descriptionForAssistiveDevices = DESCRIPTION_FOR_ASSISTIVE_DEVICES; - @NoLayout - @DelegateToWidget - public String placeholder = null; -} diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/DateResolution.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/DateResolution.java new file mode 100644 index 0000000000..ce2871e0a7 --- /dev/null +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/DateResolution.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.datefield; + +import java.util.ArrayList; +import java.util.List; + +/** + * Resolutions for DateFields + * + * @author Vaadin Ltd. + * @since 7.0 + */ +public enum DateResolution { + DAY, MONTH, YEAR; + + /** + * Returns the resolutions that are higher or equal to the given resolution, + * starting from the given resolution. In other words passing DAY to this + * methods returns DAY,MONTH,YEAR + * + * @param r + * The resolution to start from + * @return An iterable for the resolutions higher or equal to r + */ + public static Iterable getResolutionsHigherOrEqualTo( + DateResolution r) { + List resolutions = new ArrayList<>(); + DateResolution[] values = DateResolution.values(); + for (int i = r.ordinal(); i < values.length; i++) { + resolutions.add(values[i]); + } + return resolutions; + } + + /** + * Returns the resolutions that are lower than the given resolution, + * starting from the given resolution. In other words passing DAY to this + * methods returns HOUR,MINUTE,SECOND. + * + * @param r + * The resolution to start from + * @return An iterable for the resolutions lower than r + */ + public static List getResolutionsLowerThan( + DateResolution r) { + List resolutions = new ArrayList<>(); + DateResolution[] values = DateResolution.values(); + for (int i = r.ordinal() - 1; i >= 0; i--) { + resolutions.add(values[i]); + } + return resolutions; + } + +} diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/DateTimeResolution.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/DateTimeResolution.java new file mode 100644 index 0000000000..7876fb51f4 --- /dev/null +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/DateTimeResolution.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.datefield; + +/** + * Resolutions for DateTimeFields + * + * @author Vaadin Ltd. + * @since 8.0 + */ +public enum DateTimeResolution { + SECOND, MINUTE, HOUR, DAY, MONTH, YEAR; + +} diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/InlineDateFieldState.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/InlineDateFieldState.java index da0fe14a29..42c21b9376 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/datefield/InlineDateFieldState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/InlineDateFieldState.java @@ -15,7 +15,7 @@ */ package com.vaadin.shared.ui.datefield; -public class InlineDateFieldState extends TextualDateFieldState { +public class InlineDateFieldState extends AbstractTextualDateFieldState { { primaryStyleName = "v-inline-datefield"; } diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/LocalDateFieldState.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/LocalDateFieldState.java new file mode 100644 index 0000000000..fdfea3eab6 --- /dev/null +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/LocalDateFieldState.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.datefield; + +/** + * Shared state for the DateField component. + * + * @author Vaadin Ltd + * + */ +public class LocalDateFieldState extends TextualDateFieldState { + +} diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/LocalDateTimeFieldState.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/LocalDateTimeFieldState.java new file mode 100644 index 0000000000..cb439dd1a8 --- /dev/null +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/LocalDateTimeFieldState.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.datefield; + +/** + * Shared state for the DateTimeField component. + * + * @author Vaadin Ltd + * + */ +public class LocalDateTimeFieldState extends AbstractTextualDateFieldState { + +} diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/Resolution.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/Resolution.java deleted file mode 100644 index 0fc5da4803..0000000000 --- a/shared/src/main/java/com/vaadin/shared/ui/datefield/Resolution.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.shared.ui.datefield; - -import java.util.ArrayList; -import java.util.List; - -/** - * Resolutions for DateFields - * - * @author Vaadin Ltd. - * @since 7.0 - */ -public enum Resolution { - DAY, MONTH, YEAR; - - /** - * Returns the resolutions that are higher or equal to the given resolution, - * starting from the given resolution. In other words passing DAY to this - * methods returns DAY,MONTH,YEAR - * - * @param r - * The resolution to start from - * @return An iterable for the resolutions higher or equal to r - */ - public static Iterable getResolutionsHigherOrEqualTo( - Resolution r) { - List resolutions = new ArrayList<>(); - Resolution[] values = Resolution.values(); - for (int i = r.ordinal(); i < values.length; i++) { - resolutions.add(values[i]); - } - return resolutions; - } - - /** - * Returns the resolutions that are lower than the given resolution, - * starting from the given resolution. In other words passing DAY to this - * methods returns HOUR,MINUTE,SECOND. - * - * @param r - * The resolution to start from - * @return An iterable for the resolutions lower than r - */ - public static List getResolutionsLowerThan(Resolution r) { - List resolutions = new ArrayList<>(); - Resolution[] values = Resolution.values(); - for (int i = r.ordinal() - 1; i >= 0; i--) { - resolutions.add(values[i]); - } - return resolutions; - } - -} diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/TextualDateFieldState.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/TextualDateFieldState.java index ae0ec560e0..fa5c0ac8be 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/datefield/TextualDateFieldState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/TextualDateFieldState.java @@ -15,27 +15,20 @@ */ package com.vaadin.shared.ui.datefield; -import java.util.Date; - -import com.vaadin.shared.AbstractFieldState; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.annotations.NoLayout; -public class TextualDateFieldState extends AbstractFieldState { +public class TextualDateFieldState extends AbstractTextualDateFieldState { + public static final String DESCRIPTION_FOR_ASSISTIVE_DEVICES = "Arrow down key opens calendar element for choosing the date"; + { primaryStyleName = "v-datefield"; } - /* - * Start range that has been cleared, depending on the resolution of the - * date field - */ + public boolean textFieldEnabled = true; @NoLayout - public Date rangeStart = null; - - /* - * End range that has been cleared, depending on the resolution of the date - * field - */ + public String descriptionForAssistiveDevices = DESCRIPTION_FOR_ASSISTIVE_DEVICES; @NoLayout - public Date rangeEnd = null; + @DelegateToWidget + public String placeholder = null; } -- cgit v1.2.3