import java.util.ArrayList;
import java.util.Iterator;
+import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ChangeEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.user.client.ui.ListBox;
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.UIDL;
}
}
+ public void addFocusHandler(FocusHandler handler) {
+ select.addFocusHandler(handler);
+ }
+
+ public void addBlurHandler(BlurHandler handler) {
+ select.addBlurHandler(handler);
+ }
+
@Override
public void setHeight(String height) {
select.setHeight(height);
public void focus() {
select.setFocus(true);
}
+
}
package com.vaadin.client.ui.nativeselect;
+import com.google.gwt.event.dom.client.BlurEvent;
+import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.FocusEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
import com.vaadin.client.ui.VNativeSelect;
import com.vaadin.client.ui.optiongroup.OptionGroupBaseConnector;
+import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc;
import com.vaadin.shared.ui.Connect;
import com.vaadin.ui.NativeSelect;
@Connect(NativeSelect.class)
-public class NativeSelectConnector extends OptionGroupBaseConnector {
+public class NativeSelectConnector extends OptionGroupBaseConnector implements
+ BlurHandler, FocusHandler {
+
+ public NativeSelectConnector() {
+ super();
+ getWidget().addFocusHandler(this);
+ getWidget().addBlurHandler(this);
+ }
@Override
public VNativeSelect getWidget() {
return (VNativeSelect) super.getWidget();
}
+
+ @Override
+ public void onFocus(FocusEvent event) {
+ getRpcProxy(FocusAndBlurServerRpc.class).focus();
+ }
+
+ @Override
+ public void onBlur(BlurEvent event) {
+ getRpcProxy(FocusAndBlurServerRpc.class).blur();
+ }
}
import java.util.Collection;
import com.vaadin.data.Container;
+import com.vaadin.event.FieldEvents;
+import com.vaadin.event.FieldEvents.BlurEvent;
+import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
+import com.vaadin.event.FieldEvents.FocusEvent;
+import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
* better choice.
*/
@SuppressWarnings("serial")
-public class NativeSelect extends AbstractSelect {
+public class NativeSelect extends AbstractSelect implements
+ FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {
// width in characters, mimics TextField
private int columns = 0;
+ FocusAndBlurServerRpcImpl focusBlurRpc = new FocusAndBlurServerRpcImpl(this) {
+
+ @Override
+ protected void fireEvent(Event event) {
+ NativeSelect.this.fireEvent(event);
+ }
+ };
+
public NativeSelect() {
super();
+ registerRpc(focusBlurRpc);
}
public NativeSelect(String caption, Collection<?> options) {
}
}
+ @Override
+ public void addFocusListener(FocusListener listener) {
+ addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
+ FocusListener.focusMethod);
+ }
+
+ /**
+ * @deprecated As of 7.0, replaced by
+ * {@link #addFocusListener(FocusListener)}
+ **/
+ @Override
+ @Deprecated
+ public void addListener(FocusListener listener) {
+ addFocusListener(listener);
+ }
+
+ @Override
+ public void removeFocusListener(FocusListener listener) {
+ removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
+ }
+
+ /**
+ * @deprecated As of 7.0, replaced by
+ * {@link #removeFocusListener(FocusListener)}
+ **/
+ @Override
+ @Deprecated
+ public void removeListener(FocusListener listener) {
+ removeFocusListener(listener);
+ }
+
+ @Override
+ public void addBlurListener(BlurListener listener) {
+ addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
+ BlurListener.blurMethod);
+ }
+
+ /**
+ * @deprecated As of 7.0, replaced by {@link #addBlurListener(BlurListener)}
+ **/
+ @Override
+ @Deprecated
+ public void addListener(BlurListener listener) {
+ addBlurListener(listener);
+ }
+
+ @Override
+ public void removeBlurListener(BlurListener listener) {
+ removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
+ }
+
+ /**
+ * @deprecated As of 7.0, replaced by
+ * {@link #removeBlurListener(BlurListener)}
+ **/
+ @Override
+ @Deprecated
+ public void removeListener(BlurListener listener) {
+ removeBlurListener(listener);
+ }
+
}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.nativeselect;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class NativeSelectsFocusAndBlurListenerTests extends MultiBrowserTest {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.tb3.MultiBrowserTest#getBrowsersToTest()
+ */
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ return Collections.singletonList(Browser.CHROME
+ .getDesiredCapabilities());
+ }
+
+ @Test
+ public void testFocusListener() throws InterruptedException {
+ setDebug(true);
+ openTestURL();
+ Thread.sleep(1000);
+ menu("Component");
+ menuSub("Listeners");
+ menuSub("Focus listener");
+
+ getDriver().findElement(By.tagName("body")).click();
+
+ WebElement select = getDriver().findElement(By.tagName("select"));
+ select.click();
+
+ String bodytext = getDriver().findElement(By.tagName("body")).getText();
+
+ Assert.assertTrue(bodytext.contains("FocusEvent"));
+
+ }
+
+ @Test
+ public void testBlurListener() throws InterruptedException {
+ setDebug(true);
+ openTestURL();
+ Thread.sleep(1000);
+ menu("Component");
+ menuSub("Listeners");
+ menuSub("Blur listener");
+
+ getDriver().findElement(By.tagName("body")).click();
+
+ WebElement select = getDriver().findElement(By.tagName("select"));
+ select.click();
+
+ getDriver().findElement(By.tagName("body")).click();
+
+ String bodytext = getDriver().findElement(By.tagName("body")).getText();
+
+ Assert.assertTrue(bodytext.contains("BlurEvent"));
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.tb3.AbstractTB3Test#getUIClass()
+ */
+ @Override
+ protected Class<?> getUIClass() {
+ return NativeSelects.class;
+ }
+
+ /**
+ * @since
+ * @param string
+ */
+ private void menuSub(String string) {
+ getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))
+ .click();
+ new Actions(getDriver()).moveByOffset(100, 0).build().perform();
+ }
+
+ /**
+ * @since
+ * @param string
+ */
+ private void menu(String string) {
+ getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))
+ .click();
+
+ }
+
+}