import com.vaadin.tokka.event.Handler;
import com.vaadin.tokka.event.Registration;
import com.vaadin.ui.Component;
-import com.vaadin.ui.Component.LegacyEvent;
import com.vaadin.ui.HasComponents;
import com.vaadin.ui.LegacyComponent;
import com.vaadin.ui.UI;
}
/**
- * Checks if the given {@link LegacyEvent} type is listened for this
- * component.
+ * Checks if the given event type is listened for this component.
*
* @param eventType
* the event type to be checked
private static final Method EVENT_HANDLER_METHOD = ReflectTools
.findMethod(Handler.class, "accept", Event.class);
- @SuppressWarnings("rawtypes")
protected <T> Registration onEvent(Class<? extends Event> eventType,
Handler<? super T> handler) {
Objects.requireNonNull(handler, "Handler cannot be null");
return () -> removeListener(eventType, handler);
}
- @SuppressWarnings("rawtypes")
protected <T> Registration onEvent(String eventId,
Class<? extends Event> eventType, Handler<? super T> handler) {
+ Objects.requireNonNull(handler, "Handler cannot be null");
addListener(eventId, eventType, handler, EVENT_HANDLER_METHOD);
return () -> removeListener(eventType, handler);
}
import com.vaadin.server.ClientConnector;
/**
- * Generic event object typed for pay load.
+ * A base class for user interface events fired by connectors.
*
+ * @author Vaadin Ltd.
* @since
- * @param <T>
- * pay load type
*/
-public class Event<T> extends EventObject {
-
- /**
- * Pay load value.
- */
- private final T value;
+public class Event extends EventObject {
/**
* {@code true} if event from a client-side update, {@code false} if from an
* @param userOriginated
* is the event from API call or client update
*/
- public Event(ClientConnector source, T value, boolean userOriginated) {
+ public Event(ClientConnector source, boolean userOriginated) {
super(source);
- this.value = value;
this.userOriginated = userOriginated;
}
- /**
- * Gets the payload value.
- *
- * @return payload value
- */
- public T getValue() {
- return value;
- }
-
/**
* Gets the origin of this event.
*
import java.util.function.Consumer;
/**
- * Generic interface for event handlers. Event handlers are removed using a
- * {@link Registration} object.
+ * A base interface for event handlers.
*
+ * @param <E>
+ * the event type
+ *
+ * @author Vaadin Ltd.
* @since
+ *
* @see Event
* @see Registration
- * @param <T>
- * event pay load type
*/
@FunctionalInterface
-public interface Handler<T> extends Consumer<Event<T>>, Serializable {
+public interface Handler<E extends Event> extends Consumer<E>, Serializable {
/**
* Handles the given event.
// Class.getDeclaredMethod, but even if it used getMethod instead, the
// superinterface argument type is Object, not Event, after type erasure.
@Override
- void accept(Event<T> e);
+ void accept(E e);
}
*/
package com.vaadin.tokka.server.communication.data;
-import java.io.Serializable;
import java.util.Collection;
-import com.vaadin.server.ClientConnector;
-import com.vaadin.tokka.event.Event;
import com.vaadin.tokka.server.ListingExtension;
import com.vaadin.tokka.ui.components.HasValue;
+import com.vaadin.tokka.ui.components.HasValue.ValueChange;
import com.vaadin.tokka.ui.components.Listing;
import com.vaadin.ui.Component;
* @param <T>
* type of selected values
*/
-public interface SelectionModel<T> extends Serializable, ListingExtension<T> {
+public interface SelectionModel<T> extends ListingExtension<T> {
- public class SelectionEvent<T> extends Event<T> {
- public SelectionEvent(ClientConnector source, T value,
+ public class SelectionChange<T> extends ValueChange<T> {
+ public SelectionChange(SelectionModel<T> source, T value,
boolean userOriginated) {
super(source, value, userOriginated);
}
if (value != null) {
refresh(value);
}
- fireEvent(new SelectionEvent<T>(this, value, userOriginated));
+ fireEvent(new SelectionChange<T>(this, value, userOriginated));
}
}
}
@Override
- public Registration onChange(Handler<T> handler) {
- return onEvent(SelectionEvent.class, handler);
+ public Registration onChange(Handler<ValueChange<T>> handler) {
+ return onEvent(SelectionChange.class, handler);
}
@Override
import java.io.Serializable;
+import com.vaadin.server.ClientConnector;
+import com.vaadin.tokka.event.Event;
import com.vaadin.tokka.event.Handler;
import com.vaadin.tokka.event.Registration;
*/
public interface HasValue<V> extends Serializable {
+ public abstract class ValueChange<V> extends Event {
+
+ private final V value;
+
+ protected <C extends ClientConnector & HasValue<V>> ValueChange(
+ C source, boolean userOriginated) {
+ this(source, source.getValue(), userOriginated);
+ }
+
+ protected ValueChange(ClientConnector source, V value,
+ boolean userOriginated) {
+ super(source, userOriginated);
+ this.value = value;
+ }
+
+ /**
+ * Returns the payload value.
+ *
+ * @return payload value
+ */
+ public V getValue() {
+ return value;
+ }
+ }
+
/**
* Sets the value of this object. Setting a value fires a value change
* event.
* @throws IllegalArgumentException
* if handler is null
*/
- Registration onChange(Handler<V> handler);
+ Registration onChange(Handler<ValueChange<V>> handler);
}
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
-import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.shared.tokka.ui.components.fields.TextFieldServerRpc;
import com.vaadin.shared.tokka.ui.components.fields.TextFieldState;
-import com.vaadin.tokka.event.Event;
import com.vaadin.tokka.event.Handler;
import com.vaadin.tokka.event.Registration;
import com.vaadin.tokka.ui.components.HasValue;
public abstract class AbstractTextField extends AbstractComponent
implements HasValue<String> {
- public static class TextChangeEvent
- extends Event<String> {
-
- public static final String ID = TextChangeListener.EVENT_ID;
-
- public TextChangeEvent(AbstractTextField source, String text,
- boolean userOriginated) {
- super(source, text, userOriginated);
+ public static class TextChange extends ValueChange<String> {
+ public TextChange(AbstractTextField source, boolean userOriginated) {
+ super(source, userOriginated);
}
}
public void setText(String text) {
if (!isReadOnly()) {
setValue(text);
- fireEvent(new TextChangeEvent(AbstractTextField.this, text,
- true));
+ fireEvent(new TextChange(AbstractTextField.this, true));
}
}
});
}
@Override
- public Registration onChange(Handler<String> handler) {
- return onEvent(TextChangeEvent.ID, TextChangeEvent.class, handler);
+ public Registration onChange(Handler<ValueChange<String>> handler) {
+ return onEvent(TextChange.class, handler);
}
/**
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
import com.vaadin.shared.ui.checkbox.CheckBoxState;
-import com.vaadin.tokka.event.Event;
import com.vaadin.tokka.event.Handler;
import com.vaadin.tokka.event.Registration;
import com.vaadin.tokka.ui.components.HasValue;
public class CheckBox extends AbstractComponent implements HasValue<Boolean> {
- public class StateChangeEvent extends Event<Boolean> {
- public StateChangeEvent(Boolean value, boolean userOriginated) {
- super(CheckBox.this, value, userOriginated);
+ public class StateChange extends ValueChange<Boolean> {
+ public StateChange(boolean userOriginated) {
+ super(CheckBox.this, userOriginated);
}
}
return;
}
getState(!userOriginated).checked = value;
- fireEvent(new StateChangeEvent(value, userOriginated));
+ fireEvent(new StateChange(userOriginated));
}
@Override
- public Registration onChange(Handler<Boolean> handler) {
- return onEvent(StateChangeEvent.class, handler);
+ public Registration onChange(Handler<ValueChange<Boolean>> handler) {
+ return onEvent(StateChange.class, handler);
}
@Override
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.shared.tokka.ui.components.fields.DateFieldServerRpc;
import com.vaadin.shared.tokka.ui.components.fields.DateFieldState;
-import com.vaadin.tokka.event.Event;
import com.vaadin.tokka.event.Handler;
import com.vaadin.tokka.event.Registration;
import com.vaadin.tokka.ui.components.HasValue;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter
.ofPattern("dd-MM-uuuu");
- public static class DateChange extends Event<LocalDate> {
- protected DateChange(DateField source, LocalDate date,
- boolean userOriginated) {
- super(source, date, userOriginated);
+ public static class DateChange extends ValueChange<LocalDate> {
+ protected DateChange(DateField source, boolean userOriginated) {
+ super(source, userOriginated);
}
}
LocalDate localDate = FORMATTER.parse(value,
TemporalQueries.localDate());
setValue(localDate);
- fireEvent(new DateChange(DateField.this, localDate, true));
+ fireEvent(new DateChange(DateField.this, true));
}
}
});
}
@Override
- public Registration onChange(Handler<LocalDate> handler) {
+ public Registration onChange(Handler<ValueChange<LocalDate>> handler) {
return onEvent(DateChange.class, handler);
}