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-2014 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.Style.Visibility;
  21. import com.google.gwt.event.dom.client.ClickEvent;
  22. import com.google.gwt.event.dom.client.ClickHandler;
  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 implements ReconnectDialog {
  37. private static final String STYLE_RECONNECTING = "active";
  38. public Label label;
  39. private HandlerRegistration clickHandler = null;
  40. public DefaultReconnectDialog() {
  41. super(false, true);
  42. addStyleName("v-reconnect-dialog");
  43. FlowPanel root = new FlowPanel("div");
  44. HTML spinner = new HTML();
  45. spinner.addStyleName("spinner");
  46. label = GWT.create(Label.class);
  47. label.addStyleName("text");
  48. root.add(spinner);
  49. root.add(label);
  50. setWidget(root);
  51. }
  52. @Override
  53. public void setText(String text) {
  54. label.setText(text);
  55. }
  56. @Override
  57. public void setReconnecting(boolean reconnecting) {
  58. setStyleName(STYLE_RECONNECTING, reconnecting);
  59. // Click to refresh after giving up
  60. if (!reconnecting) {
  61. clickHandler = addDomHandler(new ClickHandler() {
  62. @Override
  63. public void onClick(ClickEvent event) {
  64. // refresh
  65. WidgetUtil.redirect(null);
  66. }
  67. }, ClickEvent.getType());
  68. } else {
  69. if (clickHandler != null) {
  70. clickHandler.removeHandler();
  71. }
  72. }
  73. }
  74. @Override
  75. public void show(ApplicationConnection connection) {
  76. ac = connection;
  77. show();
  78. }
  79. @Override
  80. public void setPopupPosition(int left, int top) {
  81. // Don't set inline styles for position, handle it in the theme
  82. }
  83. @Override
  84. public void preload(ApplicationConnection connection) {
  85. setModal(false); // Don't interfere with application use
  86. show(connection);
  87. getElement().getStyle().setVisibility(Visibility.HIDDEN);
  88. setStyleName(STYLE_RECONNECTING, true);
  89. Scheduler.get().scheduleDeferred(new ScheduledCommand() {
  90. @Override
  91. public void execute() {
  92. getElement().getStyle().setVisibility(Visibility.VISIBLE);
  93. setStyleName(STYLE_RECONNECTING, false);
  94. hide();
  95. }
  96. });
  97. }
  98. }