Skip to content

Commit 629503c

Browse files
committed
Merge branch 'release_2.1.1' of https://github.com/GwtMaterialDesign/gwt-material into release_2.1.1
2 parents 82e59a1 + 4b7d8e1 commit 629503c

File tree

6 files changed

+104
-96
lines changed

6 files changed

+104
-96
lines changed

gwt-material/src/main/java/gwt/material/design/client/base/helper/EventHelper.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ public final class EventHelper {
3030

3131
public static void onAttachOnce(HasAttachHandlers has, AttachEvent.Handler handler) {
3232
HandlerRegistration[] reg = new HandlerRegistration[1];
33-
reg[0] = has.addAttachHandler(event -> {
34-
if(event.isAttached()) {
35-
handler.onAttachOrDetach(event);
3633

37-
if (reg[0] != null) {
38-
reg[0].removeHandler();
34+
if (has.isAttached()) {
35+
handler.onAttachOrDetach(null);
36+
} else {
37+
reg[0] = has.addAttachHandler(event -> {
38+
if (event.isAttached()) {
39+
handler.onAttachOrDetach(event);
40+
41+
if (reg[0] != null) {
42+
reg[0].removeHandler();
43+
}
3944
}
40-
}
41-
});
45+
});
46+
}
4247
}
4348
}

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialDatePicker.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ public void reload() {
190190

191191
/**
192192
* As of now use {@link MaterialDatePicker#setSelectionType(MaterialDatePickerType)}
193-
*
194-
* @param type
195193
*/
196194
@Deprecated
197195
public void setDateSelectionType(MaterialDatePickerType type) {
@@ -399,28 +397,23 @@ public void setFormat(String format) {
399397

400398
@Override
401399
public Date getValue() {
402-
if (isAttached()) {
403-
return getPickerDate();
404-
}
405-
else {
406-
return this.date;
407-
}
400+
return isAttached() ? getPickerDate() : this.date;
408401
}
409402

410403
@Override
411404
public void setValue(Date value, boolean fireEvents) {
412405
this.date = value;
413406
if (value == null) {
414407
clear();
415-
return;
416-
}
417-
if (isAttached()) {
418-
suppressChangeEvent = !fireEvents;
419-
setPickerDate(JsDate.create((double) value.getTime()), pickatizedDateInput);
420-
suppressChangeEvent = false;
421-
label.addStyleName(CssName.ACTIVE);
408+
} else {
409+
if (isAttached()) {
410+
suppressChangeEvent = !fireEvents;
411+
setPickerDate(JsDate.create((double) value.getTime()), pickatizedDateInput);
412+
suppressChangeEvent = false;
413+
label.addStyleName(CssName.ACTIVE);
414+
}
415+
super.setValue(value, fireEvents);
422416
}
423-
super.setValue(value, fireEvents);
424417
}
425418

426419
@Override
@@ -476,7 +469,7 @@ protected void setupLanguage(DatePickerLanguage language) {
476469
if (language.getJs() != null) {
477470
ScriptInjector.fromString(language.getJs().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
478471
getPicker().stop();
479-
Scheduler.get().scheduleDeferred(() -> load());
472+
Scheduler.get().scheduleDeferred(this::load);
480473
}
481474
}
482475

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialListValueBox.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,11 @@ public void setValue(T value) {
627627
@Override
628628
public void setValue(T value, boolean fireEvents) {
629629
int index = values.indexOf(value);
630-
if (index >= 0) {
630+
if (index < 0 && value instanceof String) {
631+
index = getIndexByString((String) value);
632+
}
633+
634+
if (index > -1) {
631635
T before = getValue();
632636
setSelectedIndexInternal(index);
633637

@@ -637,6 +641,28 @@ public void setValue(T value, boolean fireEvents) {
637641
}
638642
}
639643

644+
// TODO: Optimize performance (maybe use a map)
645+
public T getValueByString(String key) {
646+
for (T value : values) {
647+
if (keyFactory.generateKey(value).equals(key)) {
648+
return value;
649+
}
650+
}
651+
return null;
652+
}
653+
654+
// TODO: Optimize performance (maybe use a map)
655+
public int getIndexByString(String key) {
656+
int index = -1;
657+
for (T value : values) {
658+
index++;
659+
if (keyFactory.generateKey(value).equals(key)) {
660+
return index;
661+
}
662+
}
663+
return index;
664+
}
665+
640666
public boolean isOld() {
641667
return getToggleOldMixin().isOn();
642668
}

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialRange.java

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@
5353
//@formatter:on
5454
public class MaterialRange extends AbstractValueWidget<Integer> implements HasChangeHandlers, HasStatusText {
5555

56+
private static String VALUE = "value";
57+
private static String MAX = "max";
58+
private static String MIN = "min";
59+
5660
private Paragraph paragraph = new Paragraph();
5761
private MaterialInput rangeInputElement = new MaterialInput();
5862
private Span thumb = new Span();
5963
private Span value = new Span();
60-
private static String VALUE = "value";
61-
private static String MAX = "max";
62-
private static String MIN = "min";
64+
6365
private MaterialLabel errorLabel = new MaterialLabel();
6466
private StatusTextMixin<AbstractValueWidget, MaterialLabel> statusTextMixin;
6567

@@ -195,41 +197,6 @@ public void setMax(Integer max) {
195197
setIntToRangeElement(MAX, max);
196198
}
197199

198-
@Override
199-
public void setErrorText(String errorText) {
200-
getStatusTextMixin().setErrorText(errorText);
201-
}
202-
203-
@Override
204-
public void setSuccessText(String successText) {
205-
getStatusTextMixin().setSuccessText(successText);
206-
}
207-
208-
@Override
209-
public void setHelperText(String helperText) {
210-
getStatusTextMixin().setHelperText(helperText);
211-
}
212-
213-
@Override
214-
public void clearStatusText() {
215-
getStatusTextMixin().clearStatusText();
216-
}
217-
218-
@Override
219-
public void clearErrorText() {
220-
getStatusTextMixin().clearErrorText();
221-
}
222-
223-
@Override
224-
public void clearHelperText() {
225-
getStatusTextMixin().clearHelperText();
226-
}
227-
228-
@Override
229-
public void clearSuccessText() {
230-
getStatusTextMixin().clearSuccessText();
231-
}
232-
233200
public MaterialLabel getErrorLabel() {
234201
return errorLabel;
235202
}

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialSwitch.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,26 +198,6 @@ public void setLabel(Label label) {
198198
this.label = label;
199199
}
200200

201-
@Override
202-
public void setErrorText(String errorText) {
203-
getStatusTextMixin().setErrorText(errorText);
204-
}
205-
206-
@Override
207-
public void setSuccessText(String successText) {
208-
getStatusTextMixin().setSuccessText(successText);
209-
}
210-
211-
@Override
212-
public void setHelperText(String helperText) {
213-
getStatusTextMixin().setHelperText(helperText);
214-
}
215-
216-
@Override
217-
public void clearStatusText() {
218-
getStatusTextMixin().clearStatusText();
219-
}
220-
221201
/**
222202
* Set the On State Label of the switch component
223203
*/

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialToast.java

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
*/
2020
package gwt.material.design.client.ui;
2121

22+
import com.google.gwt.dom.client.Element;
2223
import com.google.gwt.dom.client.Style.Unit;
2324
import com.google.gwt.user.client.DOM;
2425
import com.google.gwt.user.client.ui.RootPanel;
2526
import com.google.gwt.user.client.ui.Widget;
2627
import gwt.material.design.client.js.JsMaterialElement;
2728
import gwt.material.design.jquery.client.api.Functions;
29+
import gwt.material.design.jquery.client.api.JQueryElement;
2830

2931
import static gwt.material.design.jquery.client.api.JQuery.$;
3032

@@ -58,6 +60,8 @@ public class MaterialToast {
5860
private Functions.Func callback;
5961
private Widget[] widgets;
6062

63+
private JQueryElement element;
64+
6165
public MaterialToast(Widget... widgets) {
6266
this.widgets = widgets;
6367
}
@@ -140,23 +144,19 @@ public void toast(String msg, String className) {
140144
* @param className class name to custom style your toast.
141145
*/
142146
public void toast(String msg, int lifeMillis, String className) {
143-
String genId = DOM.createUniqueId();
144-
if (className == null) {
145-
className = genId;
147+
String id;
148+
if (element != null) {
149+
id = (String) element.attr("id");
146150
} else {
147-
className += ' ' + genId;
151+
id = DOM.createUniqueId();
148152
}
149-
toast(msg, lifeMillis, genId, className, callback);
150153

151-
if (widgets != null) {
152-
for (Widget widget : widgets) {
153-
widget.getElement().getStyle().setPaddingLeft(30, Unit.PX);
154-
RootPanel.get(genId).add(widget);
155-
}
154+
if (className == null) {
155+
className = id;
156+
} else {
157+
className += ' ' + id;
156158
}
157-
}
158159

159-
protected void toast(String msg, int lifeMillis, String id, String className, Functions.Func callback) {
160160
Object duration = lifeMillis;
161161
if (lifeMillis <= 0) {
162162
duration = "unlimited";
@@ -168,6 +168,43 @@ protected void toast(String msg, int lifeMillis, String id, String className, Fu
168168
}
169169
});
170170

171-
$(".toast." + id).attr("id", id);
171+
element = $(".toast." + id);
172+
element.attr("id", id);
173+
//element.toggleClass(className, true);
174+
175+
if (widgets != null) {
176+
RootPanel toast = RootPanel.get(id);
177+
for (Widget widget : widgets) {
178+
widget.getElement().getStyle().setPaddingLeft(20, Unit.PX);
179+
toast.add(widget);
180+
}
181+
}
182+
}
183+
184+
public void close() {
185+
String id = getId();
186+
if (id != null && !id.isEmpty()) {
187+
Widget toast = RootPanel.get(id);
188+
if (toast != null && toast.isAttached()) {
189+
element.remove();
190+
}
191+
}
192+
}
193+
194+
public boolean isOpen() {
195+
String id = getId();
196+
if (id != null && !id.isEmpty()) {
197+
Widget toast = RootPanel.get(id);
198+
return toast.isAttached() && toast.isVisible();
199+
}
200+
return false;
201+
}
202+
203+
public String getId() {
204+
return element != null ? (String) element.attr("id") : null;
205+
}
206+
207+
public JQueryElement getElement() {
208+
return element;
172209
}
173210
}

0 commit comments

Comments
 (0)