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.

FocusingComponents.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.vaadin.tests;
  2. import com.vaadin.tests.components.TestDateField;
  3. import com.vaadin.ui.Button;
  4. import com.vaadin.ui.CustomComponent;
  5. import com.vaadin.ui.GridLayout;
  6. import com.vaadin.v7.ui.AbstractSelect;
  7. import com.vaadin.v7.ui.ComboBox;
  8. import com.vaadin.v7.ui.ListSelect;
  9. import com.vaadin.v7.ui.NativeSelect;
  10. import com.vaadin.v7.ui.OptionGroup;
  11. import com.vaadin.v7.ui.TextField;
  12. /**
  13. * Simple test helper to test Focusable.focus() method.
  14. *
  15. */
  16. public class FocusingComponents extends CustomComponent {
  17. GridLayout lo = new GridLayout(2, 1);
  18. public FocusingComponents() {
  19. setCompositionRoot(lo);
  20. lo.setSpacing(true);
  21. Focusable f;
  22. f = new Button();
  23. addFocusableTest(f);
  24. addFocusableTest(new ComboBox());
  25. addFocusableTest(new TextField());
  26. addFocusableTest(new TestDateField());
  27. addFocusableTest(new NativeSelect());
  28. addFocusableTest(new ListSelect());
  29. addFocusableTest(new OptionGroup());
  30. OptionGroup optionGroup = new OptionGroup();
  31. optionGroup.setMultiSelect(true);
  32. addFocusableTest(optionGroup);
  33. }
  34. private void addFocusableTest(final Focusable f) {
  35. f.setCaption(f.getClass().getSimpleName());
  36. lo.addComponent(f);
  37. if (f instanceof AbstractSelect) {
  38. AbstractSelect s = (AbstractSelect) f;
  39. s.addItem("Foo");
  40. s.addItem("Bar");
  41. }
  42. Button focus = new Button("focus");
  43. focus.addClickListener(event -> f.focus());
  44. lo.addComponent(focus);
  45. }
  46. }