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.

TreeGridDropTargetConnector.java 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.client.connectors.grid;
  17. import java.util.List;
  18. import java.util.Map;
  19. import com.google.gwt.dom.client.Element;
  20. import com.google.gwt.dom.client.NativeEvent;
  21. import com.google.gwt.dom.client.TableRowElement;
  22. import com.vaadin.client.MouseEventDetailsBuilder;
  23. import com.vaadin.shared.MouseEventDetails;
  24. import com.vaadin.shared.data.HierarchicalDataCommunicatorConstants;
  25. import com.vaadin.shared.ui.Connect;
  26. import com.vaadin.shared.ui.grid.DropLocation;
  27. import com.vaadin.shared.ui.grid.GridState;
  28. import com.vaadin.shared.ui.treegrid.TreeGridDropTargetRpc;
  29. import com.vaadin.shared.ui.treegrid.TreeGridDropTargetState;
  30. import com.vaadin.ui.components.grid.TreeGridDropTarget;
  31. import elemental.json.JsonObject;
  32. /**
  33. * Makes TreeGrid an HTML5 drop target. This is the client side counterpart of
  34. * {@link TreeGridDropTarget}.
  35. *
  36. * @author Vaadin Ltd
  37. * @since 8.1
  38. */
  39. @Connect(TreeGridDropTarget.class)
  40. public class TreeGridDropTargetConnector extends GridDropTargetConnector {
  41. @Override
  42. protected void sendDropEventToServer(List<String> types,
  43. Map<String, String> data, String dropEffect,
  44. NativeEvent dropEvent) {
  45. String rowKey = null;
  46. DropLocation dropLocation = null;
  47. Integer rowDepth = null;
  48. Boolean rowCollapsed = null;
  49. Element targetElement = getTargetElement(
  50. (Element) dropEvent.getEventTarget().cast());
  51. // the target element is either the tablewrapper or one of the body rows
  52. if (TableRowElement.is(targetElement)) {
  53. JsonObject rowData = getRowData(targetElement.cast());
  54. rowKey = rowData.getString(GridState.JSONKEY_ROWKEY);
  55. dropLocation = getDropLocation(targetElement, dropEvent);
  56. // Collect hierarchy information
  57. JsonObject hierarchyDescription = rowData.getObject(
  58. HierarchicalDataCommunicatorConstants.ROW_HIERARCHY_DESCRIPTION);
  59. rowDepth = (int) hierarchyDescription
  60. .getNumber(HierarchicalDataCommunicatorConstants.ROW_DEPTH);
  61. rowCollapsed = hierarchyDescription.getBoolean(
  62. HierarchicalDataCommunicatorConstants.ROW_COLLAPSED);
  63. } else {
  64. dropLocation = DropLocation.EMPTY;
  65. }
  66. MouseEventDetails mouseEventDetails = MouseEventDetailsBuilder
  67. .buildMouseEventDetails(dropEvent, targetElement);
  68. getRpcProxy(TreeGridDropTargetRpc.class).drop(types, data, dropEffect,
  69. rowKey, rowDepth, rowCollapsed, dropLocation,
  70. mouseEventDetails);
  71. }
  72. @Override
  73. public TreeGridDropTargetState getState() {
  74. return (TreeGridDropTargetState) super.getState();
  75. }
  76. }