diff --git a/.travis.yml b/.travis.yml
index d066fe1a4..f38aefaac 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,17 +8,17 @@ cache:
- $HOME/.m2
before_install:
# install the gwt-material-jquery library before we build the demo
-- git clone -b release_2.4.2 https://github.com/GwtMaterialDesign/gwt-material-jquery.git
+- git clone -b release_2.5.0_rc1 https://github.com/GwtMaterialDesign/gwt-material-jquery.git
- cd gwt-material-jquery
- mvn install -DskipTests=true -DdryRun=true
- cd ..
# install the gwt-material library before we build the demo
-- git clone -b release_2.4.2 https://github.com/GwtMaterialDesign/gwt-material.git
+- git clone -b release_2.5.0_rc1 https://github.com/GwtMaterialDesign/gwt-material.git
- cd gwt-material
- mvn install -DskipTests=true -DdryRun=true
- cd ..
# install the gwt-material-table library before we build the demo
-- git clone -b release_2.4.2 https://github.com/GwtMaterialDesign/gwt-material-table.git
+- git clone -b release_2.5.0_rc1 https://github.com/GwtMaterialDesign/gwt-material-table.git
- cd gwt-material-table
- mvn install -DskipTests=true -DdryRun=true
- cd ..
diff --git a/.utility/deploy.sh b/.utility/deploy.sh
index c45c40d91..04a6e5acb 100644
--- a/.utility/deploy.sh
+++ b/.utility/deploy.sh
@@ -1,6 +1,6 @@
#!/bin/bash
set -ev
-if [ "$TRAVIS_JDK_VERSION" == "oraclejdk8" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "release_2.4.2" ]; then
+if [ "$TRAVIS_JDK_VERSION" == "oraclejdk8" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "release_2.5.0_rc1" ]; then
echo "ossrh\${env.OSSRH_USER}\${env.OSSRH_PASS}" > ~/settings.xml
mvn deploy -DskipTests --settings ~/settings.xml
fi
\ No newline at end of file
diff --git a/README.md b/README.md
index 72cb73ebb..10d644a12 100644
--- a/README.md
+++ b/README.md
@@ -6,12 +6,12 @@
Gwt Material Design Extra Components for https://github.com/GwtMaterialDesign/gwt-material
-## Current Version 2.4.2
+## Current Version 2.5.0-rc1
```xml
com.github.gwtmaterialdesign
gwt-material-addins
- 2.4.2
+ 2.5.0-rc1
```
diff --git a/pom.xml b/pom.xml
index 6bfd1d23a..8a79fa488 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
gwt-material-parent
com.github.gwtmaterialdesign
- 2.4.2
+ 2.5.0-rc1
gwt-material-addins
@@ -24,7 +24,7 @@
scm:git:git@github.com:GwtMaterialDesign/gwt-material-addins.git
scm:git:git@github.com:GwtMaterialDesign/gwt-material-addins.git
http://github.com/GwtMaterialDesign/gwt-material-addins
- v2.4.2
+ v2.5.0-rc1
diff --git a/src/main/java/gwt/material/design/addins/client/combobox/MaterialComboBox.java b/src/main/java/gwt/material/design/addins/client/combobox/MaterialComboBox.java
index afab6d65a..367c45524 100644
--- a/src/main/java/gwt/material/design/addins/client/combobox/MaterialComboBox.java
+++ b/src/main/java/gwt/material/design/addins/client/combobox/MaterialComboBox.java
@@ -99,7 +99,7 @@
*/
//@formatter:on
public class MaterialComboBox extends AbstractValueWidget> implements JsLoader, HasPlaceholder,
- HasComboBoxHandlers, HasReadOnly, HasFieldTypes, IsAsyncWidget>, HasLabel, HasOpenClose {
+ HasComboBoxHandlers, HasReadOnly, HasFieldTypes, IsAsyncWidget>, HasLabel, HasOpenClose, HasSingleValue {
static {
if (MaterialAddins.isDebug()) {
@@ -583,17 +583,6 @@ public List getSelectedValue() {
return getValue();
}
- /**
- * Only return a single value even if multi support is activate.
- */
- public T getSingleValue() {
- List values = getSelectedValue();
- if (values != null && !values.isEmpty()) {
- return values.get(0);
- }
- return null;
- }
-
@Override
public void setValue(List value) {
setValue(value, false);
@@ -603,31 +592,16 @@ public void setValue(List value) {
* Set the selected value using a single item, generally used
* in single selection mode.
*/
+ @Override
public void setSingleValue(T value) {
setValue(Collections.singletonList(value));
}
- @Override
- public void setValue(List values, boolean fireEvents) {
- if (values == null) {
- reset();
-
- if (fireEvents) {
- ValueChangeEvent.fire(this, null);
- }
- } else if (!isMultiple()) {
- if (!values.isEmpty()) {
- setSingleValue(values.get(0), fireEvents);
- }
- } else {
- setValues(values, fireEvents);
- }
- }
-
/**
* Set the selected value using a single item, generally used
* in single selection mode.
*/
+ @Override
public void setSingleValue(T value, boolean fireEvents) {
int index = this.values.indexOf(value);
if (index < 0 && value instanceof String) {
@@ -644,6 +618,35 @@ public void setSingleValue(T value, boolean fireEvents) {
}
}
+ /**
+ * Only return a single value even if multi support is activate.
+ */
+ @Override
+ public T getSingleValue() {
+ List values = getSelectedValue();
+ if (values != null && !values.isEmpty()) {
+ return values.get(0);
+ }
+ return null;
+ }
+
+ @Override
+ public void setValue(List values, boolean fireEvents) {
+ if (values == null) {
+ reset();
+
+ if (fireEvents) {
+ ValueChangeEvent.fire(this, null);
+ }
+ } else if (!isMultiple()) {
+ if (!values.isEmpty()) {
+ setSingleValue(values.get(0), fireEvents);
+ }
+ } else {
+ setValues(values, fireEvents);
+ }
+ }
+
// TODO: Optimize performance (maybe use a map)
public T getValueByString(String key) {
for (T value : values) {
@@ -1222,6 +1225,10 @@ public AsyncWidgetCallback> getAsyncCallback() {
return getAsyncWidgetMixin().getAsyncCallback();
}
+ public List getOptions() {
+ return values;
+ }
+
@Override
public void setAsyncDisplayLoader(AsyncDisplayLoader displayLoader) {
getAsyncWidgetMixin().setAsyncDisplayLoader(displayLoader);
diff --git a/src/main/java/gwt/material/design/addins/client/iconmorph/IconMorphedEvent.java b/src/main/java/gwt/material/design/addins/client/iconmorph/IconMorphedEvent.java
new file mode 100644
index 000000000..91d657277
--- /dev/null
+++ b/src/main/java/gwt/material/design/addins/client/iconmorph/IconMorphedEvent.java
@@ -0,0 +1,61 @@
+/*
+ * #%L
+ * GwtMaterial
+ * %%
+ * Copyright (C) 2015 - 2017 GwtMaterialDesign
+ * %%
+ * 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%
+ */
+package gwt.material.design.addins.client.iconmorph;
+
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
+import com.google.gwt.event.shared.HasHandlers;
+
+public class IconMorphedEvent extends GwtEvent {
+
+ protected boolean morphed;
+
+ public IconMorphedEvent(boolean morphed) {
+ this.morphed = morphed;
+ }
+
+ public interface IconMorphedHandler extends EventHandler {
+ void onIconMorphed(IconMorphedEvent event);
+ }
+
+ public static final Type TYPE = new Type<>();
+
+ public static void fire(HasHandlers source, boolean morphed) {
+ source.fireEvent(new IconMorphedEvent(morphed));
+ }
+
+ @Override
+ public Type getAssociatedType() {
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(IconMorphedHandler handler) {
+ handler.onIconMorphed(this);
+ }
+
+ public boolean isMorphed() {
+ return morphed;
+ }
+
+ public void setMorphed(boolean morphed) {
+ this.morphed = morphed;
+ }
+}
diff --git a/src/main/java/gwt/material/design/addins/client/iconmorph/MaterialIconMorph.java b/src/main/java/gwt/material/design/addins/client/iconmorph/MaterialIconMorph.java
index 30670a8cc..fbb478c2b 100644
--- a/src/main/java/gwt/material/design/addins/client/iconmorph/MaterialIconMorph.java
+++ b/src/main/java/gwt/material/design/addins/client/iconmorph/MaterialIconMorph.java
@@ -20,6 +20,7 @@
package gwt.material.design.addins.client.iconmorph;
import com.google.gwt.dom.client.Document;
+import com.google.gwt.event.shared.HandlerRegistration;
import gwt.material.design.addins.client.MaterialAddins;
import gwt.material.design.addins.client.base.constants.AddinsCssName;
import gwt.material.design.client.MaterialDesignBase;
@@ -30,6 +31,8 @@
import gwt.material.design.client.constants.IconSize;
import gwt.material.design.client.ui.MaterialIcon;
+import static gwt.material.design.jquery.client.api.JQuery.$;
+
//@formatter:off
/**
@@ -67,30 +70,76 @@ public class MaterialIconMorph extends MaterialWidget implements HasDurationTran
}
}
- private CssNameMixin sizeMixin;
- private MaterialIcon source, target;
+ protected static final String ICON_MORPH = "icon-morph";
+ protected static final String MORPHED = "morphed";
+ protected CssNameMixin sizeMixin;
+ protected String customSize;
+ protected MaterialIcon source, target;
public MaterialIconMorph() {
- super(Document.get().createDivElement(), AddinsCssName.ANIM_CONTAINER);
- getElement().setAttribute("onclick", "this.classList.toggle('morphed')");
+ super(Document.get().createDivElement(), AddinsCssName.ANIM_CONTAINER, ICON_MORPH);
}
@Override
protected void onLoad() {
super.onLoad();
- if (getWidgetCount() >= 2) {
- source = (MaterialIcon) getWidget(0);
+ registerHandler(addClickHandler(event -> {
+ $(getElement()).toggleClass(MORPHED);
+ IconMorphedEvent.fire(this, getElement().hasClassName(MORPHED));
+ }));
+
+ // Check if we add the source and target icons thru ui binder
+ if (source == null && target == null) {
+ if (getWidgetCount() == 2) {
+ source = (MaterialIcon) getWidget(0);
+ target = (MaterialIcon) getWidget(1);
+ }
+ }
+
+ if (source != null) {
source.addStyleName(AddinsCssName.ICONS + " " + AddinsCssName.SOURCE);
- target = (MaterialIcon) getWidget(1);
+ if (!source.isAttached()) add(source);
+ }
+ if (target != null) {
target.addStyleName(AddinsCssName.ICONS + " " + AddinsCssName.TARGET);
+ if (!target.isAttached()) add(target);
+ }
+
+ applyCustomSize(customSize);
+ }
+
+ protected void applyCustomSize(String customSize) {
+ if (customSize != null) {
+ setWidth(customSize);
+ setHeight(customSize);
+
+ if (source != null) {
+ source.setWidth(customSize);
+ source.setHeight(customSize);
+ source.setFontSize(customSize);
+ }
+
+ if (target != null) {
+ target.setWidth(customSize);
+ target.setHeight(customSize);
+ target.setFontSize(customSize);
+ }
}
}
+ public void reset() {
+ getElement().removeClassName(MORPHED);
+ }
+
public void setIconSize(IconSize size) {
getSizeMixin().setCssName(size);
}
+ public void setCustomSize(String customSize) {
+ this.customSize = customSize;
+ }
+
@Override
public void setDuration(int duration) {
setTransition(new TransitionConfig(duration, "all"));
@@ -101,6 +150,14 @@ public int getDuration() {
return 0;
}
+ public void setSource(MaterialIcon source) {
+ this.source = source;
+ }
+
+ public void setTarget(MaterialIcon target) {
+ this.target = target;
+ }
+
public MaterialIcon getSource() {
return source;
}
@@ -115,4 +172,8 @@ public CssNameMixin getSizeMixin() {
}
return sizeMixin;
}
+
+ public HandlerRegistration addIconMorphedHandler(IconMorphedEvent.IconMorphedHandler handler) {
+ return addHandler(handler, IconMorphedEvent.TYPE);
+ }
}
diff --git a/src/main/java/gwt/material/design/addins/client/moment/Moment.java b/src/main/java/gwt/material/design/addins/client/moment/Moment.java
index f45665ceb..6d5c1bd8f 100644
--- a/src/main/java/gwt/material/design/addins/client/moment/Moment.java
+++ b/src/main/java/gwt/material/design/addins/client/moment/Moment.java
@@ -24,10 +24,11 @@
import gwt.material.design.addins.client.moment.option.CalendarFormat;
import gwt.material.design.addins.client.moment.option.CreationData;
import gwt.material.design.addins.client.moment.option.Duration;
+import gwt.material.design.addins.client.moment.resources.MomentClientBundle;
import gwt.material.design.jquery.client.api.Functions;
import jsinterop.annotations.*;
-@JsType(isNative = true, name = "Object", namespace = JsPackage.GLOBAL)
+@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class Moment {
@JsOverlay
@@ -49,48 +50,48 @@ public class Moment {
// Parse : String
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String value);
// Parse : String + Format
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String date, String format);
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String date, String format, String locale);
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String date, String format, Boolean strict);
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String date, String format, String locale, Boolean strict);
// Parse : String + Formats
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String date, String[] format);
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String date, String[] format, String locale);
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String date, String[] format, Boolean strict);
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String date, String[] format, String locale, Boolean strict);
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(String s, JavaScriptObject special_format);
// Parse : Special Formats
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(JavaScriptObject object);
// Parse : Unix Timestamp (milliseconds)
- @JsMethod(namespace = "moment")
+ @JsMethod(namespace = JsPackage.GLOBAL)
public static native Moment moment(double milliseconds);
// Parse : Unix Timestamp (seconds)
@@ -915,4 +916,31 @@ public class Moment {
@JsMethod
public native static Moment invalid(Object object);
+
+ /**
+ * Plugins for JDateParser
+ * @see Documentation
+ * Formats the moment with a java date format.
+ * Note: You must inject the js resource independently @see {@link MomentClientBundle#momentJDateConverterJs()}
+ */
+ @JsMethod
+ public native String formatWithJDF(String format);
+
+ /**
+ * Plugins for JDateParser
+ * @see Documentation
+ * Translates the java date format to a momentjs format.
+ * Note: You must inject the js resource independently @see {@link MomentClientBundle#momentJDateConverterJs()}
+ */
+ @JsMethod
+ public native String toMomentFormatString(String format);
+
+ /**
+ * Plugins for JDateParser
+ * @see Documentation
+ * Translates the momentjs format to a java date format.
+ * Note: You must inject the js resource independently @see {@link MomentClientBundle#momentJDateConverterJs()}
+ */
+ @JsMethod
+ public native String toJDFString(String format);
}
diff --git a/src/main/java/gwt/material/design/addins/client/moment/resources/MomentClientBundle.java b/src/main/java/gwt/material/design/addins/client/moment/resources/MomentClientBundle.java
index 852f4b6f3..0de68f0a3 100644
--- a/src/main/java/gwt/material/design/addins/client/moment/resources/MomentClientBundle.java
+++ b/src/main/java/gwt/material/design/addins/client/moment/resources/MomentClientBundle.java
@@ -29,4 +29,7 @@ public interface MomentClientBundle extends ClientBundle {
@Source("js/moment.min.js")
TextResource momentJs();
+
+ @Source("js/moment-jdateformatparser.min.js")
+ TextResource momentJDateConverterJs();
}
diff --git a/src/main/java/gwt/material/design/addins/client/moment/resources/MomentClientDebugBundle.java b/src/main/java/gwt/material/design/addins/client/moment/resources/MomentClientDebugBundle.java
index c3805ee13..b13ad69c0 100644
--- a/src/main/java/gwt/material/design/addins/client/moment/resources/MomentClientDebugBundle.java
+++ b/src/main/java/gwt/material/design/addins/client/moment/resources/MomentClientDebugBundle.java
@@ -29,4 +29,7 @@ public interface MomentClientDebugBundle extends ClientBundle {
@Source("js/moment.js")
TextResource momentDebugJs();
+
+ @Source("js/moment-jdateformatparser.js")
+ TextResource momentJDateConverterDebugJs();
}
diff --git a/src/main/java/gwt/material/design/addins/client/stepper/MaterialStep.java b/src/main/java/gwt/material/design/addins/client/stepper/MaterialStep.java
index 0167dcc75..5c75a6bef 100644
--- a/src/main/java/gwt/material/design/addins/client/stepper/MaterialStep.java
+++ b/src/main/java/gwt/material/design/addins/client/stepper/MaterialStep.java
@@ -66,7 +66,7 @@
*/
// @formatter:on
public class MaterialStep extends MaterialWidget implements HasActive, HasTitle, HasStatusText, HasAxis,
- HasSelectionHandlers {
+ HasSelectionHandlers {
private int step;
private String title;
@@ -258,6 +258,11 @@ public void setStatusDisplayPosition(Position position) {
// Nothing for now
}
+ @Override
+ public void setStatusShowByDefault(boolean showByDefault) {
+ // Nothing for now
+ }
+
protected void applyIconStatus(MaterialIcon icon, String description) {
iconError.removeFromParent();
iconSuccess.removeFromParent();
diff --git a/src/main/java/gwt/material/design/addins/client/stepper/MaterialStepper.java b/src/main/java/gwt/material/design/addins/client/stepper/MaterialStepper.java
index 828e34339..e47a6b05c 100644
--- a/src/main/java/gwt/material/design/addins/client/stepper/MaterialStepper.java
+++ b/src/main/java/gwt/material/design/addins/client/stepper/MaterialStepper.java
@@ -467,6 +467,11 @@ public void setStatusDisplayPosition(Position position) {
getCurrentStep().setStatusDisplayPosition(position);
}
+ @Override
+ public void setStatusShowByDefault(boolean showByDefault) {
+ getCurrentStep().setStatusShowByDefault(showByDefault);
+ }
+
/**
* Get feedback message.
*/
diff --git a/src/main/java/gwt/material/design/incubator/client/daterange/DateRangeOptions.java b/src/main/java/gwt/material/design/incubator/client/daterange/DateRangeOptions.java
index 2e3ab33d4..7577d07e2 100644
--- a/src/main/java/gwt/material/design/incubator/client/daterange/DateRangeOptions.java
+++ b/src/main/java/gwt/material/design/incubator/client/daterange/DateRangeOptions.java
@@ -20,8 +20,7 @@
package gwt.material.design.incubator.client.daterange;
import com.google.gwt.core.client.JsDate;
-import gwt.material.design.addins.client.moment.Moment;
-import gwt.material.design.client.ui.MaterialToast;
+import gwt.material.design.incubator.client.daterange.js.DateRangeLocale;
import gwt.material.design.incubator.client.daterange.js.DropdownAlignment;
import gwt.material.design.jquery.client.api.Functions;
import jsinterop.annotations.JsOverlay;
@@ -31,8 +30,6 @@
import java.util.Date;
-import static gwt.material.design.addins.client.moment.Moment.moment;
-
@JsType(isNative = true, name = "Object", namespace = JsPackage.GLOBAL)
public class DateRangeOptions {
@@ -106,7 +103,7 @@ public class DateRangeOptions {
protected String cancelButtonClasses;
@JsProperty
- protected Object locale;
+ protected DateRangeLocale locale;
@JsProperty
protected boolean singleDatePicker;
@@ -128,7 +125,7 @@ public class DateRangeOptions {
@JsProperty
protected String parentEl;
-
+
@JsOverlay
public final void setStartDate(Date startDate) {
@@ -241,7 +238,7 @@ public final void setCancelButtonClasses(String cancelButtonClasses) {
}
@JsOverlay
- public final void setLocale(Object locale) {
+ public final void setLocale(DateRangeLocale locale) {
this.locale = locale;
}
diff --git a/src/main/java/gwt/material/design/incubator/client/daterange/DateRangePicker.java b/src/main/java/gwt/material/design/incubator/client/daterange/DateRangePicker.java
index 198f033fe..295d2415c 100644
--- a/src/main/java/gwt/material/design/incubator/client/daterange/DateRangePicker.java
+++ b/src/main/java/gwt/material/design/incubator/client/daterange/DateRangePicker.java
@@ -23,23 +23,21 @@
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.logical.shared.*;
import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.ui.TextBox;
import gwt.material.design.addins.client.combobox.MaterialComboBoxDebugClientBundle;
import gwt.material.design.addins.client.combobox.js.JsComboBox;
import gwt.material.design.addins.client.combobox.js.JsComboBoxOptions;
+import gwt.material.design.addins.client.inputmask.MaterialInputMask;
+import gwt.material.design.addins.client.moment.Moment;
import gwt.material.design.addins.client.moment.resources.MomentClientBundle;
import gwt.material.design.addins.client.moment.resources.MomentClientDebugBundle;
import gwt.material.design.client.MaterialDesignBase;
import gwt.material.design.client.base.*;
import gwt.material.design.client.base.helper.ScrollHelper;
-import gwt.material.design.client.base.mixin.FieldTypeMixin;
-import gwt.material.design.client.base.mixin.NativeBrowserStyleMixin;
-import gwt.material.design.client.base.mixin.ReadOnlyMixin;
-import gwt.material.design.client.base.mixin.StatusTextMixin;
+import gwt.material.design.client.base.mixin.*;
import gwt.material.design.client.base.viewport.Resolution;
import gwt.material.design.client.constants.*;
+import gwt.material.design.client.events.RegexValidationEvent;
import gwt.material.design.client.js.Window;
import gwt.material.design.client.ui.MaterialIcon;
import gwt.material.design.client.ui.MaterialLabel;
@@ -59,18 +57,21 @@
import static gwt.material.design.incubator.client.daterange.js.JsDateRangePicker.$;
-
public class DateRangePicker extends AbstractValueWidget implements HasDateRangeHandlers, HasFieldTypes,
- HasDateRangeOptions, HasIcon, HasReadOnly, HasPlaceholder, HasNativeBrowserStyle, HasLabel {
+ HasDateRangeOptions, HasIcon, HasReadOnly, HasPlaceholder, HasNativeBrowserStyle, HasLabel, HasSingleValue, HasRegex {
+
+ private static final String DATE_RANGE_STYLENAME = "date-range-picker";
static {
if (AddinsIncubator.isDebug()) {
MaterialDesignBase.injectDebugJs(MomentClientDebugBundle.INSTANCE.momentDebugJs());
+ MaterialDesignBase.injectDebugJs(MomentClientDebugBundle.INSTANCE.momentJDateConverterDebugJs());
MaterialDesignBase.injectDebugJs(DateRangeClientDebugBundle.INSTANCE.dateRangePickerDebugJs());
MaterialDesignBase.injectCss(DateRangeClientDebugBundle.INSTANCE.dateRangePickerDebugCss());
MaterialDesignBase.injectCss(DateRangeClientDebugBundle.INSTANCE.dateRangePickerOverrideDebugCss());
} else {
MaterialDesignBase.injectJs(MomentClientBundle.INSTANCE.momentJs());
+ MaterialDesignBase.injectJs(MomentClientBundle.INSTANCE.momentJDateConverterJs());
MaterialDesignBase.injectJs(DateRangeClientBundle.INSTANCE.dateRangePickerJs());
MaterialDesignBase.injectCss(DateRangeClientBundle.INSTANCE.dateRangePickerCss());
MaterialDesignBase.injectCss(DateRangeClientBundle.INSTANCE.dateRangePickerOverrideCss());
@@ -79,24 +80,25 @@ public class DateRangePicker extends AbstractValueWidget implements HasD
MaterialDesignBase.injectCss(MaterialComboBoxDebugClientBundle.INSTANCE.select2DebugCss());
}
- private static final String DATE_INPUT_FORMAT = "MM/dd/yyyy";
- private static final String DATE_RANGE_STYLENAME = "date-range-picker";
- private ScrollHelper scrollHelper = new ScrollHelper();
- private TextBox dateInput = new TextBox();
- private Label label = new Label();
- private MaterialLabel errorLabel = new MaterialLabel();
- private MaterialIcon icon = new MaterialIcon();
- private DateRangeOptions options = new DateRangeOptions();
+ private final ScrollHelper scrollHelper = new ScrollHelper();
+ private final MaterialInputMask dateInput = new MaterialInputMask();
+ private final Label label = new Label();
+ private final MaterialLabel errorLabel = new MaterialLabel();
+ private final MaterialIcon icon = new MaterialIcon();
+ private final DateRangeOptions options = new DateRangeOptions();
+
private boolean open;
private double addedOffsetHeight = 480;
+ private String mask;
private Date startDate;
private Date endDate;
private Date[] value;
private FieldTypeMixin fieldTypeMixin;
private StatusTextMixin statusTextMixin;
- private ReadOnlyMixin readOnlyMixin;
+ private ReadOnlyMixin readOnlyMixin;
private NativeBrowserStyleMixin nativeBrowserStyleMixin;
+ private RegexMixin regexMixin;
public DateRangePicker() {
super(Document.get().createDivElement(), CssName.INPUT_FIELD, DATE_RANGE_STYLENAME);
@@ -110,13 +112,13 @@ protected void onLoad() {
}
protected void load() {
-
+ applyMasking();
add(dateInput);
add(label);
add(errorLabel);
getInputElement().daterangepicker(options, (startDate, endDate) -> {
- setValue(new Date[]{new Date(startDate.format()), new Date(endDate.format())}, true);
+ setValue(new Date[]{new Date(startDate.toString()), new Date(endDate.toString())}, true);
});
getInputElement().on(DateRangeEvents.UPDATE_CALENDAR, (e, picker) -> {
@@ -188,6 +190,12 @@ protected void load() {
IncubatorDarkThemeReloader.get().reload(DateRangeDarkTheme.class);
}
+ protected void applyMasking() {
+ if (mask != null) {
+ dateInput.setMask(mask);
+ }
+ }
+
protected void detectPosition() {
if (!isInVerticalViewPort()) {
getMethodProvider().setDrops(DropdownPosition.UP.getCssName());
@@ -265,7 +273,7 @@ public void reload() {
}
public JsDateRangePicker getInputElement() {
- return $(dateInput.getElement());
+ return $(dateInput.getValueBoxBase().getElement());
}
protected JsDateRangeMethod getMethodProvider() {
@@ -425,7 +433,7 @@ public void setCancelButtonClasses(String cancelButtonClasses) {
@Override
public void setLocale(DateRangeLocale locale) {
- options.setLocale(locale != null ? locale : false);
+ options.setLocale(locale);
}
@Override
@@ -487,14 +495,17 @@ public void setValue(Date[] value, boolean fireEvents) {
super.setValue(value, fireEvents);
}
+ @Override
public void setSingleValue(Date value) {
setValue(new Date[]{value}, false);
}
+ @Override
public void setSingleValue(Date value, boolean fireEvents) {
setValue(new Date[]{value}, fireEvents);
}
+ @Override
public Date getSingleValue() {
if (getValue().length >= 1) {
return getValue()[0];
@@ -506,17 +517,44 @@ public Date getSingleValue() {
* Call this if you have defined {@link DateRangePicker#setAutoUpdateInput(boolean)} to false.
* This will be required in order to update the input date textfield manually.
*/
- public void setDateInputValue(Date creationDate, Date endDate, String format) {
- if (dateInput != null && creationDate != null && endDate != null && format != null && !format.isEmpty()) {
- dateInput.setValue(DateTimeFormat.getFormat(format).format(creationDate) + " - " +
- DateTimeFormat.getFormat(format).format(endDate));
+ public void setDateInputValue(Date creationDate, Date endDate) {
+ if (dateInput != null && creationDate != null && endDate != null) {
+ String betweenDelimiter = options != null && options.locale != null && options.locale.getToLabel() != null ? options.locale.getToLabel() : " - ";
+ String creationDateFormatted = Moment.moment(creationDate.getTime()).format(getFormat());
+ String endDateFormatted = Moment.moment(endDate.getTime()).format(getFormat());
+ dateInput.setValue(getOptions().singleDatePicker ? creationDateFormatted :
+ creationDateFormatted + " " + betweenDelimiter + " " + endDateFormatted);
} else {
clearInputValue();
}
}
- public void setDateInputValue(Date creationDate, Date endDate) {
- setDateInputValue(creationDate, endDate, DATE_INPUT_FORMAT);
+ /**
+ * Set the format of the date range picker
+ *
+ * @param format Java Date format using {@link java.text.SimpleDateFormat}.
+ */
+ public void setFormat(String format) {
+ if (options.locale == null) {
+ options.locale = new DateRangeLocale();
+ }
+ options.locale.setFormat(format);
+ }
+
+ /**
+ * Set the format of the date range picker
+ *
+ * @param format Moment js native format
+ */
+ public void setMomentJsDateFormat(String format) {
+ if (options.locale == null) {
+ options.locale = new DateRangeLocale();
+ }
+ options.locale.setMomentJsDateFormat(format);
+ }
+
+ public String getFormat() {
+ return options != null && options.locale != null && options.locale.getFormat() != null ? options.locale.getFormat() : "MM/dd/yyyy";
}
public void clearInputValue() {
@@ -528,7 +566,7 @@ public Date[] getValue() {
return value;
}
- public TextBox getDateInput() {
+ public MaterialInputMask getDateInput() {
return dateInput;
}
@@ -667,7 +705,7 @@ public String getPlaceholder() {
@Override
public void setPlaceholder(String placeholder) {
- dateInput.getElement().setAttribute("placeholder", placeholder);
+ dateInput.setPlaceholder(placeholder);
}
@Override
@@ -685,6 +723,29 @@ public void setNativeBrowserStyle(boolean nativeBrowserStyle) {
getNativeBrowserStyleMixin().setNativeBrowserStyle(nativeBrowserStyle);
}
+ @Override
+ public void setRegex(String regex) {
+ getRegexMixin().setRegex(regex);
+ }
+
+ @Override
+ public void setRegex(String regex, String replaceRegex) {
+ getRegexMixin().setRegex(regex, replaceRegex);
+ }
+
+ @Override
+ public String getRegex() {
+ return getRegexMixin().getRegex();
+ }
+
+ public String getMask() {
+ return mask;
+ }
+
+ public void setMask(String mask) {
+ this.mask = mask;
+ }
+
@Override
public boolean isNativeBrowserStyle() {
return getNativeBrowserStyleMixin().isNativeBrowserStyle();
@@ -740,6 +801,11 @@ public HandlerRegistration addValueChangeHandler(ValueChangeHandler hand
return addHandler(handler, ValueChangeEvent.getType());
}
+ @Override
+ public HandlerRegistration addRegexValidationHandler(RegexValidationEvent.RegexValidationHandler handler) {
+ return addHandler(handler, RegexValidationEvent.getType());
+ }
+
protected FieldTypeMixin getFieldTypeMixin() {
if (fieldTypeMixin == null) {
fieldTypeMixin = new FieldTypeMixin<>(this);
@@ -755,7 +821,7 @@ public StatusTextMixin getStatusTextMixin()
return statusTextMixin;
}
- protected ReadOnlyMixin getReadOnlyMixin() {
+ protected ReadOnlyMixin getReadOnlyMixin() {
if (readOnlyMixin == null) {
readOnlyMixin = new ReadOnlyMixin<>(this, dateInput);
}
@@ -768,4 +834,11 @@ protected NativeBrowserStyleMixin getNativeBrowserStyleMixin()
}
return nativeBrowserStyleMixin;
}
+
+ protected RegexMixin getRegexMixin() {
+ if (regexMixin == null) {
+ regexMixin = new RegexMixin<>(dateInput);
+ }
+ return regexMixin;
+ }
}
diff --git a/src/main/java/gwt/material/design/incubator/client/daterange/js/DateRangeLocale.java b/src/main/java/gwt/material/design/incubator/client/daterange/js/DateRangeLocale.java
index 7a6aadeb0..202b7b224 100644
--- a/src/main/java/gwt/material/design/incubator/client/daterange/js/DateRangeLocale.java
+++ b/src/main/java/gwt/material/design/incubator/client/daterange/js/DateRangeLocale.java
@@ -20,15 +20,12 @@
package gwt.material.design.incubator.client.daterange.js;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.json.client.JSONString;
+import gwt.material.design.addins.client.moment.Moment;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
-import java.util.List;
-
/**
* @author kevzlou7979
* @see {@link gwt.material.design.incubator.client.daterange.DateRangePicker#setLocale(DateRangeLocale)}
@@ -71,6 +68,11 @@ public class DateRangeLocale {
@JsOverlay
public final void setFormat(String format) {
+ this.format = Moment.moment().toMomentFormatString(format);
+ }
+
+ @JsOverlay
+ public final void setMomentJsDateFormat(String format) {
this.format = format;
}
@@ -122,8 +124,64 @@ public final void setMonthNames(LocaleString[] monthNames) {
GWT.log("Months must be equal to seven (12) months", new IllegalArgumentException());
}
}
+
@JsOverlay
public final void setFirstDay(String firstDay) {
this.firstDay = firstDay;
}
+
+ @JsOverlay
+ public final String getFormat() {
+ return format;
+ }
+
+ @JsOverlay
+ public final String getSeparator() {
+ return separator;
+ }
+
+ @JsOverlay
+ public final String getApplyLabel() {
+ return applyLabel;
+ }
+
+ @JsOverlay
+ public final String getCancelLabel() {
+ return cancelLabel;
+ }
+
+ @JsOverlay
+ public final String getFromLabel() {
+ return fromLabel;
+ }
+
+ @JsOverlay
+ public final String getToLabel() {
+ return toLabel;
+ }
+
+ @JsOverlay
+ public final String getCustomRangeLabel() {
+ return customRangeLabel;
+ }
+
+ @JsOverlay
+ public final String getWeekLabel() {
+ return weekLabel;
+ }
+
+ @JsOverlay
+ public final LocaleString[] getDaysOfWeek() {
+ return daysOfWeek;
+ }
+
+ @JsOverlay
+ public final LocaleString[] getMonthNames() {
+ return monthNames;
+ }
+
+ @JsOverlay
+ public final String getFirstDay() {
+ return firstDay;
+ }
}
diff --git a/src/main/java/gwt/material/design/incubator/client/daterange/js/JsDateRangePicker.java b/src/main/java/gwt/material/design/incubator/client/daterange/js/JsDateRangePicker.java
index 97e85ecfe..0de7a69db 100644
--- a/src/main/java/gwt/material/design/incubator/client/daterange/js/JsDateRangePicker.java
+++ b/src/main/java/gwt/material/design/incubator/client/daterange/js/JsDateRangePicker.java
@@ -19,6 +19,7 @@
*/
package gwt.material.design.incubator.client.daterange.js;
+import com.google.gwt.core.client.JsDate;
import com.google.gwt.dom.client.Element;
import gwt.material.design.addins.client.moment.Moment;
import gwt.material.design.incubator.client.daterange.DateRangeOptions;
@@ -34,7 +35,7 @@
* @author kevzlou7979
*/
@JsType(isNative = true, name = "Object", namespace = JsPackage.GLOBAL)
-public class JsDateRangePicker {
+public class JsDateRangePicker extends DateRangeOptions {
@JsMethod(name = "$", namespace = JsPackage.GLOBAL)
public static native JsDateRangePicker $(JQueryElement element);
@@ -49,7 +50,7 @@ public class JsDateRangePicker {
public native void daterangepicker(DateRangeOptions options);
@JsMethod
- public native void daterangepicker(DateRangeOptions options, Functions.Func2 callback);
+ public native void daterangepicker(DateRangeOptions options, Functions.Func2