From: Artur Signell Date: Tue, 31 Jan 2012 11:59:15 +0000 (+0200) Subject: #8324 Split PopupView into widget and paintable X-Git-Tag: 7.0.0.alpha2~493 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=94d517de86a63fe0284223671e0ef1fe526977c5;p=vaadin-framework.git #8324 Split PopupView into widget and paintable --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java index e667489dda..34bf0ca619 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java @@ -29,7 +29,6 @@ import com.vaadin.terminal.gwt.client.RenderInformation.Size; import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VCaption; import com.vaadin.terminal.gwt.client.VCaptionWrapper; import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.VTooltip; @@ -40,13 +39,13 @@ public class VPopupView extends HTML implements Container, Iterable { public static final String CLASSNAME = "v-popupview"; /** For server-client communication */ - private String uidlId; - private ApplicationConnection client; + String uidlId; + ApplicationConnection client; /** This variable helps to communicate popup visibility to the server */ - private boolean hostPopupVisible; + boolean hostPopupVisible; - private final CustomPopup popup; + final CustomPopup popup; private final Label loading = new Label(); /** @@ -81,61 +80,6 @@ public class VPopupView extends HTML implements Container, Iterable { sinkEvents(VTooltip.TOOLTIP_EVENTS); } - /** - * - * - * @see com.vaadin.terminal.gwt.client.VPaintableWidget#updateFromUIDL(com.vaadin.terminal.gwt.client.UIDL, - * com.vaadin.terminal.gwt.client.ApplicationConnection) - */ - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - // This call should be made first. Ensure correct implementation, - // and don't let the containing layout manage caption. - if (client.updateComponent(this, uidl, false)) { - return; - } - // These are for future server connections - this.client = client; - uidlId = uidl.getId(); - - hostPopupVisible = uidl.getBooleanVariable("popupVisibility"); - - setHTML(uidl.getStringAttribute("html")); - - if (uidl.hasAttribute("hideOnMouseOut")) { - popup.setHideOnMouseOut(uidl.getBooleanAttribute("hideOnMouseOut")); - } - - // Render the popup if visible and show it. - if (hostPopupVisible) { - UIDL popupUIDL = uidl.getChildUIDL(0); - - // showPopupOnTop(popup, hostReference); - preparePopup(popup); - popup.updateFromUIDL(popupUIDL, client); - if (uidl.hasAttribute("style")) { - final String[] styles = uidl.getStringAttribute("style").split( - " "); - final StringBuffer styleBuf = new StringBuffer(); - final String primaryName = popup.getStylePrimaryName(); - styleBuf.append(primaryName); - for (int i = 0; i < styles.length; i++) { - styleBuf.append(" "); - styleBuf.append(primaryName); - styleBuf.append("-"); - styleBuf.append(styles[i]); - } - popup.setStyleName(styleBuf.toString()); - } else { - popup.setStyleName(popup.getStylePrimaryName()); - } - showPopup(popup); - - // The popup shouldn't be visible, try to hide it. - } else { - popup.hide(); - } - }// updateFromUIDL - /** * Update popup visibility to server * @@ -149,7 +93,7 @@ public class VPopupView extends HTML implements Container, Iterable { } } - private void preparePopup(final CustomPopup popup) { + void preparePopup(final CustomPopup popup) { popup.setVisible(false); popup.show(); } @@ -231,8 +175,8 @@ public class VPopupView extends HTML implements Container, Iterable { protected class CustomPopup extends VOverlay { private VPaintableWidget popupComponentPaintable = null; - private Widget popupComponentWidget = null; - private VCaptionWrapper captionWrapper = null; + Widget popupComponentWidget = null; + VCaptionWrapper captionWrapper = null; private boolean hasHadMouseOver = false; private boolean hideOnMouseOut = true; @@ -446,27 +390,11 @@ public class VPopupView extends HTML implements Container, Iterable { return true; } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - if (VCaption.isNeeded(uidl)) { - if (popup.captionWrapper != null) { - popup.captionWrapper.updateCaption(uidl); - } else { - popup.captionWrapper = new VCaptionWrapper(component, client); - popup.setWidget(popup.captionWrapper); - popup.captionWrapper.updateCaption(uidl); - } - } else { - if (popup.captionWrapper != null) { - popup.setWidget(popup.popupComponentWidget); - } - } - } - @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (client != null) { - client.handleTooltipEvent(event, this); + client.handleWidgetTooltipEvent(event, this); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java new file mode 100644 index 0000000000..627f925d77 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java @@ -0,0 +1,104 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.VCaption; +import com.vaadin.terminal.gwt.client.VCaptionWrapper; +import com.vaadin.terminal.gwt.client.VPaintableWidget; + +public class VPopupViewPaintable extends VAbstractPaintableWidgetContainer { + + /** + * + * + * @see com.vaadin.terminal.gwt.client.VPaintableWidget#updateFromUIDL(com.vaadin.terminal.gwt.client.UIDL, + * com.vaadin.terminal.gwt.client.ApplicationConnection) + */ + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + // This call should be made first. Ensure correct implementation, + // and don't let the containing layout manage caption. + if (client.updateComponent(this, uidl, false)) { + return; + } + // These are for future server connections + getWidgetForPaintable().client = client; + getWidgetForPaintable().uidlId = uidl.getId(); + + getWidgetForPaintable().hostPopupVisible = uidl + .getBooleanVariable("popupVisibility"); + + getWidgetForPaintable().setHTML(uidl.getStringAttribute("html")); + + if (uidl.hasAttribute("hideOnMouseOut")) { + getWidgetForPaintable().popup.setHideOnMouseOut(uidl + .getBooleanAttribute("hideOnMouseOut")); + } + + // Render the popup if visible and show it. + if (getWidgetForPaintable().hostPopupVisible) { + UIDL popupUIDL = uidl.getChildUIDL(0); + + // showPopupOnTop(popup, hostReference); + getWidgetForPaintable().preparePopup(getWidgetForPaintable().popup); + getWidgetForPaintable().popup.updateFromUIDL(popupUIDL, client); + if (uidl.hasAttribute("style")) { + final String[] styles = uidl.getStringAttribute("style").split( + " "); + final StringBuffer styleBuf = new StringBuffer(); + final String primaryName = getWidgetForPaintable().popup + .getStylePrimaryName(); + styleBuf.append(primaryName); + for (int i = 0; i < styles.length; i++) { + styleBuf.append(" "); + styleBuf.append(primaryName); + styleBuf.append("-"); + styleBuf.append(styles[i]); + } + getWidgetForPaintable().popup.setStyleName(styleBuf.toString()); + } else { + getWidgetForPaintable().popup + .setStyleName(getWidgetForPaintable().popup + .getStylePrimaryName()); + } + getWidgetForPaintable().showPopup(getWidgetForPaintable().popup); + + // The popup shouldn't be visible, try to hide it. + } else { + getWidgetForPaintable().popup.hide(); + } + }// updateFromUIDL + + public void updateCaption(VPaintableWidget component, UIDL uidl) { + if (VCaption.isNeeded(uidl)) { + if (getWidgetForPaintable().popup.captionWrapper != null) { + getWidgetForPaintable().popup.captionWrapper + .updateCaption(uidl); + } else { + getWidgetForPaintable().popup.captionWrapper = new VCaptionWrapper( + component, getConnection()); + getWidgetForPaintable().popup + .setWidget(getWidgetForPaintable().popup.captionWrapper); + getWidgetForPaintable().popup.captionWrapper + .updateCaption(uidl); + } + } else { + if (getWidgetForPaintable().popup.captionWrapper != null) { + getWidgetForPaintable().popup + .setWidget(getWidgetForPaintable().popup.popupComponentWidget); + } + } + } + + @Override + public VPopupView getWidgetForPaintable() { + return (VPopupView) super.getWidgetForPaintable(); + } + + @Override + protected Widget createWidget() { + return GWT.create(VPopupView.class); + } + +} diff --git a/src/com/vaadin/ui/PopupView.java b/src/com/vaadin/ui/PopupView.java index fcad727510..5637ef69d7 100644 --- a/src/com/vaadin/ui/PopupView.java +++ b/src/com/vaadin/ui/PopupView.java @@ -10,7 +10,7 @@ import java.util.Map; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VPopupView; +import com.vaadin.terminal.gwt.client.ui.VPopupViewPaintable; /** * @@ -22,7 +22,7 @@ import com.vaadin.terminal.gwt.client.ui.VPopupView; * @author Vaadin Ltd. */ @SuppressWarnings("serial") -@ClientWidget(VPopupView.class) +@ClientWidget(VPopupViewPaintable.class) public class PopupView extends AbstractComponentContainer { private Content content;