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.

TreeGridClickEvent.java 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.widget.treegrid.events;
  17. import com.google.gwt.dom.client.BrowserEvents;
  18. import com.google.gwt.dom.client.Element;
  19. import com.google.gwt.dom.client.EventTarget;
  20. import com.vaadin.client.WidgetUtil;
  21. import com.vaadin.client.renderers.HierarchyRenderer;
  22. import com.vaadin.client.widget.escalator.RowContainer;
  23. import com.vaadin.client.widget.grid.events.AbstractGridMouseEventHandler;
  24. import com.vaadin.client.widget.grid.events.AbstractGridMouseEventHandler.GridClickHandler;
  25. import com.vaadin.client.widget.grid.events.GridClickEvent;
  26. import com.vaadin.client.widget.treegrid.TreeGrid;
  27. import com.vaadin.shared.ui.grid.GridConstants;
  28. /**
  29. * Class to set as value of {@link com.vaadin.client.widgets.Grid#clickEvent}.
  30. * <br/>
  31. * Differs from {@link GridClickEvent} only in allowing events to originate form
  32. * hierarchy widget.
  33. *
  34. * @since 8.1
  35. * @author Vaadin Ltd
  36. */
  37. public class TreeGridClickEvent extends GridClickEvent {
  38. public static final Type<GridClickHandler> TYPE = new Type<GridClickHandler>(
  39. BrowserEvents.CLICK, new TreeGridClickEvent());
  40. @Override
  41. public Type<GridClickHandler> getAssociatedType() {
  42. return TYPE;
  43. }
  44. @Override
  45. public TreeGrid getGrid() {
  46. EventTarget target = getNativeEvent().getEventTarget();
  47. if (!Element.is(target)) {
  48. return null;
  49. }
  50. return WidgetUtil.findWidget(Element.as(target), TreeGrid.class);
  51. }
  52. @Override
  53. protected void dispatch(
  54. AbstractGridMouseEventHandler.GridClickHandler handler) {
  55. EventTarget target = getNativeEvent().getEventTarget();
  56. if (!Element.is(target)) {
  57. // Target is not an element
  58. return;
  59. }
  60. // Ignore event if originated from child widget
  61. // except when from hierarchy widget
  62. Element targetElement = Element.as(target);
  63. if (getGrid().isElementInChildWidget(targetElement)
  64. && !HierarchyRenderer
  65. .isElementInHierarchyWidget(targetElement)) {
  66. return;
  67. }
  68. final RowContainer container = getGrid().getEscalator()
  69. .findRowContainer(targetElement);
  70. if (container == null) {
  71. // No container for given element
  72. return;
  73. }
  74. GridConstants.Section section = GridConstants.Section.FOOTER;
  75. if (container == getGrid().getEscalator().getHeader()) {
  76. section = GridConstants.Section.HEADER;
  77. } else if (container == getGrid().getEscalator().getBody()) {
  78. section = GridConstants.Section.BODY;
  79. }
  80. doDispatch(handler, section);
  81. }
  82. }