From b938479c0690513538f52b3ac31523a3e439c4c0 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 11 Apr 2012 21:40:36 +0300 Subject: [PATCH] Made sub window work again --- .../gwt/client/ui/button/ButtonConnector.java | 25 +++++++-- .../gwt/client/ui/button/VButton.java | 20 ------- .../gwt/client/ui/window/WindowConnector.java | 54 +++++++++---------- 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/button/ButtonConnector.java b/src/com/vaadin/terminal/gwt/client/ui/button/ButtonConnector.java index 1a93859429..a04e2482e5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/button/ButtonConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/button/ButtonConnector.java @@ -7,12 +7,16 @@ package com.vaadin.terminal.gwt.client.ui.button; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.FocusEvent; import com.google.gwt.event.dom.client.FocusHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.EventHelper; +import com.vaadin.terminal.gwt.client.MouseEventDetails; +import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder; import com.vaadin.terminal.gwt.client.communication.FieldRpc.FocusAndBlurServerRpc; import com.vaadin.terminal.gwt.client.communication.RpcProxy; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; @@ -24,7 +28,7 @@ import com.vaadin.ui.Button; @Component(value = Button.class, loadStyle = LoadStyle.EAGER) public class ButtonConnector extends AbstractComponentConnector implements - BlurHandler, FocusHandler { + BlurHandler, FocusHandler, ClickHandler { private ButtonServerRpc rpc = RpcProxy.create(ButtonServerRpc.class, this); private FocusAndBlurServerRpc focusBlurProxy = RpcProxy.create( @@ -41,9 +45,8 @@ public class ButtonConnector extends AbstractComponentConnector implements @Override public void init() { super.init(); - getWidget().buttonRpcProxy = rpc; + getWidget().addClickHandler(this); getWidget().client = getConnection(); - getWidget().paintableId = getConnectorId(); } @Override @@ -56,8 +59,6 @@ public class ButtonConnector extends AbstractComponentConnector implements // Set text getWidget().setText(getState().getCaption()); - getWidget().disableOnClick = getState().isDisableOnClick(); - // handle error if (null != getState().getErrorMessage()) { if (getWidget().errorIndicatorElement == null) { @@ -116,4 +117,18 @@ public class ButtonConnector extends AbstractComponentConnector implements // there is a listener on server side focusBlurProxy.blur(); } + + public void onClick(ClickEvent event) { + if (getState().isDisableOnClick()) { + getWidget().setEnabled(false); + rpc.disableOnClick(); + } + + // Add mouse details + MouseEventDetails details = MouseEventDetailsBuilder + .buildMouseEventDetails(event.getNativeEvent(), getWidget() + .getElement()); + rpc.click(details); + + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/button/VButton.java b/src/com/vaadin/terminal/gwt/client/ui/button/VButton.java index f42e36839d..f7d73d3b5e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/button/VButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/button/VButton.java @@ -16,8 +16,6 @@ import com.google.gwt.user.client.ui.Accessibility; import com.google.gwt.user.client.ui.FocusWidget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Icon; @@ -32,8 +30,6 @@ public class VButton extends FocusWidget implements ClickHandler { protected int mousedownX = 0; protected int mousedownY = 0; - protected String paintableId; - protected ApplicationConnection client; protected final Element wrapper = DOM.createSpan(); @@ -55,8 +51,6 @@ public class VButton extends FocusWidget implements ClickHandler { private int tabIndex = 0; - protected boolean disableOnClick = false; - /* * BELOW PRIVATE MEMBERS COPY-PASTED FROM GWT CustomButton */ @@ -79,8 +73,6 @@ public class VButton extends FocusWidget implements ClickHandler { private boolean isHovering; protected int clickShortcut = 0; - // TODO Move this to VButtonPaintable - ButtonServerRpc buttonRpcProxy; public VButton() { super(DOM.createDiv()); @@ -289,21 +281,9 @@ public class VButton extends FocusWidget implements ClickHandler { * .dom.client.ClickEvent) */ public void onClick(ClickEvent event) { - if (paintableId == null || client == null) { - return; - } if (BrowserInfo.get().isSafari()) { VButton.this.setFocus(true); } - if (disableOnClick) { - setEnabled(false); - buttonRpcProxy.disableOnClick(); - } - - // Add mouse details - MouseEventDetails details = MouseEventDetailsBuilder - .buildMouseEventDetails(event.getNativeEvent(), getElement()); - buttonRpcProxy.click(details); clickPending = false; } diff --git a/src/com/vaadin/terminal/gwt/client/ui/window/WindowConnector.java b/src/com/vaadin/terminal/gwt/client/ui/window/WindowConnector.java index 733485381e..17f56e9159 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/window/WindowConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/window/WindowConnector.java @@ -16,6 +16,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ComponentConnector; +import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent; import com.vaadin.terminal.gwt.client.LayoutManager; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.Paintable; @@ -120,38 +121,17 @@ public class WindowConnector extends AbstractComponentContainerConnector getWidget().setPopupPosition(positionx, positiony); } - boolean showingUrl = false; int childIndex = 0; - UIDL childUidl = uidl.getChildUIDL(childIndex++); - - final ComponentConnector lo = client.getPaintable(childUidl); - if (getWidget().layout != null) { - if (getWidget().layout != lo) { - // remove old - getWidget().contentPanel.remove(getWidget().layout.getWidget()); - // add new - if (!showingUrl) { - getWidget().contentPanel.setWidget(lo.getWidget()); - } - getWidget().layout = lo; - } - } else if (!showingUrl) { - getWidget().contentPanel.setWidget(lo.getWidget()); - getWidget().layout = lo; - } // we may have actions - if (uidl.getChildCount() > 1) { - final int cnt = uidl.getChildCount(); - for (int i = 1; i < cnt; i++) { - childUidl = uidl.getChildUIDL(i); - if (childUidl.getTag().equals("actions")) { - if (getWidget().shortcutHandler == null) { - getWidget().shortcutHandler = new ShortcutActionHandler( - getConnectorId(), client); - } - getWidget().shortcutHandler.updateActionMap(childUidl); + for (int i = 0; i < uidl.getChildCount(); i++) { + UIDL childUidl = uidl.getChildUIDL(i); + if (childUidl.getTag().equals("actions")) { + if (getWidget().shortcutHandler == null) { + getWidget().shortcutHandler = new ShortcutActionHandler( + getConnectorId(), client); } + getWidget().shortcutHandler.updateActionMap(childUidl); } } @@ -179,7 +159,7 @@ public class WindowConnector extends AbstractComponentContainerConnector if (uidl.hasAttribute("bringToFront")) { /* - * Focus as a side-efect. Will be overridden by + * Focus as a side-effect. Will be overridden by * ApplicationConnection if another component was focused by the * server side. */ @@ -209,6 +189,22 @@ public class WindowConnector extends AbstractComponentContainerConnector return GWT.create(VWindow.class); } + @Override + public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) { + super.onConnectorHierarchyChange(event); + + // We always have 1 child, unless the child is hidden + Widget newChildWidget = null; + ComponentConnector newChild = null; + if (getChildren().size() == 1) { + newChild = getChildren().get(0); + newChildWidget = newChild.getWidget(); + } + + getWidget().layout = newChild; + getWidget().setWidget(newChildWidget); + } + public void layout() { LayoutManager lm = getLayoutManager(); VWindow window = getWidget(); -- 2.39.5