1919 */
2020package gwt .material .design .addins .client .livestamp ;
2121
22- import com .google .gwt .core .client .GWT ;
2322import com .google .gwt .dom .client .Document ;
24- import com .google .gwt .dom .client .Element ;
2523import gwt .material .design .addins .client .MaterialAddins ;
24+ import gwt .material .design .addins .client .livestamp .js .JsLiveStamp ;
2625import gwt .material .design .addins .client .moment .resources .MomentClientBundle ;
2726import gwt .material .design .addins .client .moment .resources .MomentClientDebugBundle ;
2827import gwt .material .design .client .MaterialDesignBase ;
2928import gwt .material .design .client .base .AbstractValueWidget ;
30- import gwt .material .design .client .base .JsLoader ;
3129
3230import java .util .Date ;
3331
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}
0 commit comments