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.

DefaultReconnectDialog.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2000-2021 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.communication;
  17. import com.google.gwt.core.client.Scheduler;
  18. import com.google.gwt.core.shared.GWT;
  19. import com.google.gwt.dom.client.BodyElement;
  20. import com.google.gwt.dom.client.Document;
  21. import com.google.gwt.dom.client.Style.Visibility;
  22. import com.google.gwt.event.dom.client.ClickEvent;
  23. import com.google.gwt.event.shared.HandlerRegistration;
  24. import com.google.gwt.user.client.ui.FlowPanel;
  25. import com.google.gwt.user.client.ui.HTML;
  26. import com.google.gwt.user.client.ui.Label;
  27. import com.vaadin.client.ApplicationConnection;
  28. import com.vaadin.client.WidgetUtil;
  29. import com.vaadin.client.ui.VOverlay;
  30. /**
  31. * The default implementation of the reconnect dialog.
  32. *
  33. * @since 7.6
  34. * @author Vaadin Ltd
  35. */
  36. public class DefaultReconnectDialog extends VOverlay
  37. implements ReconnectDialog {
  38. private static final String STYLE_RECONNECTING = "active";
  39. private static final String STYLE_BODY_RECONNECTING = "v-reconnecting";
  40. public Label label;
  41. private HandlerRegistration clickHandler = null;
  42. public DefaultReconnectDialog() {
  43. super(false, true);
  44. addStyleName("v-reconnect-dialog");
  45. FlowPanel root = new FlowPanel("div");
  46. HTML spinner = new HTML();
  47. spinner.addStyleName("spinner");
  48. label = GWT.create(Label.class);
  49. label.addStyleName("text");
  50. root.add(spinner);
  51. root.add(label);
  52. setWidget(root);
  53. }
  54. @Override
  55. public void setText(String text) {
  56. label.setText(text);
  57. }
  58. @Override
  59. public void setReconnecting(boolean reconnecting) {
  60. setStyleName(STYLE_RECONNECTING, reconnecting);
  61. BodyElement body = Document.get().getBody();
  62. if (reconnecting) {
  63. body.addClassName(STYLE_BODY_RECONNECTING);
  64. } else {
  65. body.removeClassName(STYLE_BODY_RECONNECTING);
  66. }
  67. // Click to refresh after giving up
  68. if (!reconnecting) {
  69. clickHandler = addDomHandler(event -> {
  70. // refresh
  71. WidgetUtil.redirect(null);
  72. }, ClickEvent.getType());
  73. } else {
  74. if (clickHandler != null) {
  75. clickHandler.removeHandler();
  76. }
  77. }
  78. }
  79. @Override
  80. public void show(ApplicationConnection connection) {
  81. ac = connection;
  82. show();
  83. }
  84. @Override
  85. public void setPopupPosition(int left, int top) {
  86. // Don't set inline styles for position, handle it in the theme
  87. }
  88. @Override
  89. public void preload(ApplicationConnection connection) {
  90. setModal(false); // Don't interfere with application use
  91. show(connection);
  92. getElement().getStyle().setVisibility(Visibility.HIDDEN);
  93. setStyleName(STYLE_RECONNECTING, true);
  94. Scheduler.get().scheduleDeferred(() -> {
  95. getElement().getStyle().setVisibility(Visibility.VISIBLE);
  96. setStyleName(STYLE_RECONNECTING, false);
  97. hide();
  98. });
  99. }
  100. }