mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
bug4210 Extracted native date time input implementation to single class
This commit is contained in:
1 parent
1187cac58e
commit
e074a216d9
7 files changed
+77
-129
No files matched your search
+1
-1
@@ -16,7 +16,7 @@ public class DateAndTimeInput extends Composite implements DateTimeInput {
|
||||
private final DateTimeInput delegate;
|
||||
|
||||
public DateAndTimeInput(Accuracy accuracy) {
|
||||
this.delegate = DateTimeInputType.DATETIME_LOCAL.isSupported() ? new NativeDatetimeLocalInput(accuracy)
|
||||
this.delegate = DateTimeInputType.DATETIME_LOCAL.isSupported() ? NativeDateTimeInput.datetimeLocale(accuracy)
|
||||
: new DateAndTimePanel(accuracy);
|
||||
initWidget(delegate.asWidget());
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,8 +17,8 @@ public class DateInput extends Composite implements DateTimeInput {
|
||||
|
||||
public DateInput() {
|
||||
if (DateTimeInputType.TIME.isSupported()) {
|
||||
final NativeDateInput input = new NativeDateInput();
|
||||
initWidget(input);
|
||||
final DateTimeInput input = NativeDateTimeInput.date();
|
||||
initWidget(input.asWidget());
|
||||
this.delegate = input;
|
||||
} else {
|
||||
final DateBox input = new DateBox();
|
||||
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.sap.sailing.gwt.common.client.datetime;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.InputElement;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
class NativeDateInput extends Widget implements DateTimeInput {
|
||||
|
||||
private static final String ATTR_TYPE = "type";
|
||||
|
||||
private final DateTimeFormat format = DateTimeFormat.getFormat("yyyy-MM-dd");
|
||||
private final InputElement input;
|
||||
|
||||
NativeDateInput() {
|
||||
this.input = Document.get().createElement(InputElement.TAG).cast();
|
||||
this.input.setAttribute(ATTR_TYPE, DateTimeInputType.DATE.getType());
|
||||
setElement(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getValue() {
|
||||
return this.format.parse(input.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Date value) {
|
||||
this.input.setValue(format.format(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Date> handler) {
|
||||
return addHandler(handler, ValueChangeEvent.getType());
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.sap.sailing.gwt.common.client.datetime;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.InputElement;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
class NativeDateTimeInput extends Widget implements DateTimeInput {
|
||||
|
||||
private static final String ATTR_TYPE = "type", ATTR_STEP = "step";
|
||||
|
||||
static DateTimeInput date() {
|
||||
return new NativeDateTimeInput(DateTimeInputType.DATE, "", DateTimeFormat.getFormat("yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
static DateTimeInput time(Accuracy accuracy) {
|
||||
return new NativeDateTimeInput(DateTimeInputType.TIME, accuracy.getStep(), accuracy.getTimeFormat());
|
||||
}
|
||||
|
||||
static DateTimeInput datetimeLocale(Accuracy accuracy) {
|
||||
return new NativeDateTimeInput(DateTimeInputType.DATETIME_LOCAL, accuracy.getStep(),
|
||||
accuracy.getDatetimeFormat());
|
||||
}
|
||||
|
||||
private final DateTimeFormat format;
|
||||
private final InputElement input;
|
||||
|
||||
private NativeDateTimeInput(DateTimeInputType inputType, String step, DateTimeFormat format) {
|
||||
this.input = Document.get().createElement(InputElement.TAG).cast();
|
||||
this.input.setAttribute(ATTR_TYPE, inputType.getType());
|
||||
this.input.setAttribute(ATTR_STEP, step);
|
||||
this.format = format;
|
||||
setElement(input);
|
||||
sinkEvents(Event.ONCHANGE | Event.ONBLUR | Event.ONKEYUP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onBrowserEvent(Event event) {
|
||||
final int type = event.getTypeInt();
|
||||
if (type == Event.ONCHANGE || type == Event.ONBLUR || type == Event.ONKEYUP) {
|
||||
ValueChangeEvent.fire(this, getValue());
|
||||
}
|
||||
super.onBrowserEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Date getValue() {
|
||||
try {
|
||||
return this.format.parse(input.getValue());
|
||||
} catch (IllegalArgumentException exc) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setValue(Date value) {
|
||||
this.input.setValue(Objects.isNull(value) ? null : format.format(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final HandlerRegistration addValueChangeHandler(ValueChangeHandler<Date> handler) {
|
||||
return addHandler(handler, ValueChangeEvent.getType());
|
||||
}
|
||||
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package com.sap.sailing.gwt.common.client.datetime;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.InputElement;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
class NativeDatetimeLocalInput extends Widget implements DateTimeInput {
|
||||
|
||||
private static final String ATTR_TYPE = "type", ATTR_STEP = "step";
|
||||
|
||||
private final DateTimeFormat format;
|
||||
private final InputElement input;
|
||||
|
||||
NativeDatetimeLocalInput(Accuracy accuracy) {
|
||||
this.input = Document.get().createElement(InputElement.TAG).cast();
|
||||
this.input.setAttribute(ATTR_TYPE, DateTimeInputType.DATETIME_LOCAL.getType());
|
||||
this.input.setAttribute(ATTR_STEP, accuracy.getStep());
|
||||
this.format = accuracy.getDatetimeFormat();
|
||||
setElement(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getValue() {
|
||||
return this.format.parse(input.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Date value) {
|
||||
this.input.setValue(format.format(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Date> handler) {
|
||||
return addHandler(handler, ValueChangeEvent.getType());
|
||||
}
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package com.sap.sailing.gwt.common.client.datetime;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.InputElement;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.event.shared.HandlerRegistration;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
class NativeTimeInput extends Widget implements DateTimeInput {
|
||||
|
||||
private static final String ATTR_TYPE = "type", ATTR_STEP = "step";
|
||||
|
||||
private final DateTimeFormat format;
|
||||
private final InputElement input;
|
||||
|
||||
NativeTimeInput(Accuracy accuracy) {
|
||||
this.input = Document.get().createElement(InputElement.TAG).cast();
|
||||
this.input.setAttribute(ATTR_TYPE, DateTimeInputType.TIME.getType());
|
||||
this.input.setAttribute(ATTR_STEP, accuracy.getStep());
|
||||
this.format = accuracy.getTimeFormat();
|
||||
setElement(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getValue() {
|
||||
return this.format.parse(input.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Date value) {
|
||||
this.input.setValue(format.format(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Date> handler) {
|
||||
return addHandler(handler, ValueChangeEvent.getType());
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -20,8 +20,8 @@ public class TimeInput extends Composite implements DateTimeInput {
|
||||
|
||||
public TimeInput(Accuracy accuracy) {
|
||||
if (DateTimeInputType.TIME.isSupported()) {
|
||||
final NativeTimeInput input = new NativeTimeInput(accuracy);
|
||||
initWidget(input);
|
||||
final DateTimeInput input = NativeDateTimeInput.time(accuracy);
|
||||
initWidget(input.asWidget());
|
||||
this.delegate = input;
|
||||
} else {
|
||||
final ValueBox<Date> input = new TimeBox(new TimeConverter(accuracy));
|
||||
|
||||
Reference in new issue
Block a user