diff options
author | Thomas <thomas@vaadin.com> | 2013-11-05 15:21:06 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-11-06 11:12:06 +0000 |
commit | fefedeab68461ebc04fd45f91a35835fc9026a56 (patch) | |
tree | f4d3b8a2d60b7ed0f1c4e81499abba584cef3d94 /client | |
parent | e0e00befc848c242f986ba5cd993ae8610a7fa83 (diff) | |
download | vaadin-framework-fefedeab68461ebc04fd45f91a35835fc9026a56.tar.gz vaadin-framework-fefedeab68461ebc04fd45f91a35835fc9026a56.zip |
Send window position data back to server after drag (#12885)
Change-Id: I9ca766b0e06390c7ab90f9cbd4996b83032789db
Diffstat (limited to 'client')
4 files changed, 145 insertions, 1 deletions
diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index 9f19a3e0ab..62937b6a67 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -33,6 +33,7 @@ import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; import com.google.gwt.event.dom.client.ScrollEvent; import com.google.gwt.event.dom.client.ScrollHandler; +import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; @@ -47,6 +48,8 @@ import com.vaadin.client.LayoutManager; import com.vaadin.client.Util; import com.vaadin.client.debug.internal.VDebugWindow; import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; +import com.vaadin.client.ui.window.WindowMoveEvent; +import com.vaadin.client.ui.window.WindowMoveHandler; import com.vaadin.shared.EventId; import com.vaadin.shared.ui.window.WindowMode; @@ -921,6 +924,9 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, dragging = false; hideDraggingCurtain(); DOM.releaseCapture(getElement()); + + // fire move event + fireEvent(new WindowMoveEvent(uidlPositionX, uidlPositionY)); } @Override @@ -1036,4 +1042,14 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, - contentPanel.getElement().getOffsetWidth(); } + /** + * Adds a Handler for when user moves the window. + * + * @since 7.1.9 + * @return {@link HandlerRegistration} used to remove the handler + */ + public HandlerRegistration addMoveHandler(WindowMoveHandler handler) { + return addHandler(handler, WindowMoveEvent.getType()); + } + } diff --git a/client/src/com/vaadin/client/ui/window/WindowConnector.java b/client/src/com/vaadin/client/ui/window/WindowConnector.java index ff2e93a3b2..54ea384f5a 100644 --- a/client/src/com/vaadin/client/ui/window/WindowConnector.java +++ b/client/src/com/vaadin/client/ui/window/WindowConnector.java @@ -34,6 +34,7 @@ import com.vaadin.client.LayoutManager; import com.vaadin.client.Paintable; import com.vaadin.client.UIDL; import com.vaadin.client.Util; +import com.vaadin.client.communication.RpcProxy; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractSingleComponentContainerConnector; import com.vaadin.client.ui.ClickEventHandler; @@ -52,7 +53,8 @@ import com.vaadin.shared.ui.window.WindowState; @Connect(value = com.vaadin.ui.Window.class) public class WindowConnector extends AbstractSingleComponentContainerConnector implements Paintable, BeforeShortcutActionListener, - SimpleManagedLayout, PostLayoutListener, MayScrollChildren { + SimpleManagedLayout, PostLayoutListener, MayScrollChildren, + WindowMoveHandler { private ClickEventHandler clickEventHandler = new ClickEventHandler(this) { @Override @@ -112,6 +114,8 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector DoubleClickEvent.getType()); window.setOwner(getConnection().getUIConnector().getWidget()); + + window.addMoveHandler(this); } @Override @@ -400,4 +404,11 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector */ return true; } + + @Override + public void onWindowMove(WindowMoveEvent event) { + RpcProxy.create(WindowServerRpc.class, this).windowMoved( + event.getNewX(), event.getNewY()); + + } } diff --git a/client/src/com/vaadin/client/ui/window/WindowMoveEvent.java b/client/src/com/vaadin/client/ui/window/WindowMoveEvent.java new file mode 100644 index 0000000000..439a90e3a1 --- /dev/null +++ b/client/src/com/vaadin/client/ui/window/WindowMoveEvent.java @@ -0,0 +1,82 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.client.ui.window; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * Event for window position updates + * + * @since 7.1.9 + * @author Vaadin Ltd + */ +public class WindowMoveEvent extends GwtEvent<WindowMoveHandler> { + + private static final Type<WindowMoveHandler> TYPE = new Type<WindowMoveHandler>(); + + private final int newX; + private final int newY; + + /** + * Creates a new event with the given parameters + * + * @param x + * The new x-position for the VWindow + * @param y + * The new y-position for the VWindow + */ + public WindowMoveEvent(int x, int y) { + newX = x; + newY = y; + } + + /** + * Gets the new x position of the window + * + * @return the new X position of the VWindow + */ + public int getNewX() { + return newX; + } + + /** + * Gets the new y position of the window + * + * @return the new Y position of the VWindow + */ + public int getNewY() { + return newY; + } + + /** + * Gets the type of the event + * + * @return the type of the event + */ + public static Type<WindowMoveHandler> getType() { + return TYPE; + } + + @Override + public Type<WindowMoveHandler> getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(WindowMoveHandler handler) { + handler.onWindowMove(this); + } +} diff --git a/client/src/com/vaadin/client/ui/window/WindowMoveHandler.java b/client/src/com/vaadin/client/ui/window/WindowMoveHandler.java new file mode 100644 index 0000000000..e30e1853fe --- /dev/null +++ b/client/src/com/vaadin/client/ui/window/WindowMoveHandler.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.client.ui.window; + +import com.google.gwt.event.shared.EventHandler; + +/** + * Handler for {@link WindowMoveEvent}s + * + * @since 7.1.9 + * @author Vaadin Ltd + */ +public interface WindowMoveHandler extends EventHandler { + + /** + * Called when the VWindow was moved by the user. + * + * @param event + * Contains new coordinates for the VWindow + */ + public void onWindowMove(WindowMoveEvent event); +} |