Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AbstractEventTriggerExtensionConnector.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2000-2018 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.extensions;
  17. import com.google.gwt.event.dom.client.ClickEvent;
  18. import com.google.gwt.user.client.ui.Widget;
  19. import com.google.web.bindery.event.shared.HandlerRegistration;
  20. import com.vaadin.client.ComponentConnector;
  21. import com.vaadin.client.ServerConnector;
  22. import com.vaadin.shared.extension.PartInformationState;
  23. /**
  24. * An abstract extension connector with trigger support. Implementor's
  25. * {@link #trigger} method call may be initiated by another {@code Component}
  26. * without server round-trip. The class is used to overcome browser security
  27. * limitations. For instance, window may not be open with the round-trip.
  28. *
  29. * @author Vaadin Ltd.
  30. * @since 8.4
  31. */
  32. public abstract class AbstractEventTriggerExtensionConnector
  33. extends AbstractExtensionConnector {
  34. private HandlerRegistration eventHandlerRegistration;
  35. /**
  36. * Called whenever a click occurs on the widget (if widget does not
  37. * implement {@link EventTrigger}) or when the {@link EventTrigger} fires.
  38. *
  39. */
  40. protected abstract void trigger();
  41. @Override
  42. public PartInformationState getState() {
  43. return (PartInformationState) super.getState();
  44. }
  45. @Override
  46. protected void extend(ServerConnector target) {
  47. Widget targetWidget = ((ComponentConnector) target).getWidget();
  48. if (targetWidget instanceof EventTrigger) {
  49. String partInformation = getState().partInformation;
  50. eventHandlerRegistration = ((EventTrigger) targetWidget)
  51. .addTrigger(this::trigger, partInformation);
  52. } else {
  53. eventHandlerRegistration = targetWidget
  54. .addDomHandler(e -> trigger(), ClickEvent.getType());
  55. }
  56. }
  57. @Override
  58. public void onUnregister() {
  59. super.onUnregister();
  60. if (eventHandlerRegistration != null) {
  61. eventHandlerRegistration.removeHandler();
  62. eventHandlerRegistration = null;
  63. }
  64. }
  65. }