From 25013128a7e2eb80b565d28abcc0af26219098db Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Wed, 26 Oct 2016 16:22:00 +0300 Subject: Implement focus/blur listeners for NativeSelect. Fixes vaadin/framework8-issues#332 Change-Id: I19996ea83ed1fbe2b115d92d6be5e6a5e158f283 --- .../src/main/java/com/vaadin/ui/NativeSelect.java | 44 ++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'server/src/main/java/com/vaadin/ui') diff --git a/server/src/main/java/com/vaadin/ui/NativeSelect.java b/server/src/main/java/com/vaadin/ui/NativeSelect.java index be4cbc5e12..bb3ae41df4 100644 --- a/server/src/main/java/com/vaadin/ui/NativeSelect.java +++ b/server/src/main/java/com/vaadin/ui/NativeSelect.java @@ -18,7 +18,15 @@ package com.vaadin.ui; import java.util.Collection; +import com.vaadin.event.FieldEvents.BlurEvent; +import com.vaadin.event.FieldEvents.BlurListener; +import com.vaadin.event.FieldEvents.BlurNotifier; +import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcDecorator; +import com.vaadin.event.FieldEvents.FocusEvent; +import com.vaadin.event.FieldEvents.FocusListener; +import com.vaadin.event.FieldEvents.FocusNotifier; import com.vaadin.server.data.DataSource; +import com.vaadin.shared.Registration; import com.vaadin.shared.data.DataCommunicatorConstants; import com.vaadin.shared.ui.nativeselect.NativeSelectState; @@ -34,14 +42,16 @@ import com.vaadin.shared.ui.nativeselect.NativeSelectState; * * @see com.vaadin.ui.ComboBox */ -public class NativeSelect extends AbstractSingleSelect { +public class NativeSelect extends AbstractSingleSelect + implements FocusNotifier, BlurNotifier { /** * Creates a new {@code NativeSelect} with an empty caption and no items. */ public NativeSelect() { - addDataGenerator((item, json) -> json.put( - DataCommunicatorConstants.DATA, String.valueOf(item))); + registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent)); + addDataGenerator((item, json) -> json + .put(DataCommunicatorConstants.DATA, String.valueOf(item))); setSelectionModel(new SimpleSingleSelection()); } @@ -85,6 +95,34 @@ public class NativeSelect extends AbstractSingleSelect { setDataSource(dataSource); } + @Override + public Registration addFocusListener(FocusListener listener) { + addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener, + FocusListener.focusMethod); + return () -> removeListener(FocusEvent.EVENT_ID, FocusEvent.class, + listener); + } + + @Override + @Deprecated + public void removeFocusListener(FocusListener listener) { + removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener); + } + + @Override + public Registration addBlurListener(BlurListener listener) { + addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener, + BlurListener.blurMethod); + return () -> removeListener(BlurEvent.EVENT_ID, BlurEvent.class, + listener); + } + + @Override + @Deprecated + public void removeBlurListener(BlurListener listener) { + removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener); + } + @Override protected NativeSelectState getState() { return getState(true); -- cgit v1.2.3