Skip to content

Commit d5fe1bd

Browse files
committed
Livestamp support for setting null values.
1 parent f6959a4 commit d5fe1bd

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

src/main/java/gwt/material/design/addins/client/livestamp/MaterialLiveStamp.java

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
*/
2020
package gwt.material.design.addins.client.livestamp;
2121

22-
import com.google.gwt.core.client.GWT;
2322
import com.google.gwt.dom.client.Document;
24-
import com.google.gwt.dom.client.Element;
2523
import gwt.material.design.addins.client.MaterialAddins;
24+
import gwt.material.design.addins.client.livestamp.js.JsLiveStamp;
2625
import gwt.material.design.addins.client.moment.resources.MomentClientBundle;
2726
import gwt.material.design.addins.client.moment.resources.MomentClientDebugBundle;
2827
import gwt.material.design.client.MaterialDesignBase;
2928
import gwt.material.design.client.base.AbstractValueWidget;
30-
import gwt.material.design.client.base.JsLoader;
3129

3230
import java.util.Date;
3331

@@ -56,9 +54,9 @@
5654
* @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#livestamp">Material Live Stamp</a>
5755
* @see <a href="https://github.com/mattbradley/livestampjs">LiveStamp 1.1.2</a>
5856
*/
59-
public class MaterialLiveStamp extends AbstractValueWidget<Date> implements JsLoader {
57+
public class MaterialLiveStamp extends AbstractValueWidget<Date> {
6058

61-
private Date date = new Date();
59+
private Date value = new Date();
6260

6361
static {
6462
if (MaterialAddins.isDebug()) {
@@ -75,45 +73,31 @@ public MaterialLiveStamp() {
7573
}
7674

7775
@Override
78-
protected void onLoad() {
79-
super.onLoad();
76+
protected void onUnload() {
77+
super.onUnload();
8078

81-
load();
79+
destroy();
8280
}
8381

8482
@Override
85-
public void load() {
86-
if (date != null) {
87-
setValue(date);
83+
public void setValue(Date value, boolean fireEvents) {
84+
super.setValue(value, fireEvents);
85+
this.value = value;
86+
87+
if (value != null) {
88+
getElement().setAttribute("data-livestamp", value.toString());
8889
} else {
89-
GWT.log("You must specify the date value.", new IllegalStateException());
90+
destroy();
9091
}
9192
}
9293

93-
@Override
94-
public void unload() {
95-
getElement().removeAttribute("data-livestamp");
96-
}
97-
98-
@Override
99-
public void reload() {
100-
unload();
101-
load();
102-
}
103-
104-
@Override
105-
public void setValue(Date date, boolean fireEvents) {
106-
this.date = date;
107-
108-
if (date != null) {
109-
getElement().setAttribute("data-livestamp", date.toString());
110-
111-
super.setValue(date, fireEvents);
112-
}
94+
public void destroy() {
95+
JsLiveStamp.$(getElement()).livestamp("destroy");
96+
getElement().setInnerText("-");
11397
}
11498

11599
@Override
116100
public Date getValue() {
117-
return date;
101+
return value;
118102
}
119103
}

src/main/java/gwt/material/design/addins/client/livestamp/js/JsLiveStamp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ public class JsLiveStamp extends JQueryElement {
4343
public static native JsLiveStamp $(String selector);
4444

4545
@JsMethod
46-
public native JsLiveStamp livestamp(int currentMillis);
46+
public native JsLiveStamp livestamp(String method);
4747
}

0 commit comments

Comments
 (0)