Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CustomDDImplementation.java 2.6KB

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