Skip to content

Commit 568eb3f

Browse files
authored
Merge pull request #443 from GwtMaterialDesign/release_2.8.0
Release 2.8.5
2 parents 7cbe3e3 + 1a96a63 commit 568eb3f

File tree

11 files changed

+116
-44
lines changed

11 files changed

+116
-44
lines changed

.idea/copyright/profiles_settings.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
Gwt Material Design Extra Components for https://github.com/GwtMaterialDesign/gwt-material <br>
88

9-
## Current Version 2.8.3
9+
## Current Version 2.8.5
1010
```xml
1111
<dependency>
1212
<groupId>com.github.gwtmaterialdesign</groupId>
1313
<artifactId>gwt-material-addins</artifactId>
14-
<version>2.8.3</version>
14+
<version>2.8.5</version>
1515
</dependency>
1616
```
1717

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>gwt-material-parent</artifactId>
77
<groupId>com.github.gwtmaterialdesign</groupId>
8-
<version>2.8.3</version>
8+
<version>2.8.5</version>
99
</parent>
1010

1111
<artifactId>gwt-material-addins</artifactId>
@@ -24,7 +24,7 @@
2424
<connection>scm:git:[email protected]:GwtMaterialDesign/gwt-material-addins.git</connection>
2525
<developerConnection>scm:git:[email protected]:GwtMaterialDesign/gwt-material-addins.git</developerConnection>
2626
<url>http://github.com/GwtMaterialDesign/gwt-material-addins</url>
27-
<tag>v2.8.3</tag>
27+
<tag>v2.8.5</tag>
2828
</scm>
2929

3030
<licenses>

src/main/java/gwt/material/design/addins/client/combobox/MaterialComboBox.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public class MaterialComboBox<T> extends AbstractValueWidget<List<T>> implements
122122
protected List<T> values = new ArrayList<>();
123123
private Label label = new Label();
124124
private MaterialLabel errorLabel = new MaterialLabel();
125+
private MaterialLabel helperText = new MaterialLabel();
125126
protected MaterialWidget listbox = new MaterialWidget(Document.get().createSelectElement());
126127
private KeyFactory<T, String> keyFactory = new AllowBlankKeyFactory<>();
127128
private JsComboBoxOptions options = JsComboBoxOptions.create();
@@ -150,6 +151,8 @@ protected void onLoad() {
150151
addWidget(listbox);
151152
addWidget(label);
152153
addWidget(errorLabel);
154+
helperText.addStyleName("help-description");
155+
153156
errorLabel.setMarginTop(8);
154157
listbox.setGwtDisplay(Style.Display.BLOCK);
155158

@@ -341,7 +344,7 @@ public void clear() {
341344
final Iterator<Widget> it = iterator();
342345
while (it.hasNext()) {
343346
final Widget widget = it.next();
344-
if (widget != label && widget != errorLabel && widget != listbox) {
347+
if (widget != label && widget != errorLabel && widget != listbox && widget != helperText) {
345348
it.remove();
346349
}
347350
}
@@ -627,6 +630,11 @@ public void setSingleValue(T value) {
627630
setValue(Collections.singletonList(value));
628631
}
629632

633+
public void setSingleValue(T value, String text, boolean addAsDefault) {
634+
setValue(Collections.singletonList(value));
635+
addItem(text, value);
636+
}
637+
630638
/**
631639
* Set the selected value using a single item, generally used
632640
* in single selection mode.
@@ -1376,4 +1384,10 @@ public AsyncWidgetMixin<MaterialComboBox, List<T>> getAsyncWidgetMixin() {
13761384
}
13771385
return asyncWidgetMixin;
13781386
}
1387+
1388+
@Override
1389+
public void setHelperText(String helperText) {
1390+
this.helperText.setText(helperText);
1391+
addWidget(this.helperText);
1392+
}
13791393
}

src/main/java/gwt/material/design/addins/client/inputmask/AbstractInputMask.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class AbstractInputMask<T> extends MaterialValueBox<T>
7676
}
7777

7878
private String mask;
79+
protected boolean autoReload;
7980
protected JsInputMaskOptions options = new JsInputMaskOptions();
8081

8182
public AbstractInputMask() {
@@ -196,6 +197,21 @@ public void setValue(T value) {
196197
super.setValue(value);
197198
}
198199

200+
@Override
201+
public void setValue(T value, boolean fireEvents) {
202+
super.setValue(value, fireEvents);
203+
204+
if (autoReload) reload();
205+
}
206+
207+
public boolean isAutoReload() {
208+
return autoReload;
209+
}
210+
211+
public void setAutoReload(boolean autoReload) {
212+
this.autoReload = autoReload;
213+
}
214+
199215
@Override
200216
public HandlerRegistration addCompleteHandler(CompleteEvent.CompleteHandler handler) {
201217
return addHandler(handler, CompleteEvent.TYPE);

src/main/java/gwt/material/design/addins/client/inputmask/MaterialDateInputMask.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package gwt.material.design.addins.client.inputmask;
2121

22+
import com.google.gwt.editor.client.EditorError;
2223
import com.google.gwt.event.dom.client.FocusHandler;
2324
import com.google.gwt.event.logical.shared.InitializeHandler;
2425
import com.google.gwt.event.logical.shared.ValueChangeEvent;
@@ -35,13 +36,14 @@
3536
import gwt.material.design.client.events.ToggleReadOnlyEvent;
3637

3738
import java.util.Date;
39+
import java.util.List;
3840

3941
public class MaterialDateInputMask extends AbstractValueWidget<Date>
4042
implements HasFieldTypes, HasLabel, HasInputMaskHandlers, HasPlaceholder, HasReadOnly, HasActive, HasToggleReadOnlyHandler, HasAutocomplete, HasPasteHandlers, HasFieldSensitivity {
4143

42-
private String format = "YYYY-mm-dd";
43-
private MaterialInputMask inputMask;
44-
private DateInputParser inputParser;
44+
protected String format = "YYYY-mm-dd";
45+
protected MaterialInputMask inputMask;
46+
protected DateInputParser inputParser;
4547

4648
public MaterialDateInputMask() {
4749
super(DOM.createDiv());
@@ -50,8 +52,8 @@ public MaterialDateInputMask() {
5052
inputParser = new DateInputParser(inputMask);
5153
inputMask.setPlaceholder(format.toUpperCase());
5254
setMask(format);
53-
5455
setValidateOnBlur(true);
56+
addStyleName("input-field date-mask");
5557
}
5658

5759
@Override
@@ -65,6 +67,16 @@ protected void onLoad() {
6567
});
6668
}
6769

70+
@Override
71+
public void setErrorText(String errorText) {
72+
inputMask.setErrorText(errorText);
73+
}
74+
75+
@Override
76+
public void clearErrorText() {
77+
inputMask.clearErrorText();
78+
}
79+
6880
public void setMask(String mask) {
6981
this.format = mask
7082
.replace("m", "M")
@@ -208,6 +220,22 @@ public HandlerRegistration addPasteHandler(PasteEvent.PasteEventHandler handler)
208220
return inputMask.addPasteHandler(handler);
209221
}
210222

223+
public DateInputParser getInputParser() {
224+
return inputParser;
225+
}
226+
227+
public void setInputParser(DateInputParser inputParser) {
228+
this.inputParser = inputParser;
229+
}
230+
231+
public MaterialInputMask getInputMask() {
232+
return inputMask;
233+
}
234+
235+
public void setInputMask(MaterialInputMask inputMask) {
236+
this.inputMask = inputMask;
237+
}
238+
211239
@Override
212240
public String getPlaceholder() {
213241
return inputMask.getPlaceholder();

src/main/java/gwt/material/design/addins/client/inputmask/base/DateInputParser.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
public class DateInputParser<T extends AbstractInputMask<String>> {
2828

29-
private final T valuebox;
29+
protected final T valuebox;
3030

3131
public DateInputParser(T valuebox) {
3232
this.valuebox = valuebox;
@@ -43,33 +43,39 @@ public Date parseDate(String format) {
4343
public void setValue(String format, Date value) {
4444
if (value != null) {
4545
valuebox.setValue(DateTimeFormat.getFormat(format).format(value), true);
46+
} else {
47+
valuebox.clear();
4648
}
4749
}
4850

4951
public boolean validate(String format) {
50-
if (valuebox.getText() != null && !valuebox.getText().isEmpty()
51-
&& valuebox.getMask() != null && format != null) {
52-
format = format.toLowerCase();
53-
String dateString = valuebox.getText();
54-
String month = dateString.substring(format.indexOf("m"), format.indexOf("m") + 2);
55-
String day = dateString.substring(format.indexOf("d"), format.indexOf("d") + 2);
56-
String year = dateString.substring(format.indexOf("y"), format.lastIndexOf("y") + 1);
57-
58-
boolean validLeapYear = validateLeapYear(day, month, Integer.parseInt(year));
59-
if (!validLeapYear) {
60-
valuebox.setErrorText("Not a valid date");
52+
try {
53+
if (valuebox.getText() != null && !valuebox.getText().isEmpty()
54+
&& valuebox.getMask() != null && format != null) {
55+
format = format.toLowerCase();
56+
String dateString = valuebox.getValueWithMask();
57+
String month = dateString.substring(format.indexOf("m"), format.indexOf("m") + 2);
58+
String day = dateString.substring(format.indexOf("d"), format.indexOf("d") + 2);
59+
String year = dateString.substring(format.indexOf("y"), format.lastIndexOf("y") + 1);
60+
61+
boolean validLeapYear = validateLeapYear(day, month, Integer.parseInt(year));
62+
if (!validLeapYear) {
63+
valuebox.setErrorText("Not a valid date");
64+
}
65+
66+
boolean valid = validate(month, getMonthRegex(), getMothDoesNotMatchError())
67+
&& validate(day, getDayRegex(), getDayDoesNotMatchError())
68+
&& validate(year, getYearRegex(), getYearDoesNotMatchError())
69+
&& validLeapYear;
70+
71+
if (valid) {
72+
valuebox.clearStatusText();
73+
}
74+
75+
return valid;
6176
}
62-
63-
boolean valid = validate(month, getMonthRegex(), getMothDoesNotMatchError())
64-
&& validate(day, getDayRegex(), getDayDoesNotMatchError())
65-
&& validate(year, getYearRegex(), getYearDoesNotMatchError())
66-
&& validLeapYear;
67-
68-
if (valid) {
69-
valuebox.clearStatusText();
70-
}
71-
72-
return valid;
77+
} catch (Exception e) {
78+
valuebox.setErrorText("Not a valid date");
7379
}
7480
return false;
7581
}

src/main/java/gwt/material/design/addins/client/moment/Moment.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,9 +944,7 @@ public class Moment {
944944
*/
945945
@JsMethod
946946
public native String toJDFString(String format);
947-
948947
public native MomentTimezone tz(String timeZone);
949-
950948
@JsMethod(namespace = "moment")
951949
public static native void updateLocale(String locale, LocaleOptions localeOptions);
952950
}

src/main/java/gwt/material/design/addins/client/moment/MomentTimezone.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,24 @@
1919
*/
2020
package gwt.material.design.addins.client.moment;
2121

22+
import jsinterop.annotations.JsConstructor;
2223
import jsinterop.annotations.JsMethod;
2324
import jsinterop.annotations.JsPackage;
2425
import jsinterop.annotations.JsType;
2526

26-
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "moment")
27-
public class MomentTimezone {
27+
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "moment.tz")
28+
public class MomentTimezone extends Moment {
29+
30+
@JsConstructor
31+
public MomentTimezone(String date, String timezone) { // moment.tz("asd", "asd")
32+
33+
}
2834

2935
public native MomentTimezone zone(String timeZone);
3036

3137
public native String format(String format);
3238

33-
@JsMethod(namespace = "moment.tz")
39+
@JsMethod
3440
public static native String guess();
3541

3642
public native MomentTimezone add(int amount, String unit);

src/main/java/gwt/material/design/incubator/client/daterange/DateRangePicker.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,17 @@ public class DateRangePicker extends AbstractValueWidget<Date[]> implements HasD
6666
static {
6767
if (AddinsIncubator.isDebug()) {
6868
MaterialDesignBase.injectDebugJs(MomentClientDebugBundle.INSTANCE.momentDebugJs());
69+
MaterialDesignBase.injectDebugJs(MomentClientDebugBundle.INSTANCE.momentLocale());
6970
MaterialDesignBase.injectDebugJs(MomentClientDebugBundle.INSTANCE.momentJDateConverterDebugJs());
71+
MaterialDesignBase.injectDebugJs(MomentClientDebugBundle.INSTANCE.momentWithTimezone());
7072
MaterialDesignBase.injectDebugJs(DateRangeClientDebugBundle.INSTANCE.dateRangePickerDebugJs());
7173
MaterialDesignBase.injectCss(DateRangeClientDebugBundle.INSTANCE.dateRangePickerDebugCss());
7274
MaterialDesignBase.injectCss(DateRangeClientDebugBundle.INSTANCE.dateRangePickerOverrideDebugCss());
7375
} else {
7476
MaterialDesignBase.injectJs(MomentClientBundle.INSTANCE.momentJs());
77+
MaterialDesignBase.injectJs(MomentClientBundle.INSTANCE.momentWithLocale());
7578
MaterialDesignBase.injectJs(MomentClientBundle.INSTANCE.momentJDateConverterJs());
79+
MaterialDesignBase.injectJs(MomentClientBundle.INSTANCE.momentWithTimezone());
7680
MaterialDesignBase.injectJs(DateRangeClientBundle.INSTANCE.dateRangePickerJs());
7781
MaterialDesignBase.injectCss(DateRangeClientBundle.INSTANCE.dateRangePickerCss());
7882
MaterialDesignBase.injectCss(DateRangeClientBundle.INSTANCE.dateRangePickerOverrideCss());

0 commit comments

Comments
 (0)