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.

VTargetInSubtree.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.v7.client.ui.tree;
  17. import com.google.gwt.user.client.ui.Widget;
  18. import com.vaadin.client.UIDL;
  19. import com.vaadin.client.ui.dd.VAcceptCriterion;
  20. import com.vaadin.client.ui.dd.VDragAndDropManager;
  21. import com.vaadin.client.ui.dd.VDragEvent;
  22. import com.vaadin.shared.ui.dd.AcceptCriterion;
  23. import com.vaadin.v7.client.ui.VTree;
  24. import com.vaadin.v7.client.ui.VTree.TreeNode;
  25. import com.vaadin.v7.ui.Tree;
  26. @AcceptCriterion(Tree.TargetInSubtree.class)
  27. public final class VTargetInSubtree extends VAcceptCriterion {
  28. @Override
  29. protected boolean accept(VDragEvent drag, UIDL configuration) {
  30. VTree tree = (VTree) VDragAndDropManager.get().getCurrentDropHandler()
  31. .getConnector().getWidget();
  32. TreeNode treeNode = tree
  33. .getNodeByKey((String) drag.getDropDetails().get("itemIdOver"));
  34. if (treeNode != null) {
  35. Widget parent2 = treeNode;
  36. int depth = configuration.getIntAttribute("depth");
  37. if (depth < 0) {
  38. depth = Integer.MAX_VALUE;
  39. }
  40. final String searchedKey = configuration.getStringAttribute("key");
  41. for (int i = 0; i <= depth && parent2 instanceof TreeNode; i++) {
  42. if (searchedKey.equals(((TreeNode) parent2).key)) {
  43. return true;
  44. }
  45. // panel -> next level node
  46. parent2 = parent2.getParent().getParent();
  47. }
  48. }
  49. return false;
  50. }
  51. }