aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMikael Grankvist <mgrankvi@vaadin.com>2012-11-13 10:11:51 +0200
committerMikael Grankvist <mgrankvi@vaadin.com>2012-11-13 10:49:00 +0200
commit46c8f62546cf177a24258787c16cb9a9fc166463 (patch)
tree498c97a9255dc8a253fe6197d7732ea2540fef5c /client
parent47cb9d4ccbab3df2f36b5441f65fae357e0a7d8f (diff)
downloadvaadin-framework-46c8f62546cf177a24258787c16cb9a9fc166463.tar.gz
vaadin-framework-46c8f62546cf177a24258787c16cb9a9fc166463.zip
(#9924) Moved hierarchy code and fixed popup view to not be a LegacyComponent anymore.
Change-Id: I2d12b8876bee47030383cf4845efd49eaeee72ee
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java122
-rw-r--r--client/src/com/vaadin/client/ui/popupview/VPopupView.java42
-rw-r--r--client/src/com/vaadin/client/ui/popupview/VisibilityChangeEvent.java36
-rw-r--r--client/src/com/vaadin/client/ui/popupview/VisibilityChangeHandler.java8
4 files changed, 121 insertions, 87 deletions
diff --git a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java
index eba09b6a19..ca06b28bdd 100644
--- a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java
+++ b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java
@@ -15,86 +15,56 @@
*/
package com.vaadin.client.ui.popupview;
-import com.vaadin.client.ApplicationConnection;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gwt.event.shared.HandlerRegistration;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
-import com.vaadin.client.Paintable;
-import com.vaadin.client.UIDL;
import com.vaadin.client.VCaption;
import com.vaadin.client.VCaptionWrapper;
+import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentContainerConnector;
import com.vaadin.client.ui.PostLayoutListener;
import com.vaadin.shared.ui.ComponentStateUtil;
import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.popupview.PopupViewServerRpc;
+import com.vaadin.shared.ui.popupview.PopupViewState;
import com.vaadin.ui.PopupView;
@Connect(PopupView.class)
public class PopupViewConnector extends AbstractComponentContainerConnector
- implements Paintable, PostLayoutListener {
+ implements PostLayoutListener, VisibilityChangeHandler {
private boolean centerAfterLayout = false;
+ private final List<HandlerRegistration> handlerRegistration = new ArrayList<HandlerRegistration>();
+
+ @Override
+ protected void init() {
+ super.init();
+
+ handlerRegistration.add(getWidget().addVisibilityChangeHandler(
+ this));
+ }
+
@Override
public boolean delegateCaptionHandling() {
return false;
}
- /**
- *
- *
- * @see com.vaadin.client.ComponentConnector#updateFromUIDL(com.vaadin.client.UIDL,
- * com.vaadin.client.ApplicationConnection)
- */
@Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- if (!isRealUpdate(uidl)) {
- return;
- }
- // These are for future server connections
- getWidget().client = client;
- getWidget().uidlId = uidl.getId();
-
- getWidget().hostPopupVisible = uidl
- .getBooleanVariable("popupVisibility");
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
- getWidget().setHTML(uidl.getStringAttribute("html"));
-
- if (uidl.hasAttribute("hideOnMouseOut")) {
- getWidget().popup.setHideOnMouseOut(uidl
- .getBooleanAttribute("hideOnMouseOut"));
- }
-
- // Render the popup if visible and show it.
- if (getWidget().hostPopupVisible) {
- UIDL popupUIDL = uidl.getChildUIDL(0);
-
- // showPopupOnTop(popup, hostReference);
- getWidget().preparePopup(getWidget().popup);
- getWidget().popup.updateFromUIDL(popupUIDL, client);
- if (ComponentStateUtil.hasStyles(getState())) {
- final StringBuffer styleBuf = new StringBuffer();
- final String primaryName = getWidget().popup
- .getStylePrimaryName();
- styleBuf.append(primaryName);
- for (String style : getState().styles) {
- styleBuf.append(" ");
- styleBuf.append(primaryName);
- styleBuf.append("-");
- styleBuf.append(style);
- }
- getWidget().popup.setStyleName(styleBuf.toString());
- } else {
- getWidget().popup.setStyleName(getWidget().popup
- .getStylePrimaryName());
- }
- getWidget().showPopup(getWidget().popup);
- centerAfterLayout = true;
+ getWidget().setHTML(getState().html);
+ getWidget().popup.setHideOnMouseOut(getState().hideOnMouseOut);
+ }
- // The popup shouldn't be visible, try to hide it.
- } else {
- getWidget().popup.hide();
- }
- }// updateFromUIDL
+ @Override
+ public PopupViewState getState() {
+ return (PopupViewState) super.getState();
+ }
@Override
public void updateCaption(ComponentConnector component) {
@@ -131,7 +101,41 @@ public class PopupViewConnector extends AbstractComponentContainerConnector
@Override
public void onConnectorHierarchyChange(
ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {
- // TODO Move code from updateFromUIDL to this method
+ // Render the popup if visible and show it.
+ if (!getChildren().isEmpty()) {
+ getWidget().preparePopup(getWidget().popup);
+ getWidget().popup
+ .setPopupConnector((ComponentConnector) getChildren()
+ .get(0));
+ if (ComponentStateUtil.hasStyles(getState())) {
+ final StringBuffer styleBuf = new StringBuffer();
+ final String primaryName = getWidget().popup
+ .getStylePrimaryName();
+ styleBuf.append(primaryName);
+ for (String style : getState().styles) {
+ styleBuf.append(" ");
+ styleBuf.append(primaryName);
+ styleBuf.append("-");
+ styleBuf.append(style);
+ }
+ getWidget().popup.setStyleName(styleBuf.toString());
+ } else {
+ getWidget().popup.setStyleName(getWidget().popup
+ .getStylePrimaryName());
+ }
+ getWidget().showPopup(getWidget().popup);
+ centerAfterLayout = true;
+
+ // The popup shouldn't be visible, try to hide it.
+ } else {
+ getWidget().popup.hide();
+ }
+ }
+
+ @Override
+ public void onVisibilityChange(VisibilityChangeEvent event) {
+ getRpcProxy(PopupViewServerRpc.class).setPopupVisibility(
+ event.isVisible());
}
-}
+} \ No newline at end of file
diff --git a/client/src/com/vaadin/client/ui/popupview/VPopupView.java b/client/src/com/vaadin/client/ui/popupview/VPopupView.java
index 88ee3afada..e8bc19038d 100644
--- a/client/src/com/vaadin/client/ui/popupview/VPopupView.java
+++ b/client/src/com/vaadin/client/ui/popupview/VPopupView.java
@@ -26,6 +26,7 @@ import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
@@ -36,9 +37,7 @@ import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ComponentConnector;
-import com.vaadin.client.UIDL;
import com.vaadin.client.VCaptionWrapper;
import com.vaadin.client.VConsole;
import com.vaadin.client.ui.ShortcutActionHandler;
@@ -50,10 +49,6 @@ public class VPopupView extends HTML {
public static final String CLASSNAME = "v-popupview";
- /** For server-client communication */
- String uidlId;
- ApplicationConnection client;
-
/** This variable helps to communicate popup visibility to the server */
boolean hostPopupVisible;
@@ -78,7 +73,7 @@ public class VPopupView extends HTML {
addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
- updateState(true);
+ fireEvent(new VisibilityChangeEvent(true));
}
});
@@ -86,25 +81,13 @@ public class VPopupView extends HTML {
popup.addCloseHandler(new CloseHandler<PopupPanel>() {
@Override
public void onClose(CloseEvent<PopupPanel> event) {
- updateState(false);
+ fireEvent(new VisibilityChangeEvent(false));
}
});
popup.setAnimationEnabled(true);
}
- /**
- * Update popup visibility to server
- *
- * @param visibility
- */
- private void updateState(boolean visible) {
- // If we know the server connection
- // then update the current situation
- if (uidlId != null && client != null && isAttached()) {
- client.updateVariable(uidlId, "popupVisibility", visible, true);
- }
- }
void preparePopup(final CustomPopup popup) {
popup.setVisible(false);
@@ -191,7 +174,7 @@ public class VPopupView extends HTML {
*/
protected class CustomPopup extends VOverlay {
- private ComponentConnector popupComponentPaintable = null;
+ private ComponentConnector popupComponentConnector = null;
Widget popupComponentWidget = null;
VCaptionWrapper captionWrapper = null;
@@ -327,23 +310,20 @@ public class VPopupView extends HTML {
@Override
public boolean remove(Widget w) {
- popupComponentPaintable = null;
+ popupComponentConnector = null;
popupComponentWidget = null;
captionWrapper = null;
return super.remove(w);
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
- ComponentConnector newPopupComponent = client.getPaintable(uidl
- .getChildUIDL(0));
+ public void setPopupConnector(ComponentConnector newPopupComponent) {
- if (newPopupComponent != popupComponentPaintable) {
+ if (newPopupComponent != popupComponentConnector) {
Widget newWidget = newPopupComponent.getWidget();
setWidget(newWidget);
popupComponentWidget = newWidget;
- popupComponentPaintable = newPopupComponent;
+ popupComponentConnector = newPopupComponent;
}
}
@@ -384,4 +364,10 @@ public class VPopupView extends HTML {
}// class CustomPopup
+ public HandlerRegistration addVisibilityChangeHandler(
+ final VisibilityChangeHandler visibilityChangeHandler) {
+ return addHandler(visibilityChangeHandler,
+ VisibilityChangeEvent.getType());
+ }
+
}// class VPopupView
diff --git a/client/src/com/vaadin/client/ui/popupview/VisibilityChangeEvent.java b/client/src/com/vaadin/client/ui/popupview/VisibilityChangeEvent.java
new file mode 100644
index 0000000000..e2cec40a8f
--- /dev/null
+++ b/client/src/com/vaadin/client/ui/popupview/VisibilityChangeEvent.java
@@ -0,0 +1,36 @@
+package com.vaadin.client.ui.popupview;
+
+import com.google.gwt.event.shared.GwtEvent;
+
+public class VisibilityChangeEvent extends
+ GwtEvent<VisibilityChangeHandler> {
+
+ private static Type<VisibilityChangeHandler> TYPE;
+
+ private boolean visible;
+
+ public VisibilityChangeEvent(final boolean visible) {
+ this.visible = visible;
+ }
+
+ public boolean isVisible() {
+ return visible;
+ }
+
+ @Override
+ public Type<VisibilityChangeHandler> getAssociatedType() {
+ return getType();
+ }
+
+ public static Type<VisibilityChangeHandler> getType() {
+ if (TYPE == null) {
+ TYPE = new Type<VisibilityChangeHandler>();
+ }
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(final VisibilityChangeHandler handler) {
+ handler.onVisibilityChange(this);
+ }
+}
diff --git a/client/src/com/vaadin/client/ui/popupview/VisibilityChangeHandler.java b/client/src/com/vaadin/client/ui/popupview/VisibilityChangeHandler.java
new file mode 100644
index 0000000000..3f8d715264
--- /dev/null
+++ b/client/src/com/vaadin/client/ui/popupview/VisibilityChangeHandler.java
@@ -0,0 +1,8 @@
+package com.vaadin.client.ui.popupview;
+
+import com.google.gwt.event.shared.EventHandler;
+
+public interface VisibilityChangeHandler extends EventHandler {
+
+ void onVisibilityChange(VisibilityChangeEvent event);
+}