You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractListingFocusBlurTest.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components;
  17. import java.lang.reflect.ParameterizedType;
  18. import java.lang.reflect.Type;
  19. import java.util.stream.Collectors;
  20. import java.util.stream.IntStream;
  21. import com.googlecode.gentyref.GenericTypeReflector;
  22. import com.vaadin.event.FieldEvents.BlurNotifier;
  23. import com.vaadin.event.FieldEvents.FocusNotifier;
  24. import com.vaadin.server.VaadinRequest;
  25. import com.vaadin.ui.AbstractListing;
  26. /**
  27. * @author Vaadin Ltd
  28. *
  29. */
  30. public abstract class AbstractListingFocusBlurTest<T extends AbstractListing<Integer> & FocusNotifier & BlurNotifier>
  31. extends AbstractTestUIWithLog {
  32. @Override
  33. @SuppressWarnings("unchecked")
  34. protected void setup(VaadinRequest request) {
  35. Type valueType = GenericTypeReflector.getTypeParameter(getClass(),
  36. AbstractListingFocusBlurTest.class.getTypeParameters()[0]);
  37. if (valueType instanceof ParameterizedType) {
  38. valueType = ((ParameterizedType) valueType).getRawType();
  39. }
  40. if (valueType instanceof Class<?>) {
  41. Class<T> clazz = (Class<T>) valueType;
  42. try {
  43. T select = clazz.newInstance();
  44. select.setItems(
  45. IntStream.range(1, 10).mapToObj(Integer::valueOf)
  46. .collect(Collectors.toList()));
  47. addComponent(select);
  48. select.addFocusListener(event -> log("Focus Event"));
  49. select.addBlurListener(event -> log("Blur Event"));
  50. } catch (InstantiationException | IllegalAccessException e) {
  51. throw new RuntimeException(e);
  52. }
  53. } else {
  54. throw new RuntimeException(
  55. "Unexpected component type " + valueType.getTypeName());
  56. }
  57. }
  58. }