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.

TabletContextMenu.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright 2000-2014 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.table;
  17. import com.vaadin.event.Action;
  18. import com.vaadin.event.Action.Handler;
  19. import com.vaadin.event.ShortcutAction;
  20. import com.vaadin.server.VaadinRequest;
  21. import com.vaadin.tests.components.AbstractTestUI;
  22. import com.vaadin.ui.HorizontalLayout;
  23. import com.vaadin.ui.Table;
  24. /**
  25. * A test UI for context menus on different parts of a VSCrollTable.
  26. *
  27. * This UI has no attached unit test due to the poor support of touch events on
  28. * Selenium.
  29. *
  30. * @since
  31. * @author Vaadin Ltd
  32. */
  33. public class TabletContextMenu extends AbstractTestUI {
  34. /*
  35. * (non-Javadoc)
  36. *
  37. * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
  38. * VaadinRequest)
  39. */
  40. @Override
  41. protected void setup(VaadinRequest request) {
  42. setSizeFull();
  43. HorizontalLayout layout = new HorizontalLayout();
  44. layout.setSizeFull();
  45. layout.setSpacing(true);
  46. addComponent(layout);
  47. Table table1 = createTable("no scrolling, has context menu");
  48. addActionHandler(table1);
  49. table1.addItem();
  50. layout.addComponent(table1);
  51. Table table2 = createTable("should scroll, has context menu");
  52. for (int i = 0; i < 100; ++i) {
  53. table2.addItem();
  54. }
  55. addActionHandler(table2);
  56. layout.addComponent(table2);
  57. Table table3 = createTable("no scrolling, no context menu");
  58. table3.addItem();
  59. layout.addComponent(table3);
  60. Table table4 = createTable("should scroll, no context menu");
  61. for (int i = 0; i < 100; ++i) {
  62. table4.addItem();
  63. }
  64. layout.addComponent(table4);
  65. }
  66. private Table createTable(String caption) {
  67. Table table = new Table(caption);
  68. table.setImmediate(true);
  69. table.addContainerProperty("column1", String.class, "test");
  70. table.setSizeFull();
  71. table.setHeight("500px");
  72. table.setSelectable(true);
  73. return table;
  74. }
  75. private void addActionHandler(Table table) {
  76. table.addActionHandler(new Handler() {
  77. Action tabNext = new ShortcutAction("Shift",
  78. ShortcutAction.KeyCode.TAB, null);
  79. Action tabPrev = new ShortcutAction("Shift+Tab",
  80. ShortcutAction.KeyCode.TAB,
  81. new int[] { ShortcutAction.ModifierKey.SHIFT });
  82. Action curDown = new ShortcutAction("Down",
  83. ShortcutAction.KeyCode.ARROW_DOWN, null);
  84. Action curUp = new ShortcutAction("Up",
  85. ShortcutAction.KeyCode.ARROW_UP, null);
  86. Action enter = new ShortcutAction("Enter",
  87. ShortcutAction.KeyCode.ENTER, null);
  88. Action add = new ShortcutAction("Add Below",
  89. ShortcutAction.KeyCode.A, null);
  90. Action delete = new ShortcutAction("Delete",
  91. ShortcutAction.KeyCode.DELETE, null);
  92. @Override
  93. public void handleAction(Action action, Object sender, Object target) {
  94. System.out.println(action.getCaption());
  95. }
  96. @Override
  97. public Action[] getActions(Object target, Object sender) {
  98. return new Action[] { tabNext, tabPrev, curDown, curUp, enter,
  99. add, delete };
  100. }
  101. });
  102. }
  103. /*
  104. * (non-Javadoc)
  105. *
  106. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  107. */
  108. @Override
  109. protected String getTestDescription() {
  110. return "Make sure empty table parts have context menu on touch screen devices";
  111. }
  112. /*
  113. * (non-Javadoc)
  114. *
  115. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  116. */
  117. @Override
  118. protected Integer getTicketNumber() {
  119. return 13694;
  120. }
  121. }