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.

DndTableTargetDetails.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright 2000-2013 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.data.util.BeanItemContainer;
  18. import com.vaadin.event.dd.DragAndDropEvent;
  19. import com.vaadin.event.dd.DropHandler;
  20. import com.vaadin.event.dd.TargetDetailsImpl;
  21. import com.vaadin.event.dd.acceptcriteria.AcceptAll;
  22. import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
  23. import com.vaadin.server.VaadinRequest;
  24. import com.vaadin.shared.MouseEventDetails;
  25. import com.vaadin.tests.components.AbstractTestUI;
  26. import com.vaadin.ui.Label;
  27. import com.vaadin.ui.Table;
  28. import com.vaadin.ui.Table.TableDragMode;
  29. import com.vaadin.ui.VerticalLayout;
  30. /**
  31. * Test UI for table as a drop target: AbstractSelectTargetDetails should
  32. * provide getMouseEvent() method.
  33. *
  34. * @author Vaadin Ltd
  35. */
  36. public class DndTableTargetDetails extends AbstractTestUI {
  37. @Override
  38. protected void setup(VaadinRequest request) {
  39. createSourceTable();
  40. Table target = new Table();
  41. BeanItemContainer<TestBean> container = new BeanItemContainer<TestBean>(
  42. TestBean.class);
  43. container.addBean(new TestBean("target-item"));
  44. target.setContainerDataSource(container);
  45. target.setPageLength(1);
  46. target.addStyleName("target");
  47. target.setWidth(100, Unit.PERCENTAGE);
  48. target.setDropHandler(new TestDropHandler());
  49. addComponent(target);
  50. }
  51. protected void createSourceTable() {
  52. Table table = new Table();
  53. table.setPageLength(1);
  54. table.setDragMode(TableDragMode.ROW);
  55. table.setWidth(100, Unit.PERCENTAGE);
  56. BeanItemContainer<TestBean> container = new BeanItemContainer<TestBean>(
  57. TestBean.class);
  58. container.addBean(new TestBean("item"));
  59. table.setContainerDataSource(container);
  60. addComponent(table);
  61. }
  62. @Override
  63. protected String getTestDescription() {
  64. return "Mouse details should be available for AbstractSelectTargetDetails DnD when table is a target";
  65. }
  66. @Override
  67. protected Integer getTicketNumber() {
  68. return 13416;
  69. }
  70. protected static class TestDropHandler implements DropHandler {
  71. public TestDropHandler() {
  72. }
  73. @Override
  74. public void drop(DragAndDropEvent event) {
  75. TargetDetailsImpl details = (TargetDetailsImpl) event
  76. .getTargetDetails();
  77. MouseEventDetails mouseDetails = details.getMouseEvent();
  78. VerticalLayout layout = (VerticalLayout) details.getTarget()
  79. .getUI().getContent();
  80. Label name = new Label("Button name="
  81. + mouseDetails.getButtonName());
  82. name.addStyleName("dnd-button-name");
  83. layout.addComponent(name);
  84. if (mouseDetails.isCtrlKey()) {
  85. name.addStyleName("ctrl");
  86. }
  87. if (mouseDetails.isAltKey()) {
  88. name.addStyleName("alt");
  89. }
  90. if (mouseDetails.isShiftKey()) {
  91. name.addStyleName("shift");
  92. }
  93. layout.addComponent(name);
  94. }
  95. @Override
  96. public AcceptCriterion getAcceptCriterion() {
  97. return AcceptAll.get();
  98. }
  99. }
  100. public static class TestBean {
  101. private String name;
  102. public TestBean(String name) {
  103. this.name = name;
  104. }
  105. public String getName() {
  106. return name;
  107. }
  108. }
  109. }