From 960c742571e118ed67ac2fcea72ab6dfa922f3c9 Mon Sep 17 00:00:00 2001 From: Rishiraj Anand Date: Tue, 30 Apr 2019 14:09:14 +0530 Subject: [PATCH] Added Clear Button in DatePicker and DateTimePicker --- .../client/ui/base/DatePickerBase.java | 15 +++++++-- .../ui/base/constants/HasShowClearButton.java | 33 +++++++++++++++++++ .../client/ui/base/DateTimePickerBase.java | 26 ++++++++++----- .../ui/base/constants/HasShowClearButton.java | 33 +++++++++++++++++++ 4 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 src/main/java/org/gwtbootstrap3/extras/datepicker/client/ui/base/constants/HasShowClearButton.java create mode 100644 src/main/java/org/gwtbootstrap3/extras/datetimepicker/client/ui/base/constants/HasShowClearButton.java diff --git a/src/main/java/org/gwtbootstrap3/extras/datepicker/client/ui/base/DatePickerBase.java b/src/main/java/org/gwtbootstrap3/extras/datepicker/client/ui/base/DatePickerBase.java index 3bbf00cc..0851f2eb 100644 --- a/src/main/java/org/gwtbootstrap3/extras/datepicker/client/ui/base/DatePickerBase.java +++ b/src/main/java/org/gwtbootstrap3/extras/datepicker/client/ui/base/DatePickerBase.java @@ -61,6 +61,7 @@ import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasMinView; import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasPosition; import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasShowTodayButton; +import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasShowClearButton; import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasStartDate; import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasStartView; import org.gwtbootstrap3.extras.datepicker.client.ui.base.constants.HasViewSelect; @@ -99,7 +100,7 @@ */ public class DatePickerBase extends Widget implements HasEnabled, HasId, HasResponsiveness, HasVisibility, HasPlaceholder, HasAutoClose, HasDaysOfWeekDisabled, HasEndDate, HasForceParse, HasFormat, HasHighlightToday, HasKeyboardNavigation, - HasMinView, HasShowTodayButton, HasStartDate, HasStartView, HasViewSelect, HasWeekStart, HasDateTimePickerHandlers, + HasMinView, HasShowTodayButton, HasShowClearButton, HasStartDate, HasStartView, HasViewSelect, HasWeekStart, HasDateTimePickerHandlers, HasLanguage, HasName, HasValue, HasPosition, LeafValueEditor, HasEditorErrors, HasErrorHandler, HasValidators, HasBlankValidator { @@ -154,6 +155,7 @@ public void onBlur(BlurEvent event) { private DatePickerMinView minView = DatePickerMinView.DAY; private boolean showTodayButton = false; + private boolean showClearButton = false; private boolean highlightToday = false; private boolean keyboardNavigation = true; private boolean forceParse = true; @@ -446,6 +448,12 @@ public void setShowTodayButton(final boolean showTodayButton) { this.showTodayButton = showTodayButton; } + /** {@inheritDoc} */ + @Override + public void setShowClearButton(boolean showClearbutton) { + this.showClearButton = showClearbutton; + } + /** {@inheritDoc} */ @Override public void setStartDate(final Date startDate) { @@ -649,7 +657,7 @@ protected void configure(final Widget w, final Widget container) { this.remove(w.getElement()); configure(w.getElement(), container.getElement(), format, weekStart.getValue(), toDaysOfWeekDisabledString(daysOfWeekDisabled), autoClose, - startView.getValue(), minView.getValue(), showTodayButton, highlightToday, keyboardNavigation, forceParse, viewSelect.getValue(), + startView.getValue(), minView.getValue(), showTodayButton, showClearButton, highlightToday, keyboardNavigation, forceParse, viewSelect.getValue(), language.getCode(), position.getPosition()); } @@ -696,7 +704,7 @@ private native void setDaysOfWeekDisabled(Element e, String daysOfWeekDisabled) }-*/; protected native void configure(Element e, Element p, String format, int weekStart, String daysOfWeekDisabled, boolean autoClose, int startView, - int minViewMode, boolean todayBtn, boolean highlightToday, boolean keyboardNavigation, boolean forceParse, int viewSelect, String language, + int minViewMode, boolean todayBtn, boolean clearBtn, boolean highlightToday, boolean keyboardNavigation, boolean forceParse, int viewSelect, String language, String orientation) /*-{ if (todayBtn) { @@ -713,6 +721,7 @@ protected native void configure(Element e, Element p, String format, int weekSta startView: startView, minViewMode: minViewMode, todayBtn: todayBtn, + clearBtn: clearBtn, todayHighlight: highlightToday, keyboardNavigation: keyboardNavigation, forceParse: forceParse, diff --git a/src/main/java/org/gwtbootstrap3/extras/datepicker/client/ui/base/constants/HasShowClearButton.java b/src/main/java/org/gwtbootstrap3/extras/datepicker/client/ui/base/constants/HasShowClearButton.java new file mode 100644 index 00000000..6ea42252 --- /dev/null +++ b/src/main/java/org/gwtbootstrap3/extras/datepicker/client/ui/base/constants/HasShowClearButton.java @@ -0,0 +1,33 @@ +package org.gwtbootstrap3.extras.datepicker.client.ui.base.constants; + +/* + * #%L + * GwtBootstrap3 + * %% + * Copyright (C) 2013 - 2014 GwtBootstrap3 + * %% + * 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. + * #L% + */ + +/** + * Boolean, Default: false + *

+ * If true, displays a clear button at the bottom of the datepicker to clear the selected date. + * If true, the "Clear" button will clear the currently selected date from the datepicker; + * + * @author Rishiraj Anand + */ +public interface HasShowClearButton { + void setShowClearButton(boolean showClearButton); +} diff --git a/src/main/java/org/gwtbootstrap3/extras/datetimepicker/client/ui/base/DateTimePickerBase.java b/src/main/java/org/gwtbootstrap3/extras/datetimepicker/client/ui/base/DateTimePickerBase.java index e07f5429..d751b680 100644 --- a/src/main/java/org/gwtbootstrap3/extras/datetimepicker/client/ui/base/DateTimePickerBase.java +++ b/src/main/java/org/gwtbootstrap3/extras/datetimepicker/client/ui/base/DateTimePickerBase.java @@ -66,6 +66,7 @@ import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasPosition; import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasShowMeridian; import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasShowTodayButton; +import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasShowClearButton; import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasStartDate; import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasStartView; import org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants.HasViewSelect; @@ -103,7 +104,7 @@ */ public class DateTimePickerBase extends Widget implements HasEnabled, HasReadOnly, HasId, HasResponsiveness, HasVisibility, HasPlaceholder, HasAutoClose, HasDaysOfWeekDisabled, HasEndDate, HasForceParse, HasFormat, HasHighlightToday, - HasKeyboardNavigation, HasMaxView, HasMinuteStep, HasMinView, HasShowMeridian, HasShowTodayButton, HasStartDate, + HasKeyboardNavigation, HasMaxView, HasMinuteStep, HasMinView, HasShowMeridian, HasShowTodayButton, HasShowClearButton, HasStartDate, HasStartView, HasViewSelect, HasWeekStart, HasDateTimePickerHandlers, HasLanguage, HasName, HasValue, HasPosition, LeafValueEditor, HasEditorErrors, HasErrorHandler, HasValidators, HasBlankValidator { @@ -149,7 +150,7 @@ public void onBlur(BlurEvent event) { private LeafValueEditor editor; private final ErrorHandlerMixin errorHandlerMixin = new ErrorHandlerMixin(this); private final DatePickerValidatorMixin validatorMixin = new DatePickerValidatorMixin(this, - errorHandlerMixin.getErrorHandler()); + errorHandlerMixin.getErrorHandler()); /** * DEFAULT values @@ -163,6 +164,7 @@ public void onBlur(BlurEvent event) { private DateTimePickerView minView = DateTimePickerView.HOUR; private DateTimePickerView maxView = DateTimePickerView.DECADE; private boolean showTodayButton = false; + private boolean showClearButton = false; private boolean highlightToday = false; private boolean keyboardNavigation = true; private boolean forceParse = true; @@ -468,6 +470,13 @@ public void setShowTodayButton(final boolean showTodayButton) { this.showTodayButton = showTodayButton; } + /** {@inheritDoc} */ + @Override + public void setShowClearButton(final boolean showClearButton) { + this.showClearButton = showClearButton; + } + + /** {@inheritDoc} */ @Override public void setStartDate(final Date startDate) { @@ -602,7 +611,7 @@ private void setDateTimeFormat(final String format) { /** * Sets the format view type. - * + * * @param formatViewType * @see DateTimePickerFormatViewType */ @@ -676,8 +685,8 @@ protected void configure() { this.remove(getElement()); configure(getElement(), format, formatViewType.getValue(), weekStart.getValue(), toDaysOfWeekDisabledString(daysOfWeekDisabled), - autoClose, startView.getValue(), minView.getValue(), maxView.getValue(), showTodayButton, highlightToday, - keyboardNavigation, forceParse, minuteStep, viewSelect.getValue(), showMeridian, language.getCode(), position.getPosition()); + autoClose, startView.getValue(), minView.getValue(), maxView.getValue(), showTodayButton, showClearButton, highlightToday, + keyboardNavigation, forceParse, minuteStep, viewSelect.getValue(), showMeridian, language.getCode(), position.getPosition()); } protected void execute(final String cmd) { @@ -717,9 +726,9 @@ private native void setDaysOfWeekDisabled(Element e, String daysOfWeekDisabled) }-*/; protected native void configure(Element e, String format, String formatViewType, int weekStart, - String daysOfWeekDisabled, boolean autoClose, int startView, int minView, int maxView, boolean todayBtn, - boolean highlightToday, boolean keyboardNavigation, boolean forceParse, int minuteStep, int viewSelect, - boolean showMeridian, String language, String position) /*-{ + String daysOfWeekDisabled, boolean autoClose, int startView, int minView, int maxView, boolean todayBtn, boolean clearBtn, + boolean highlightToday, boolean keyboardNavigation, boolean forceParse, int minuteStep, int viewSelect, + boolean showMeridian, String language, String position) /*-{ var that = this; $wnd.jQuery(e).datetimepicker({ format: format, @@ -732,6 +741,7 @@ protected native void configure(Element e, String format, String formatViewType, minView: minView, maxView: maxView, todayBtn: todayBtn, + clearBtn: clearBtn, todayHighlight: highlightToday, keyboardNavigation: keyboardNavigation, forceParse: forceParse, diff --git a/src/main/java/org/gwtbootstrap3/extras/datetimepicker/client/ui/base/constants/HasShowClearButton.java b/src/main/java/org/gwtbootstrap3/extras/datetimepicker/client/ui/base/constants/HasShowClearButton.java new file mode 100644 index 00000000..035fb768 --- /dev/null +++ b/src/main/java/org/gwtbootstrap3/extras/datetimepicker/client/ui/base/constants/HasShowClearButton.java @@ -0,0 +1,33 @@ +package org.gwtbootstrap3.extras.datetimepicker.client.ui.base.constants; + +/* + * #%L + * GwtBootstrap3 + * %% + * Copyright (C) 2013 - 2014 GwtBootstrap3 + * %% + * 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. + * #L% + */ + +/** + * Boolean, Default: false + *

+ * If true, displays a clear button at the bottom of the datetimepicker to clear the current date. + * If true, the "Clear" button will clear the currently selected date from the datetimepicker; + * + * @author Rishiraj Anand + */ +public interface HasShowClearButton { + void setShowClearButton(boolean showClearButton); +}