選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DefaultReconnectDialog.java 3.7KB

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