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.

PopupViewConnector.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright 2011 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.ui.popupview;
  17. import com.vaadin.client.ApplicationConnection;
  18. import com.vaadin.client.ComponentConnector;
  19. import com.vaadin.client.Paintable;
  20. import com.vaadin.client.UIDL;
  21. import com.vaadin.client.VCaption;
  22. import com.vaadin.client.VCaptionWrapper;
  23. import com.vaadin.client.ui.AbstractComponentContainerConnector;
  24. import com.vaadin.client.ui.PostLayoutListener;
  25. import com.vaadin.shared.ui.Connect;
  26. import com.vaadin.ui.PopupView;
  27. @Connect(PopupView.class)
  28. public class PopupViewConnector extends AbstractComponentContainerConnector
  29. implements Paintable, PostLayoutListener {
  30. private boolean centerAfterLayout = false;
  31. @Override
  32. public boolean delegateCaptionHandling() {
  33. return false;
  34. }
  35. /**
  36. *
  37. *
  38. * @see com.vaadin.client.ComponentConnector#updateFromUIDL(com.vaadin.client.UIDL,
  39. * com.vaadin.client.ApplicationConnection)
  40. */
  41. @Override
  42. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  43. if (!isRealUpdate(uidl)) {
  44. return;
  45. }
  46. // These are for future server connections
  47. getWidget().client = client;
  48. getWidget().uidlId = uidl.getId();
  49. getWidget().hostPopupVisible = uidl
  50. .getBooleanVariable("popupVisibility");
  51. getWidget().setHTML(uidl.getStringAttribute("html"));
  52. if (uidl.hasAttribute("hideOnMouseOut")) {
  53. getWidget().popup.setHideOnMouseOut(uidl
  54. .getBooleanAttribute("hideOnMouseOut"));
  55. }
  56. // Render the popup if visible and show it.
  57. if (getWidget().hostPopupVisible) {
  58. UIDL popupUIDL = uidl.getChildUIDL(0);
  59. // showPopupOnTop(popup, hostReference);
  60. getWidget().preparePopup(getWidget().popup);
  61. getWidget().popup.updateFromUIDL(popupUIDL, client);
  62. if (getState().hasStyles()) {
  63. final StringBuffer styleBuf = new StringBuffer();
  64. final String primaryName = getWidget().popup
  65. .getStylePrimaryName();
  66. styleBuf.append(primaryName);
  67. for (String style : getState().getStyles()) {
  68. styleBuf.append(" ");
  69. styleBuf.append(primaryName);
  70. styleBuf.append("-");
  71. styleBuf.append(style);
  72. }
  73. getWidget().popup.setStyleName(styleBuf.toString());
  74. } else {
  75. getWidget().popup.setStyleName(getWidget().popup
  76. .getStylePrimaryName());
  77. }
  78. getWidget().showPopup(getWidget().popup);
  79. centerAfterLayout = true;
  80. // The popup shouldn't be visible, try to hide it.
  81. } else {
  82. getWidget().popup.hide();
  83. }
  84. }// updateFromUIDL
  85. @Override
  86. public void updateCaption(ComponentConnector component) {
  87. if (VCaption.isNeeded(component.getState())) {
  88. if (getWidget().popup.captionWrapper != null) {
  89. getWidget().popup.captionWrapper.updateCaption();
  90. } else {
  91. getWidget().popup.captionWrapper = new VCaptionWrapper(
  92. component, getConnection());
  93. getWidget().popup.setWidget(getWidget().popup.captionWrapper);
  94. getWidget().popup.captionWrapper.updateCaption();
  95. }
  96. } else {
  97. if (getWidget().popup.captionWrapper != null) {
  98. getWidget().popup
  99. .setWidget(getWidget().popup.popupComponentWidget);
  100. }
  101. }
  102. }
  103. @Override
  104. public VPopupView getWidget() {
  105. return (VPopupView) super.getWidget();
  106. }
  107. @Override
  108. public void postLayout() {
  109. if (centerAfterLayout) {
  110. centerAfterLayout = false;
  111. getWidget().center();
  112. }
  113. }
  114. }