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.8KB

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