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.

VTargetNodeIsChildOf.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. *
  3. */
  4. package com.vaadin.terminal.gwt.client.ui.dd;
  5. import com.google.gwt.user.client.ui.Widget;
  6. import com.vaadin.terminal.gwt.client.UIDL;
  7. import com.vaadin.terminal.gwt.client.ui.VTree;
  8. import com.vaadin.terminal.gwt.client.ui.VTree.TreeNode;
  9. final public class VTargetNodeIsChildOf extends VAcceptCriterion {
  10. @Override
  11. public boolean validates(VDragEvent drag, UIDL configuration) {
  12. VTree tree = (VTree) VDragAndDropManager.get().getCurrentDropHandler()
  13. .getPaintable();
  14. TreeNode treeNode = tree.getNodeByKey((String) drag.getDropDetails()
  15. .get("itemIdOver"));
  16. if (treeNode != null) {
  17. Widget parent2 = treeNode.getParent().getParent();
  18. int depth = configuration.getIntAttribute("depth");
  19. if (depth < 0) {
  20. depth = Integer.MAX_VALUE;
  21. }
  22. for (int i = 0; i < depth && parent2 instanceof TreeNode; i++) {
  23. if (configuration.getStringAttribute("key").equals(
  24. ((TreeNode) parent2).key)) {
  25. return true;
  26. }
  27. parent2 = parent2.getParent().getParent();
  28. }
  29. }
  30. return false;
  31. }
  32. }