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.

CustomDDImplementation.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.vaadin.tests.dd;
  2. import java.util.Map;
  3. import com.vaadin.event.dd.DragAndDropEvent;
  4. import com.vaadin.event.dd.DropHandler;
  5. import com.vaadin.event.dd.DropTarget;
  6. import com.vaadin.event.dd.TargetDetails;
  7. import com.vaadin.event.dd.acceptcriteria.AcceptAll;
  8. import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
  9. import com.vaadin.ui.AbstractComponent;
  10. import com.vaadin.ui.CssLayout;
  11. import com.vaadin.ui.CustomComponent;
  12. import com.vaadin.ui.Layout;
  13. /**
  14. * Test/Example/Draft code how to build custom DD implementation using the thing
  15. * framework provided by Vaadin.
  16. *
  17. */
  18. public class CustomDDImplementation extends CustomComponent {
  19. public CustomDDImplementation() {
  20. Layout l = new CssLayout();
  21. l.addComponent(new MyDropTarget());
  22. l.addComponent(new MyDragSource());
  23. }
  24. /**
  25. * Server side component that accepts drags must implement HasDropHandler
  26. * that have one method to get reference of DropHandler.
  27. *
  28. * DropHandler may be implemented directly or probably most commonly using a
  29. * half baked implementation {@link AbstractDropHandler}.
  30. *
  31. * Check the @ClientWidget
  32. *
  33. */
  34. class MyDropTarget extends AbstractComponent implements DropTarget {
  35. @Override
  36. public DropHandler getDropHandler() {
  37. return new DropHandler() {
  38. @Override
  39. public void drop(DragAndDropEvent event) {
  40. // Do something with data
  41. return;
  42. }
  43. @Override
  44. public AcceptCriterion getAcceptCriterion() {
  45. return AcceptAll.get();
  46. }
  47. };
  48. }
  49. @Override
  50. public TargetDetails translateDropTargetDetails(
  51. Map<String, Object> clientVariables) {
  52. // If component has some special drop details that it needs to
  53. // translate for server side use, developer must return a
  54. // DragDropDetails here. If details does not exist or raw client
  55. // side data is ok, it is safe to return null here.
  56. return null;
  57. }
  58. }
  59. /**
  60. * Server side implementation of source does not necessary need to contain
  61. * anything.
  62. *
  63. * Check the @ClientWidget
  64. *
  65. * However component might have different modes to support starting drag
  66. * operations that are controlled via server side api.
  67. *
  68. */
  69. public class MyDragSource extends AbstractComponent {
  70. }
  71. }