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.

AcceptCriterion.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2000-2016 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.event.dd.acceptcriteria;
  17. import java.io.Serializable;
  18. import com.vaadin.event.Transferable;
  19. import com.vaadin.event.dd.DragAndDropEvent;
  20. import com.vaadin.event.dd.DropHandler;
  21. import com.vaadin.server.PaintException;
  22. import com.vaadin.server.PaintTarget;
  23. /**
  24. * Criterion that can be used create policy to accept/discard dragged content
  25. * (presented by {@link Transferable}).
  26. *
  27. * The drag and drop mechanism will verify the criteria returned by
  28. * {@link DropHandler#getAcceptCriterion()} before calling
  29. * {@link DropHandler#drop(DragAndDropEvent)}.
  30. *
  31. * The criteria can be evaluated either on the client (browser - see
  32. * {@link ClientSideCriterion}) or on the server (see
  33. * {@link ServerSideCriterion}). If no constraints are needed, an
  34. * {@link AcceptAll} can be used.
  35. *
  36. * In addition to accepting or rejecting a possible drop, criteria can provide
  37. * additional hints for client side painting.
  38. *
  39. * @see DropHandler
  40. * @see ClientSideCriterion
  41. * @see ServerSideCriterion
  42. *
  43. * @since 6.3
  44. */
  45. public interface AcceptCriterion extends Serializable {
  46. /**
  47. * Returns whether the criteria can be checked on the client or whether a
  48. * server request is needed to check the criteria.
  49. *
  50. * This requirement may depend on the state of the criterion (e.g. logical
  51. * operations between criteria), so this cannot be based on a marker
  52. * interface.
  53. */
  54. public boolean isClientSideVerifiable();
  55. public void paint(PaintTarget target) throws PaintException;
  56. /**
  57. * This needs to be implemented if and only if a criterion does some lazy server side
  58. * initialization. The UIDL painted in this method will be passed to client
  59. * side drop handler implementation. Implementation can assume that
  60. * {@link #accept(DragAndDropEvent)} is called before this method.
  61. *
  62. * @param target
  63. * @throws PaintException
  64. */
  65. public void paintResponse(PaintTarget target) throws PaintException;
  66. /**
  67. * Validates the data in event to be appropriate for the
  68. * {@link DropHandler#drop(DragAndDropEvent)} method.
  69. * <p>
  70. * Note that even if your criterion is validated on client side, you should
  71. * always validate the data on server side too.
  72. *
  73. * @param dragEvent
  74. * @return
  75. */
  76. public boolean accept(DragAndDropEvent dragEvent);
  77. }