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.

AbstractOrderedLayoutTest.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.vaadin.tests.components;
  2. import java.util.LinkedHashMap;
  3. import com.vaadin.event.LayoutEvents.LayoutClickEvent;
  4. import com.vaadin.event.LayoutEvents.LayoutClickListener;
  5. import com.vaadin.ui.AbstractOrderedLayout;
  6. import com.vaadin.ui.Component;
  7. public abstract class AbstractOrderedLayoutTest<T extends AbstractOrderedLayout>
  8. extends AbstractLayoutTest<T> implements LayoutClickListener {
  9. private Command<T, Boolean> layoutClickListenerCommand = new Command<T, Boolean>() {
  10. @Override
  11. public void execute(T c, Boolean value, Object data) {
  12. if (value) {
  13. c.addLayoutClickListener(AbstractOrderedLayoutTest.this);
  14. } else {
  15. }
  16. }
  17. };
  18. private Command<T, Integer> setComponentExpandRatio = new Command<T, Integer>() {
  19. @Override
  20. public void execute(T c, Integer value, Object ratio) {
  21. Component child = getComponentAtIndex(c, value);
  22. c.setExpandRatio(child, (Float) ratio);
  23. }
  24. };
  25. @Override
  26. protected void createActions() {
  27. super.createActions();
  28. createLayoutClickListenerAction(CATEGORY_LISTENERS);
  29. createChangeComponentExpandRatioAction(CATEGORY_LAYOUT_FEATURES);
  30. // Set a root style so we can see the component. Can be overridden by
  31. // setting the style name in the UI
  32. for (T c : getTestComponents()) {
  33. c.setStyleName("background-lightblue");
  34. }
  35. }
  36. private void createLayoutClickListenerAction(String category) {
  37. createBooleanAction("Layout click listener", category, false,
  38. layoutClickListenerCommand);
  39. }
  40. private void createChangeComponentExpandRatioAction(String category) {
  41. String expandRatioCategory = "Component expand ratio";
  42. createCategory(expandRatioCategory, category);
  43. LinkedHashMap<String, Float> options = new LinkedHashMap<>();
  44. options.put("0", 0f);
  45. options.put("0.5", 0.5f);
  46. for (float f = 1; f <= 5; f++) {
  47. options.put(String.valueOf(f), f);
  48. }
  49. for (int i = 0; i < 20; i++) {
  50. String componentExpandRatioCategory = "Component " + i
  51. + " expand ratio";
  52. createCategory(componentExpandRatioCategory, expandRatioCategory);
  53. for (String option : options.keySet()) {
  54. createClickAction(option, componentExpandRatioCategory,
  55. setComponentExpandRatio, Integer.valueOf(i),
  56. options.get(option));
  57. }
  58. }
  59. }
  60. @Override
  61. public void layoutClick(LayoutClickEvent event) {
  62. log(event.getClass().getSimpleName() + ": button="
  63. + event.getButtonName() + ", childComponent="
  64. + event.getChildComponent().getClass().getSimpleName()
  65. + ", relativeX=" + event.getRelativeX() + ", relativeY="
  66. + event.getRelativeY());
  67. }
  68. }