Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SourceIs.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. /**
  5. *
  6. */
  7. package com.vaadin.event.dd.acceptcriteria;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10. import com.vaadin.event.TransferableImpl;
  11. import com.vaadin.event.dd.DragAndDropEvent;
  12. import com.vaadin.terminal.PaintException;
  13. import com.vaadin.terminal.PaintTarget;
  14. import com.vaadin.ui.Component;
  15. /**
  16. * Client side criteria that checks if the drag source is one of the given
  17. * components.
  18. *
  19. * @since 6.3
  20. */
  21. @SuppressWarnings("serial")
  22. public class SourceIs extends ClientSideCriterion {
  23. private Component[] components;
  24. public SourceIs(Component... component) {
  25. components = component;
  26. }
  27. @Override
  28. public void paintContent(PaintTarget target) throws PaintException {
  29. super.paintContent(target);
  30. int paintedComponents = 0;
  31. for (int i = 0; i < components.length; i++) {
  32. Component c = components[i];
  33. if (c.getApplication() != null) {
  34. target.addAttribute("component" + paintedComponents++, c);
  35. } else {
  36. Logger.getLogger(SourceIs.class.getName())
  37. .log(Level.WARNING,
  38. "SourceIs component {0} at index {1} is not attached to the component hierachy and will thus be ignored",
  39. new Object[] { c.getClass().getName(),
  40. Integer.valueOf(i) });
  41. }
  42. }
  43. target.addAttribute("c", paintedComponents);
  44. }
  45. @Override
  46. public boolean accept(DragAndDropEvent dragEvent) {
  47. if (dragEvent.getTransferable() instanceof TransferableImpl) {
  48. Component sourceComponent = ((TransferableImpl) dragEvent
  49. .getTransferable()).getSourceComponent();
  50. for (Component c : components) {
  51. if (c == sourceComponent) {
  52. return true;
  53. }
  54. }
  55. }
  56. return false;
  57. }
  58. }