@@ -7,9 +7,11 @@ import java.io.Serializable; | |||
import java.lang.reflect.Method; | |||
import com.vaadin.event.MouseEvents.ClickEvent; | |||
import com.vaadin.terminal.gwt.client.Connector; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.tools.ReflectTools; | |||
import com.vaadin.ui.Component; | |||
import com.vaadin.ui.ComponentContainer; | |||
public interface LayoutEvents { | |||
@@ -120,5 +122,17 @@ public interface LayoutEvents { | |||
return childComponent; | |||
} | |||
public static LayoutClickEvent createEvent(ComponentContainer layout, | |||
MouseEventDetails mouseDetails, Connector clickedConnector) { | |||
Component clickedComponent = (Component) clickedConnector; | |||
Component childComponent = clickedComponent; | |||
while (childComponent != null | |||
&& childComponent.getParent() != layout) { | |||
childComponent = childComponent.getParent(); | |||
} | |||
return new LayoutClickEvent(layout, mouseDetails, clickedComponent, | |||
childComponent); | |||
} | |||
} | |||
} |
@@ -6,5 +6,4 @@ package com.vaadin.terminal.gwt.client; | |||
public interface EventId { | |||
public static final String BLUR = "blur"; | |||
public static final String FOCUS = "focus"; | |||
public static final String LAYOUT_CLICK = "layout_click"; | |||
} |
@@ -9,23 +9,24 @@ import java.util.Iterator; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.dom.client.Style; | |||
import com.google.gwt.dom.client.Style.Unit; | |||
import com.google.gwt.event.dom.client.DomEvent.Type; | |||
import com.google.gwt.event.shared.EventHandler; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.google.gwt.user.client.Element; | |||
import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.terminal.gwt.client.ApplicationConnection; | |||
import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.DirectionalManagedLayout; | |||
import com.vaadin.terminal.gwt.client.EventId; | |||
import com.vaadin.terminal.gwt.client.UIDL; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout.AbsoluteWrapper; | |||
public class AbsoluteLayoutConnector extends | |||
AbstractComponentContainerConnector implements DirectionalManagedLayout { | |||
public interface AbsoluteLayoutServerRPC extends LayoutClickRPC, ServerRpc { | |||
} | |||
private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( | |||
this, EventId.LAYOUT_CLICK) { | |||
this) { | |||
@Override | |||
protected ComponentConnector getChildComponent(Element element) { | |||
@@ -33,12 +34,21 @@ public class AbsoluteLayoutConnector extends | |||
} | |||
@Override | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
H handler, Type<H> type) { | |||
return getWidget().addDomHandler(handler, type); | |||
} | |||
protected LayoutClickRPC getLayoutClickRPC() { | |||
return rpc; | |||
}; | |||
}; | |||
private AbsoluteLayoutServerRPC rpc = GWT | |||
.create(AbsoluteLayoutServerRPC.class); | |||
@Override | |||
protected void init() { | |||
super.init(); | |||
initRPC(rpc); | |||
} | |||
@Override | |||
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { | |||
getWidget().client = client; |
@@ -0,0 +1,161 @@ | |||
/* | |||
@VaadinApache2LicenseForJavaFiles@ | |||
*/ | |||
package com.vaadin.terminal.gwt.client.ui; | |||
import com.google.gwt.dom.client.NativeEvent; | |||
import com.google.gwt.event.dom.client.ContextMenuEvent; | |||
import com.google.gwt.event.dom.client.ContextMenuHandler; | |||
import com.google.gwt.event.dom.client.DomEvent; | |||
import com.google.gwt.event.dom.client.DoubleClickEvent; | |||
import com.google.gwt.event.dom.client.DoubleClickHandler; | |||
import com.google.gwt.event.dom.client.MouseUpEvent; | |||
import com.google.gwt.event.dom.client.MouseUpHandler; | |||
import com.google.gwt.event.shared.EventHandler; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.google.gwt.user.client.Element; | |||
import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
public abstract class AbstractClickEventHandler implements DoubleClickHandler, | |||
ContextMenuHandler, MouseUpHandler { | |||
private HandlerRegistration doubleClickHandlerRegistration; | |||
private HandlerRegistration mouseUpHandlerRegistration; | |||
private HandlerRegistration contextMenuHandlerRegistration; | |||
protected ComponentConnector connector; | |||
private String clickEventIdentifier; | |||
public AbstractClickEventHandler(ComponentConnector connector, | |||
String clickEventIdentifier) { | |||
this.connector = connector; | |||
this.clickEventIdentifier = clickEventIdentifier; | |||
} | |||
public void handleEventHandlerRegistration() { | |||
// Handle registering/unregistering of click handler depending on if | |||
// server side listeners have been added or removed. | |||
if (hasEventListener()) { | |||
if (mouseUpHandlerRegistration == null) { | |||
mouseUpHandlerRegistration = registerHandler(this, | |||
MouseUpEvent.getType()); | |||
contextMenuHandlerRegistration = registerHandler(this, | |||
ContextMenuEvent.getType()); | |||
doubleClickHandlerRegistration = registerHandler(this, | |||
DoubleClickEvent.getType()); | |||
} | |||
} else { | |||
if (mouseUpHandlerRegistration != null) { | |||
// Remove existing handlers | |||
doubleClickHandlerRegistration.removeHandler(); | |||
mouseUpHandlerRegistration.removeHandler(); | |||
contextMenuHandlerRegistration.removeHandler(); | |||
contextMenuHandlerRegistration = null; | |||
mouseUpHandlerRegistration = null; | |||
doubleClickHandlerRegistration = null; | |||
} | |||
} | |||
} | |||
/** | |||
* Registers the given handler to the widget so that the necessary events | |||
* are passed to this {@link ClickEventHandler}. | |||
* <p> | |||
* By default registers the handler with the connector root widget. | |||
* </p> | |||
* | |||
* @param <H> | |||
* @param handler | |||
* The handler to register | |||
* @param type | |||
* The type of the handler. | |||
* @return A reference for the registration of the handler. | |||
*/ | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
final H handler, DomEvent.Type<H> type) { | |||
return connector.getWidget().addDomHandler(handler, type); | |||
} | |||
/** | |||
* Checks if there is a server side event listener registered for clicks | |||
* | |||
* @return true if there is a server side event listener registered, false | |||
* otherwise | |||
*/ | |||
public boolean hasEventListener() { | |||
return connector.hasEventListener(clickEventIdentifier); | |||
} | |||
/** | |||
* Event handler for context menu. Prevents the browser context menu from | |||
* popping up if there is a listener for right clicks. | |||
*/ | |||
public void onContextMenu(ContextMenuEvent event) { | |||
if (hasEventListener() && shouldFireEvent(event)) { | |||
// Prevent showing the browser's context menu when there is a right | |||
// click listener. | |||
event.preventDefault(); | |||
} | |||
} | |||
/** | |||
* Event handler for mouse up. This is used to detect all single click | |||
* events. | |||
*/ | |||
public void onMouseUp(MouseUpEvent event) { | |||
// TODO For perfect accuracy we should check that a mousedown has | |||
// occured on this element before this mouseup and that no mouseup | |||
// has occured anywhere after that. | |||
if (hasEventListener() && shouldFireEvent(event)) { | |||
// "Click" with left, right or middle button | |||
fireClick(event.getNativeEvent()); | |||
} | |||
} | |||
/** | |||
* Sends the click event based on the given native event. | |||
* | |||
* @param event | |||
* The native event that caused this click event | |||
*/ | |||
protected abstract void fireClick(NativeEvent event); | |||
/** | |||
* Called before firing a click event. Allows sub classes to decide if this | |||
* in an event that should cause an event or not. | |||
* | |||
* @param event | |||
* The user event | |||
* @return true if the event should be fired, false otherwise | |||
*/ | |||
protected boolean shouldFireEvent(DomEvent<?> event) { | |||
return true; | |||
} | |||
/** | |||
* Event handler for double clicks. Used to fire double click events. Note | |||
* that browsers typically fail to prevent the second click event so a | |||
* double click will result in two click events and one double click event. | |||
*/ | |||
public void onDoubleClick(DoubleClickEvent event) { | |||
if (hasEventListener() && shouldFireEvent(event)) { | |||
fireClick(event.getNativeEvent()); | |||
} | |||
} | |||
/** | |||
* Click event calculates and returns coordinates relative to the element | |||
* returned by this method. Default implementation uses the root element of | |||
* the widget. Override to provide a different relative element. | |||
* | |||
* @return The Element used for calculating relative coordinates for a click | |||
* or null if no relative coordinates can be calculated. | |||
*/ | |||
protected Element getRelativeToElement() { | |||
return connector.getWidget().getElement(); | |||
} | |||
} |
@@ -15,6 +15,7 @@ import com.vaadin.terminal.gwt.client.ComponentContainerConnector; | |||
import com.vaadin.terminal.gwt.client.ComponentState; | |||
import com.vaadin.terminal.gwt.client.ConnectorMap; | |||
import com.vaadin.terminal.gwt.client.LayoutManager; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.TooltipInfo; | |||
import com.vaadin.terminal.gwt.client.UIDL; | |||
import com.vaadin.terminal.gwt.client.VConsole; | |||
@@ -25,6 +26,17 @@ import com.vaadin.terminal.gwt.client.communication.SharedState; | |||
public abstract class AbstractComponentConnector extends AbstractConnector | |||
implements ComponentConnector { | |||
public interface ClickRPC extends ServerRpc { | |||
/** | |||
* Called when a click event has occurred and there are server side | |||
* listeners for the event. | |||
* | |||
* @param mouseDetails | |||
* Details about the mouse when the event took place | |||
*/ | |||
public void click(MouseEventDetails mouseDetails); | |||
} | |||
private ComponentContainerConnector parent; | |||
private Widget widget; |
@@ -8,13 +8,30 @@ import java.util.List; | |||
import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.ComponentContainerConnector; | |||
import com.vaadin.terminal.gwt.client.Connector; | |||
import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangedEvent; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.Util; | |||
import com.vaadin.terminal.gwt.client.VConsole; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
public abstract class AbstractComponentContainerConnector extends | |||
AbstractComponentConnector implements ComponentContainerConnector { | |||
public interface LayoutClickRPC extends ServerRpc { | |||
/** | |||
* Called when a layout click event has occurred and there are server | |||
* side listeners for the event. | |||
* | |||
* @param mouseDetails | |||
* Details about the mouse when the event took place | |||
* @param clickedConnector | |||
* The child component that was the target of the event | |||
*/ | |||
public void layoutClick(MouseEventDetails mouseDetails, | |||
Connector clickedConnector); | |||
} | |||
List<ComponentConnector> children; | |||
/** |
@@ -5,29 +5,35 @@ package com.vaadin.terminal.gwt.client.ui; | |||
import java.util.List; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.dom.client.Style; | |||
import com.google.gwt.event.dom.client.DomEvent.Type; | |||
import com.google.gwt.event.shared.EventHandler; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.google.gwt.user.client.Element; | |||
import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.terminal.gwt.client.ApplicationConnection; | |||
import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.DirectionalManagedLayout; | |||
import com.vaadin.terminal.gwt.client.EventId; | |||
import com.vaadin.terminal.gwt.client.LayoutManager; | |||
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.ValueMap; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
import com.vaadin.terminal.gwt.client.ui.layout.ComponentConnectorLayoutSlot; | |||
import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot; | |||
public abstract class AbstractOrderedLayoutConnector extends | |||
AbstractComponentContainerConnector implements DirectionalManagedLayout { | |||
public interface AbstractOrderedLayoutServerRPC extends | |||
LayoutClickRPC, ServerRpc { | |||
} | |||
AbstractOrderedLayoutServerRPC rpc = GWT | |||
.create(AbstractOrderedLayoutServerRPC.class); | |||
private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( | |||
this, EventId.LAYOUT_CLICK) { | |||
this) { | |||
@Override | |||
protected ComponentConnector getChildComponent(Element element) { | |||
@@ -36,14 +42,15 @@ public abstract class AbstractOrderedLayoutConnector extends | |||
} | |||
@Override | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
H handler, Type<H> type) { | |||
return getWidget().addDomHandler(handler, type); | |||
} | |||
protected LayoutClickRPC getLayoutClickRPC() { | |||
return rpc; | |||
}; | |||
}; | |||
@Override | |||
public void init() { | |||
initRPC(rpc); | |||
getLayoutManager().registerDependency(this, | |||
getWidget().spacingMeasureElement); | |||
} |
@@ -7,6 +7,7 @@ import java.util.LinkedList; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.dom.client.NativeEvent; | |||
import com.google.gwt.event.dom.client.DomEvent; | |||
import com.google.gwt.event.dom.client.DomEvent.Type; | |||
import com.google.gwt.event.shared.EventHandler; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
@@ -17,11 +18,25 @@ import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.ComponentState; | |||
import com.vaadin.terminal.gwt.client.Connector; | |||
import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangedEvent; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; | |||
public abstract class AbstractSplitPanelConnector extends | |||
AbstractComponentContainerConnector implements SimpleManagedLayout { | |||
public interface AbstractSplitPanelRPC extends ServerRpc { | |||
/** | |||
* Called when a click event has occurred on the splitter. | |||
* | |||
* @param mouseDetails | |||
* Details about the mouse when the event took place | |||
*/ | |||
public void splitterClick(MouseEventDetails mouseDetails); | |||
} | |||
public static class SplitterState { | |||
private int position; | |||
private String positionUnit; | |||
@@ -101,11 +116,12 @@ public abstract class AbstractSplitPanelConnector extends | |||
} | |||
public static final String SPLITTER_CLICK_EVENT_IDENTIFIER = "sp_click"; | |||
private AbstractSplitPanelRPC rpc = GWT.create(AbstractSplitPanelRPC.class); | |||
@Override | |||
protected void init() { | |||
super.init(); | |||
initRPC(rpc); | |||
// TODO Remove | |||
getWidget().client = getConnection(); | |||
getWidget().id = getConnectorId(); | |||
@@ -115,8 +131,7 @@ public abstract class AbstractSplitPanelConnector extends | |||
// TODO Implement caption handling | |||
} | |||
ClickEventHandler clickEventHandler = new ClickEventHandler(this, | |||
SPLITTER_CLICK_EVENT_IDENTIFIER) { | |||
ClickEventHandler clickEventHandler = new ClickEventHandler(this) { | |||
@Override | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
@@ -132,25 +147,24 @@ public abstract class AbstractSplitPanelConnector extends | |||
} | |||
@Override | |||
public void onContextMenu( | |||
com.google.gwt.event.dom.client.ContextMenuEvent event) { | |||
protected boolean shouldFireEvent(DomEvent<?> event) { | |||
Element target = event.getNativeEvent().getEventTarget().cast(); | |||
if (getWidget().splitter.isOrHasChild(target)) { | |||
super.onContextMenu(event); | |||
if (!getWidget().splitter.isOrHasChild(target)) { | |||
return false; | |||
} | |||
return super.shouldFireEvent(event); | |||
}; | |||
@Override | |||
protected void fireClick(NativeEvent event) { | |||
Element target = event.getEventTarget().cast(); | |||
if (getWidget().splitter.isOrHasChild(target)) { | |||
super.fireClick(event); | |||
} | |||
} | |||
protected Element getRelativeToElement() { | |||
return getWidget().splitter; | |||
}; | |||
@Override | |||
protected Element getRelativeToElement() { | |||
return null; | |||
protected void fireClick(NativeEvent event, | |||
MouseEventDetails mouseDetails) { | |||
rpc.splitterClick(mouseDetails); | |||
} | |||
}; |
@@ -3,128 +3,48 @@ | |||
*/ | |||
package com.vaadin.terminal.gwt.client.ui; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import com.google.gwt.dom.client.NativeEvent; | |||
import com.google.gwt.event.dom.client.ContextMenuEvent; | |||
import com.google.gwt.event.dom.client.ContextMenuHandler; | |||
import com.google.gwt.event.dom.client.DomEvent; | |||
import com.google.gwt.event.dom.client.DoubleClickEvent; | |||
import com.google.gwt.event.dom.client.DoubleClickHandler; | |||
import com.google.gwt.event.dom.client.MouseUpEvent; | |||
import com.google.gwt.event.dom.client.MouseUpHandler; | |||
import com.google.gwt.event.shared.EventHandler; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.google.gwt.user.client.Element; | |||
import com.vaadin.terminal.gwt.client.ApplicationConnection; | |||
import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder; | |||
public abstract class ClickEventHandler implements DoubleClickHandler, | |||
ContextMenuHandler, MouseUpHandler { | |||
public abstract class ClickEventHandler extends AbstractClickEventHandler { | |||
private HandlerRegistration doubleClickHandlerRegistration; | |||
private HandlerRegistration mouseUpHandlerRegistration; | |||
private HandlerRegistration contextMenuHandlerRegistration; | |||
public static final String CLICK_EVENT_IDENTIFIER = "click"; | |||
protected String clickEventIdentifier; | |||
protected ComponentConnector connector; | |||
public ClickEventHandler(ComponentConnector connector) { | |||
this(connector, CLICK_EVENT_IDENTIFIER); | |||
} | |||
public ClickEventHandler(ComponentConnector connector, | |||
String clickEventIdentifier) { | |||
this.connector = connector; | |||
this.clickEventIdentifier = clickEventIdentifier; | |||
} | |||
public void handleEventHandlerRegistration() { | |||
// Handle registering/unregistering of click handler depending on if | |||
// server side listeners have been added or removed. | |||
if (hasEventListener()) { | |||
if (mouseUpHandlerRegistration == null) { | |||
mouseUpHandlerRegistration = registerHandler(this, | |||
MouseUpEvent.getType()); | |||
contextMenuHandlerRegistration = registerHandler(this, | |||
ContextMenuEvent.getType()); | |||
doubleClickHandlerRegistration = registerHandler(this, | |||
DoubleClickEvent.getType()); | |||
} | |||
} else { | |||
if (mouseUpHandlerRegistration != null) { | |||
// Remove existing handlers | |||
doubleClickHandlerRegistration.removeHandler(); | |||
mouseUpHandlerRegistration.removeHandler(); | |||
contextMenuHandlerRegistration.removeHandler(); | |||
contextMenuHandlerRegistration = null; | |||
mouseUpHandlerRegistration = null; | |||
doubleClickHandlerRegistration = null; | |||
} | |||
} | |||
} | |||
protected abstract <H extends EventHandler> HandlerRegistration registerHandler( | |||
final H handler, DomEvent.Type<H> type); | |||
protected ApplicationConnection getApplicationConnection() { | |||
return connector.getConnection(); | |||
} | |||
public boolean hasEventListener() { | |||
return connector.hasEventListener(clickEventIdentifier); | |||
super(connector, clickEventIdentifier); | |||
} | |||
/** | |||
* Sends the click event based on the given native event. Delegates actual | |||
* sending to {@link #fireClick(MouseEventDetails)}. | |||
* | |||
* @param event | |||
* The native event that caused this click event | |||
*/ | |||
protected void fireClick(NativeEvent event) { | |||
String pid = connector.getConnectorId(); | |||
MouseEventDetails mouseDetails = MouseEventDetailsBuilder | |||
.buildMouseEventDetails(event, getRelativeToElement()); | |||
Map<String, Object> parameters = new HashMap<String, Object>(); | |||
parameters.put("mouseDetails", mouseDetails.serialize()); | |||
connector.getConnection().updateVariable(pid, clickEventIdentifier, | |||
parameters, true); | |||
} | |||
public void onContextMenu(ContextMenuEvent event) { | |||
if (hasEventListener()) { | |||
// Prevent showing the browser's context menu when there is a right | |||
// click listener. | |||
event.preventDefault(); | |||
} | |||
} | |||
public void onMouseUp(MouseUpEvent event) { | |||
// TODO For perfect accuracy we should check that a mousedown has | |||
// occured on this element before this mouseup and that no mouseup | |||
// has occured anywhere after that. | |||
if (hasEventListener()) { | |||
// "Click" with left, right or middle button | |||
fireClick(event.getNativeEvent()); | |||
} | |||
} | |||
public void onDoubleClick(DoubleClickEvent event) { | |||
if (hasEventListener()) { | |||
fireClick(event.getNativeEvent()); | |||
} | |||
fireClick(event, mouseDetails); | |||
} | |||
/** | |||
* Click event calculates and returns coordinates relative to the element | |||
* returned by this method. Default implementation uses the root element of | |||
* the widget. Override to provide a different relative element. | |||
* Sends the click event to the server. Must be implemented by sub classes, | |||
* typically by calling an RPC method. | |||
* | |||
* @param event | |||
* The event that caused this click to be fired | |||
* | |||
* @return The Element used for calculating relative coordinates for a click | |||
* or null if no relative coordinates can be calculated. | |||
* @param mouseDetails | |||
* The mouse details for the event | |||
*/ | |||
protected Element getRelativeToElement() { | |||
return connector.getWidget().getElement(); | |||
} | |||
protected abstract void fireClick(NativeEvent event, | |||
MouseEventDetails mouseDetails); | |||
} |
@@ -4,20 +4,17 @@ | |||
package com.vaadin.terminal.gwt.client.ui; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.event.dom.client.DomEvent.Type; | |||
import com.google.gwt.event.shared.EventHandler; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.google.gwt.user.client.Element; | |||
import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.terminal.gwt.client.ApplicationConnection; | |||
import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.EventId; | |||
import com.vaadin.terminal.gwt.client.UIDL; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
public class CssLayoutConnector extends AbstractComponentContainerConnector { | |||
private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( | |||
this, EventId.LAYOUT_CLICK) { | |||
this) { | |||
@Override | |||
protected ComponentConnector getChildComponent(Element element) { | |||
@@ -25,12 +22,23 @@ public class CssLayoutConnector extends AbstractComponentContainerConnector { | |||
} | |||
@Override | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
H handler, Type<H> type) { | |||
return getWidget().addDomHandler(handler, type); | |||
} | |||
protected LayoutClickRPC getLayoutClickRPC() { | |||
return rpc; | |||
}; | |||
}; | |||
public interface CssLayoutServerRPC extends LayoutClickRPC, ServerRpc { | |||
} | |||
private CssLayoutServerRPC rpc = GWT.create(CssLayoutServerRPC.class); | |||
@Override | |||
protected void init() { | |||
super.init(); | |||
initRPC(rpc); | |||
} | |||
@Override | |||
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { | |||
@@ -8,27 +8,37 @@ import java.util.Map; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.dom.client.Document; | |||
import com.google.gwt.dom.client.NativeEvent; | |||
import com.google.gwt.dom.client.Node; | |||
import com.google.gwt.dom.client.NodeList; | |||
import com.google.gwt.dom.client.ObjectElement; | |||
import com.google.gwt.dom.client.Style; | |||
import com.google.gwt.event.dom.client.DomEvent.Type; | |||
import com.google.gwt.event.shared.EventHandler; | |||
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; | |||
import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.terminal.gwt.client.ApplicationConnection; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.UIDL; | |||
import com.vaadin.terminal.gwt.client.VConsole; | |||
import com.vaadin.terminal.gwt.client.VTooltip; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
public class EmbeddedConnector extends AbstractComponentConnector { | |||
public static final String CLICK_EVENT_IDENTIFIER = "click"; | |||
public interface EmbeddedServerRPC extends ClickRPC, ServerRpc { | |||
} | |||
public static final String ALTERNATE_TEXT = "alt"; | |||
EmbeddedServerRPC rpc = GWT.create(EmbeddedServerRPC.class); | |||
@Override | |||
protected void init() { | |||
super.init(); | |||
initRPC(rpc); | |||
} | |||
@Override | |||
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { | |||
super.updateFromUIDL(uidl, client); | |||
@@ -180,12 +190,12 @@ public class EmbeddedConnector extends AbstractComponentConnector { | |||
} | |||
protected final ClickEventHandler clickEventHandler = new ClickEventHandler( | |||
this, CLICK_EVENT_IDENTIFIER) { | |||
this) { | |||
@Override | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
H handler, Type<H> type) { | |||
return getWidget().addDomHandler(handler, type); | |||
protected void fireClick(NativeEvent event, | |||
MouseEventDetails mouseDetails) { | |||
rpc.click(mouseDetails); | |||
} | |||
}; |
@@ -7,25 +7,23 @@ import java.util.HashSet; | |||
import java.util.Iterator; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.event.dom.client.DomEvent.Type; | |||
import com.google.gwt.event.shared.EventHandler; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.google.gwt.user.client.Element; | |||
import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.terminal.gwt.client.ApplicationConnection; | |||
import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.ConnectorMap; | |||
import com.vaadin.terminal.gwt.client.DirectionalManagedLayout; | |||
import com.vaadin.terminal.gwt.client.EventId; | |||
import com.vaadin.terminal.gwt.client.UIDL; | |||
import com.vaadin.terminal.gwt.client.VCaption; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
import com.vaadin.terminal.gwt.client.ui.VGridLayout.Cell; | |||
import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot; | |||
public class GridLayoutConnector extends AbstractComponentContainerConnector | |||
implements DirectionalManagedLayout { | |||
private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler( | |||
this, EventId.LAYOUT_CLICK) { | |||
this) { | |||
@Override | |||
protected ComponentConnector getChildComponent(Element element) { | |||
@@ -33,14 +31,21 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector | |||
} | |||
@Override | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
H handler, Type<H> type) { | |||
return getWidget().addDomHandler(handler, type); | |||
} | |||
protected LayoutClickRPC getLayoutClickRPC() { | |||
return rpc; | |||
}; | |||
}; | |||
public interface GridLayoutServerRPC extends LayoutClickRPC, ServerRpc { | |||
} | |||
private GridLayoutServerRPC rpc = GWT.create(GridLayoutServerRPC.class); | |||
@Override | |||
public void init() { | |||
initRPC(rpc); | |||
getLayoutManager().registerDependency(this, | |||
getWidget().spacingMeasureElement); | |||
} |
@@ -3,17 +3,20 @@ | |||
*/ | |||
package com.vaadin.terminal.gwt.client.ui; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import com.google.gwt.dom.client.NativeEvent; | |||
import com.google.gwt.user.client.Element; | |||
import com.vaadin.terminal.gwt.client.ApplicationConnection; | |||
import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder; | |||
import com.vaadin.terminal.gwt.client.ui.AbstractComponentContainerConnector.LayoutClickRPC; | |||
public abstract class LayoutClickEventHandler extends AbstractClickEventHandler { | |||
public abstract class LayoutClickEventHandler extends ClickEventHandler { | |||
public static final String LAYOUT_CLICK_EVENT_IDENTIFIER = "lClick"; | |||
public LayoutClickEventHandler(ComponentConnector connector) { | |||
this(connector, LAYOUT_CLICK_EVENT_IDENTIFIER); | |||
} | |||
public LayoutClickEventHandler(ComponentConnector connector, | |||
String clickEventIdentifier) { | |||
@@ -22,21 +25,16 @@ public abstract class LayoutClickEventHandler extends ClickEventHandler { | |||
protected abstract ComponentConnector getChildComponent(Element element); | |||
protected ComponentConnector getChildComponent(NativeEvent event) { | |||
return getChildComponent((Element) event.getEventTarget().cast()); | |||
} | |||
@Override | |||
protected void fireClick(NativeEvent event) { | |||
ApplicationConnection client = getApplicationConnection(); | |||
String pid = connector.getConnectorId(); | |||
MouseEventDetails mouseDetails = MouseEventDetailsBuilder | |||
.buildMouseEventDetails(event, getRelativeToElement()); | |||
ComponentConnector childComponent = getChildComponent((Element) event | |||
.getEventTarget().cast()); | |||
Map<String, Object> parameters = new HashMap<String, Object>(); | |||
parameters.put("mouseDetails", mouseDetails.serialize()); | |||
parameters.put("component", childComponent); | |||
client.updateVariable(pid, clickEventIdentifier, parameters, true); | |||
getLayoutClickRPC().layoutClick(mouseDetails, getChildComponent(event)); | |||
} | |||
protected abstract LayoutClickRPC getLayoutClickRPC(); | |||
} |
@@ -4,23 +4,27 @@ | |||
package com.vaadin.terminal.gwt.client.ui; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.dom.client.NativeEvent; | |||
import com.google.gwt.dom.client.Style; | |||
import com.google.gwt.dom.client.Style.Unit; | |||
import com.google.gwt.event.dom.client.DomEvent.Type; | |||
import com.google.gwt.event.shared.EventHandler; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.terminal.gwt.client.ApplicationConnection; | |||
import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.ComponentState; | |||
import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangedEvent; | |||
import com.vaadin.terminal.gwt.client.LayoutManager; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.UIDL; | |||
import com.vaadin.terminal.gwt.client.Util; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
public class PanelConnector extends AbstractComponentContainerConnector | |||
implements SimpleManagedLayout, PostLayoutListener { | |||
public interface PanelServerRPC extends ClickRPC, ServerRpc { | |||
} | |||
public static class PanelState extends ComponentState { | |||
private int tabIndex; | |||
private int scrollLeft, scrollTop; | |||
@@ -51,24 +55,24 @@ public class PanelConnector extends AbstractComponentContainerConnector | |||
} | |||
public static final String CLICK_EVENT_IDENTIFIER = "click"; | |||
private Integer uidlScrollTop; | |||
private ClickEventHandler clickEventHandler = new ClickEventHandler(this, | |||
CLICK_EVENT_IDENTIFIER) { | |||
private ClickEventHandler clickEventHandler = new ClickEventHandler(this) { | |||
@Override | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
H handler, Type<H> type) { | |||
return getWidget().addDomHandler(handler, type); | |||
protected void fireClick(NativeEvent event, | |||
MouseEventDetails mouseDetails) { | |||
rpc.click(mouseDetails); | |||
} | |||
}; | |||
private Integer uidlScrollLeft; | |||
private PanelServerRPC rpc = GWT.create(PanelServerRPC.class); | |||
@Override | |||
public void init() { | |||
initRPC(rpc); | |||
VPanel panel = getWidget(); | |||
LayoutManager layoutManager = getLayoutManager(); | |||
@@ -8,11 +8,9 @@ import java.util.Iterator; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.core.client.Scheduler; | |||
import com.google.gwt.dom.client.NativeEvent; | |||
import com.google.gwt.dom.client.Style; | |||
import com.google.gwt.dom.client.Style.Position; | |||
import com.google.gwt.event.dom.client.DomEvent.Type; | |||
import com.google.gwt.event.shared.EventHandler; | |||
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.Event; | |||
@@ -26,14 +24,26 @@ import com.vaadin.terminal.gwt.client.ComponentConnector; | |||
import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangedEvent; | |||
import com.vaadin.terminal.gwt.client.ConnectorMap; | |||
import com.vaadin.terminal.gwt.client.Focusable; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.UIDL; | |||
import com.vaadin.terminal.gwt.client.Util; | |||
import com.vaadin.terminal.gwt.client.VConsole; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
public class RootConnector extends AbstractComponentContainerConnector | |||
implements SimpleManagedLayout { | |||
private static final String CLICK_EVENT_IDENTIFIER = PanelConnector.CLICK_EVENT_IDENTIFIER; | |||
public interface RootServerRPC extends ClickRPC, ServerRpc { | |||
} | |||
private RootServerRPC rpc = GWT.create(RootServerRPC.class); | |||
@Override | |||
protected void init() { | |||
super.init(); | |||
initRPC(rpc); | |||
} | |||
@Override | |||
public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { | |||
@@ -297,14 +307,14 @@ public class RootConnector extends AbstractComponentContainerConnector | |||
} | |||
} | |||
private ClickEventHandler clickEventHandler = new ClickEventHandler(this, | |||
CLICK_EVENT_IDENTIFIER) { | |||
private ClickEventHandler clickEventHandler = new ClickEventHandler(this) { | |||
@Override | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
H handler, Type<H> type) { | |||
return getWidget().addDomHandler(handler, type); | |||
protected void fireClick(NativeEvent event, | |||
MouseEventDetails mouseDetails) { | |||
rpc.click(mouseDetails); | |||
} | |||
}; | |||
public void updateCaption(ComponentConnector component) { |
@@ -5,12 +5,10 @@ package com.vaadin.terminal.gwt.client.ui; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.dom.client.Element; | |||
import com.google.gwt.dom.client.NativeEvent; | |||
import com.google.gwt.dom.client.Style; | |||
import com.google.gwt.dom.client.Style.Position; | |||
import com.google.gwt.dom.client.Style.Unit; | |||
import com.google.gwt.event.dom.client.DomEvent.Type; | |||
import com.google.gwt.event.shared.EventHandler; | |||
import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.google.gwt.user.client.DOM; | |||
import com.google.gwt.user.client.Event; | |||
import com.google.gwt.user.client.Window; | |||
@@ -20,8 +18,10 @@ 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.LayoutManager; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.UIDL; | |||
import com.vaadin.terminal.gwt.client.Util; | |||
import com.vaadin.terminal.gwt.client.communication.ServerRpc; | |||
import com.vaadin.terminal.gwt.client.ui.PanelConnector.PanelState; | |||
import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; | |||
@@ -29,22 +29,23 @@ public class WindowConnector extends AbstractComponentContainerConnector | |||
implements BeforeShortcutActionListener, SimpleManagedLayout, | |||
PostLayoutListener { | |||
public static class WindowState extends PanelState { | |||
public interface WindowServerRPC extends ClickRPC, ServerRpc { | |||
} | |||
private static final String CLICK_EVENT_IDENTIFIER = PanelConnector.CLICK_EVENT_IDENTIFIER; | |||
public static class WindowState extends PanelState { | |||
private ClickEventHandler clickEventHandler = new ClickEventHandler(this, | |||
CLICK_EVENT_IDENTIFIER) { | |||
} | |||
private ClickEventHandler clickEventHandler = new ClickEventHandler(this) { | |||
@Override | |||
protected <H extends EventHandler> HandlerRegistration registerHandler( | |||
H handler, Type<H> type) { | |||
return getWidget().addDomHandler(handler, type); | |||
protected void fireClick(NativeEvent event, | |||
MouseEventDetails mouseDetails) { | |||
rpc.click(mouseDetails); | |||
} | |||
}; | |||
private WindowServerRPC rpc = GWT.create(WindowServerRPC.class); | |||
@Override | |||
protected boolean delegateCaptionHandling() { | |||
return false; | |||
@@ -53,6 +54,7 @@ public class WindowConnector extends AbstractComponentContainerConnector | |||
@Override | |||
protected void init() { | |||
super.init(); | |||
initRPC(rpc); | |||
getLayoutManager().registerDependency(this, | |||
getWidget().contentPanel.getElement()); | |||
getLayoutManager().registerDependency(this, getWidget().header); |
@@ -16,8 +16,11 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; | |||
import com.vaadin.terminal.PaintException; | |||
import com.vaadin.terminal.PaintTarget; | |||
import com.vaadin.terminal.Sizeable; | |||
import com.vaadin.terminal.gwt.client.EventId; | |||
import com.vaadin.terminal.gwt.client.Connector; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.ui.AbsoluteLayoutConnector; | |||
import com.vaadin.terminal.gwt.client.ui.AbsoluteLayoutConnector.AbsoluteLayoutServerRPC; | |||
import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler; | |||
/** | |||
* AbsoluteLayout is a layout implementation that mimics html absolute | |||
@@ -29,8 +32,14 @@ import com.vaadin.terminal.gwt.client.ui.AbsoluteLayoutConnector; | |||
public class AbsoluteLayout extends AbstractLayout implements | |||
LayoutClickNotifier { | |||
private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; | |||
private AbsoluteLayoutServerRPC rpc = new AbsoluteLayoutServerRPC() { | |||
public void layoutClick(MouseEventDetails mouseDetails, | |||
Connector clickedConnector) { | |||
fireEvent(LayoutClickEvent.createEvent(AbsoluteLayout.this, | |||
mouseDetails, clickedConnector)); | |||
} | |||
}; | |||
// The components in the layout | |||
private Collection<Component> components = new LinkedHashSet<Component>(); | |||
@@ -41,6 +50,7 @@ public class AbsoluteLayout extends AbstractLayout implements | |||
* Creates an AbsoluteLayout with full size. | |||
*/ | |||
public AbsoluteLayout() { | |||
registerRpcImplementation(rpc, AbsoluteLayoutServerRPC.class); | |||
setSizeFull(); | |||
} | |||
@@ -562,12 +572,14 @@ public class AbsoluteLayout extends AbstractLayout implements | |||
} | |||
public void addListener(LayoutClickListener listener) { | |||
addListener(CLICK_EVENT, LayoutClickEvent.class, listener, | |||
addListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, | |||
LayoutClickEvent.class, listener, | |||
LayoutClickListener.clickMethod); | |||
} | |||
public void removeListener(LayoutClickListener listener) { | |||
removeListener(CLICK_EVENT, LayoutClickEvent.class, listener); | |||
removeListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, | |||
LayoutClickEvent.class, listener); | |||
} | |||
} |
@@ -4,14 +4,8 @@ | |||
package com.vaadin.ui; | |||
import java.util.Map; | |||
import com.vaadin.event.LayoutEvents.LayoutClickEvent; | |||
import com.vaadin.event.LayoutEvents.LayoutClickNotifier; | |||
import com.vaadin.terminal.PaintException; | |||
import com.vaadin.terminal.PaintTarget; | |||
import com.vaadin.terminal.gwt.client.EventId; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.ui.Layout.MarginHandler; | |||
/** | |||
@@ -27,8 +21,6 @@ import com.vaadin.ui.Layout.MarginHandler; | |||
public abstract class AbstractLayout extends AbstractComponentContainer | |||
implements Layout, MarginHandler { | |||
private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; | |||
protected MarginInfo margins = new MarginInfo(false); | |||
/* | |||
@@ -85,45 +77,4 @@ public abstract class AbstractLayout extends AbstractComponentContainer | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractComponent#changeVariables(java.lang.Object, | |||
* java.util.Map) | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
@Override | |||
public void changeVariables(Object source, Map<String, Object> variables) { | |||
super.changeVariables(source, variables); | |||
// not all subclasses use these events | |||
if (this instanceof LayoutClickNotifier | |||
&& variables.containsKey(CLICK_EVENT)) { | |||
fireClick((Map<String, Object>) variables.get(CLICK_EVENT)); | |||
} | |||
} | |||
/** | |||
* Fire a layout click event. | |||
* | |||
* Note that this method is only used by the subclasses that implement | |||
* {@link LayoutClickNotifier}, and can be overridden for custom click event | |||
* firing. | |||
* | |||
* @param parameters | |||
* The parameters received from the client side implementation | |||
*/ | |||
protected void fireClick(Map<String, Object> parameters) { | |||
MouseEventDetails mouseDetails = MouseEventDetails | |||
.deSerialize((String) parameters.get("mouseDetails")); | |||
Component clickedComponent = (Component) parameters.get("component"); | |||
Component childComponent = clickedComponent; | |||
while (childComponent != null && childComponent.getParent() != this) { | |||
childComponent = childComponent.getParent(); | |||
} | |||
fireEvent(new LayoutClickEvent(this, mouseDetails, clickedComponent, | |||
childComponent)); | |||
} | |||
} |
@@ -15,13 +15,23 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; | |||
import com.vaadin.terminal.PaintException; | |||
import com.vaadin.terminal.PaintTarget; | |||
import com.vaadin.terminal.Sizeable; | |||
import com.vaadin.terminal.gwt.client.EventId; | |||
import com.vaadin.terminal.gwt.client.Connector; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.ui.AbstractOrderedLayoutConnector.AbstractOrderedLayoutServerRPC; | |||
import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler; | |||
@SuppressWarnings("serial") | |||
public abstract class AbstractOrderedLayout extends AbstractLayout implements | |||
Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier { | |||
private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; | |||
private AbstractOrderedLayoutServerRPC rpc = new AbstractOrderedLayoutServerRPC() { | |||
public void layoutClick(MouseEventDetails mouseDetails, | |||
Connector clickedConnector) { | |||
fireEvent(LayoutClickEvent.createEvent(AbstractOrderedLayout.this, | |||
mouseDetails, clickedConnector)); | |||
} | |||
}; | |||
public static final Alignment ALIGNMENT_DEFAULT = Alignment.TOP_LEFT; | |||
@@ -44,6 +54,10 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements | |||
*/ | |||
private boolean spacing = false; | |||
public AbstractOrderedLayout() { | |||
registerRpcImplementation(rpc, AbstractOrderedLayoutServerRPC.class); | |||
} | |||
/** | |||
* Add a component into this container. The component is added to the right | |||
* or under the previous component. | |||
@@ -367,12 +381,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements | |||
} | |||
public void addListener(LayoutClickListener listener) { | |||
addListener(CLICK_EVENT, LayoutClickEvent.class, listener, | |||
addListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, | |||
LayoutClickEvent.class, listener, | |||
LayoutClickListener.clickMethod); | |||
} | |||
public void removeListener(LayoutClickListener listener) { | |||
removeListener(CLICK_EVENT, LayoutClickEvent.class, listener); | |||
removeListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, | |||
LayoutClickEvent.class, listener); | |||
} | |||
/** |
@@ -7,16 +7,16 @@ package com.vaadin.ui; | |||
import java.io.Serializable; | |||
import java.lang.reflect.Method; | |||
import java.util.Iterator; | |||
import java.util.Map; | |||
import com.vaadin.event.ComponentEventListener; | |||
import com.vaadin.event.MouseEvents.ClickEvent; | |||
import com.vaadin.terminal.Sizeable; | |||
import com.vaadin.terminal.gwt.client.ComponentState; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.ui.AbstractSplitPanelConnector; | |||
import com.vaadin.terminal.gwt.client.ui.AbstractSplitPanelConnector.AbstractSplitPanelRPC; | |||
import com.vaadin.terminal.gwt.client.ui.AbstractSplitPanelConnector.AbstractSplitPanelState; | |||
import com.vaadin.terminal.gwt.client.ui.AbstractSplitPanelConnector.SplitterState; | |||
import com.vaadin.terminal.gwt.client.ui.ClickEventHandler; | |||
import com.vaadin.tools.ReflectTools; | |||
/** | |||
@@ -34,9 +34,20 @@ public abstract class AbstractSplitPanel extends AbstractLayout { | |||
private Unit posUnit; | |||
private static final String SPLITTER_CLICK_EVENT = AbstractSplitPanelConnector.SPLITTER_CLICK_EVENT_IDENTIFIER; | |||
private AbstractSplitPanelRPC rpc = new AbstractSplitPanelRPC() { | |||
public void splitterClick(MouseEventDetails mouseDetails) { | |||
fireEvent(new SplitterClickEvent(AbstractSplitPanel.this, | |||
mouseDetails)); | |||
} | |||
public void setSplitterPosition(int position) { | |||
getState().getSplitterState().setPosition(position); | |||
} | |||
}; | |||
public AbstractSplitPanel() { | |||
registerRpcImplementation(rpc, AbstractSplitPanelRPC.class); | |||
setSplitPosition(50, Unit.PERCENTAGE, false); | |||
} | |||
@@ -330,36 +341,6 @@ public abstract class AbstractSplitPanel extends AbstractLayout { | |||
return getState().getSplitterState().isLocked(); | |||
} | |||
/* | |||
* Invoked when a variable of the component changes. Don't add a JavaDoc | |||
* comment here, we use the default documentation from implemented | |||
* interface. | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
@Override | |||
public void changeVariables(Object source, Map<String, Object> variables) { | |||
super.changeVariables(source, variables); | |||
if (variables.containsKey("position") && !isLocked()) { | |||
Integer newPos = (Integer) variables.get("position"); | |||
getState().getSplitterState().setPosition(newPos); | |||
} | |||
if (variables.containsKey(SPLITTER_CLICK_EVENT)) { | |||
fireClick((Map<String, Object>) variables.get(SPLITTER_CLICK_EVENT)); | |||
} | |||
} | |||
@Override | |||
protected void fireClick(Map<String, Object> parameters) { | |||
MouseEventDetails mouseDetails = MouseEventDetails | |||
.deSerialize((String) parameters.get("mouseDetails")); | |||
fireEvent(new SplitterClickEvent(this, mouseDetails)); | |||
} | |||
/** | |||
* <code>SplitterClickListener</code> interface for listening for | |||
* <code>SplitterClickEvent</code> fired by a <code>SplitPanel</code>. | |||
@@ -392,12 +373,14 @@ public abstract class AbstractSplitPanel extends AbstractLayout { | |||
} | |||
public void addListener(SplitterClickListener listener) { | |||
addListener(SPLITTER_CLICK_EVENT, SplitterClickEvent.class, listener, | |||
addListener(ClickEventHandler.CLICK_EVENT_IDENTIFIER, | |||
SplitterClickEvent.class, listener, | |||
SplitterClickListener.clickMethod); | |||
} | |||
public void removeListener(SplitterClickListener listener) { | |||
removeListener(SPLITTER_CLICK_EVENT, SplitterClickEvent.class, listener); | |||
removeListener(ClickEventHandler.CLICK_EVENT_IDENTIFIER, | |||
SplitterClickEvent.class, listener); | |||
} | |||
@Override |
@@ -13,8 +13,11 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; | |||
import com.vaadin.terminal.PaintException; | |||
import com.vaadin.terminal.PaintTarget; | |||
import com.vaadin.terminal.Paintable; | |||
import com.vaadin.terminal.gwt.client.EventId; | |||
import com.vaadin.terminal.gwt.client.Connector; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.ui.CssLayoutConnector; | |||
import com.vaadin.terminal.gwt.client.ui.CssLayoutConnector.CssLayoutServerRPC; | |||
import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler; | |||
/** | |||
* CssLayout is a layout component that can be used in browser environment only. | |||
@@ -60,13 +63,23 @@ import com.vaadin.terminal.gwt.client.ui.CssLayoutConnector; | |||
@ClientWidget(CssLayoutConnector.class) | |||
public class CssLayout extends AbstractLayout implements LayoutClickNotifier { | |||
private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; | |||
private CssLayoutServerRPC rpc = new CssLayoutServerRPC() { | |||
public void layoutClick(MouseEventDetails mouseDetails, | |||
Connector clickedConnector) { | |||
fireEvent(LayoutClickEvent.createEvent(CssLayout.this, | |||
mouseDetails, clickedConnector)); | |||
} | |||
}; | |||
/** | |||
* Custom layout slots containing the components. | |||
*/ | |||
protected LinkedList<Component> components = new LinkedList<Component>(); | |||
public CssLayout() { | |||
registerRpcImplementation(rpc, CssLayoutServerRPC.class); | |||
} | |||
/** | |||
* Add a component into this container. The component is added to the right | |||
* or under the previous component. | |||
@@ -267,12 +280,14 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { | |||
} | |||
public void addListener(LayoutClickListener listener) { | |||
addListener(CLICK_EVENT, LayoutClickEvent.class, listener, | |||
addListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, | |||
LayoutClickEvent.class, listener, | |||
LayoutClickListener.clickMethod); | |||
} | |||
public void removeListener(LayoutClickListener listener) { | |||
removeListener(CLICK_EVENT, LayoutClickEvent.class, listener); | |||
removeListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, | |||
LayoutClickEvent.class, listener); | |||
} | |||
/** |
@@ -14,7 +14,9 @@ import com.vaadin.terminal.PaintException; | |||
import com.vaadin.terminal.PaintTarget; | |||
import com.vaadin.terminal.Resource; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.ui.ClickEventHandler; | |||
import com.vaadin.terminal.gwt.client.ui.EmbeddedConnector; | |||
import com.vaadin.terminal.gwt.client.ui.EmbeddedConnector.EmbeddedServerRPC; | |||
/** | |||
* Component for embedding external objects. | |||
@@ -28,8 +30,6 @@ import com.vaadin.terminal.gwt.client.ui.EmbeddedConnector; | |||
@ClientWidget(EmbeddedConnector.class) | |||
public class Embedded extends AbstractComponent { | |||
private static final String CLICK_EVENT = EmbeddedConnector.CLICK_EVENT_IDENTIFIER; | |||
/** | |||
* General object type. | |||
*/ | |||
@@ -80,6 +80,12 @@ public class Embedded extends AbstractComponent { | |||
private String altText; | |||
private EmbeddedServerRPC rpc = new EmbeddedServerRPC() { | |||
public void click(MouseEventDetails mouseDetails) { | |||
fireEvent(new ClickEvent(Embedded.this, mouseDetails)); | |||
} | |||
}; | |||
/** | |||
* Creates a new empty Embedded object. | |||
*/ | |||
@@ -498,8 +504,8 @@ public class Embedded extends AbstractComponent { | |||
* The listener to add | |||
*/ | |||
public void addListener(ClickListener listener) { | |||
addListener(CLICK_EVENT, ClickEvent.class, listener, | |||
ClickListener.clickMethod); | |||
addListener(ClickEventHandler.CLICK_EVENT_IDENTIFIER, ClickEvent.class, | |||
listener, ClickListener.clickMethod); | |||
} | |||
/** | |||
@@ -510,35 +516,8 @@ public class Embedded extends AbstractComponent { | |||
* The listener to remove | |||
*/ | |||
public void removeListener(ClickListener listener) { | |||
removeListener(CLICK_EVENT, ClickEvent.class, listener); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractComponent#changeVariables(java.lang.Object, | |||
* java.util.Map) | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
@Override | |||
public void changeVariables(Object source, Map<String, Object> variables) { | |||
super.changeVariables(source, variables); | |||
if (variables.containsKey(CLICK_EVENT)) { | |||
fireClick((Map<String, Object>) variables.get(CLICK_EVENT)); | |||
} | |||
} | |||
/** | |||
* Notifies click-listeners that a mouse click event has occurred. | |||
* | |||
* @param parameters | |||
*/ | |||
private void fireClick(Map<String, Object> parameters) { | |||
MouseEventDetails mouseDetails = MouseEventDetails | |||
.deSerialize((String) parameters.get("mouseDetails")); | |||
fireEvent(new ClickEvent(this, mouseDetails)); | |||
removeListener(ClickEventHandler.CLICK_EVENT_IDENTIFIER, | |||
ClickEvent.class, listener); | |||
} | |||
} |
@@ -17,8 +17,11 @@ import com.vaadin.event.LayoutEvents.LayoutClickListener; | |||
import com.vaadin.event.LayoutEvents.LayoutClickNotifier; | |||
import com.vaadin.terminal.PaintException; | |||
import com.vaadin.terminal.PaintTarget; | |||
import com.vaadin.terminal.gwt.client.EventId; | |||
import com.vaadin.terminal.gwt.client.Connector; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.ui.GridLayoutConnector; | |||
import com.vaadin.terminal.gwt.client.ui.GridLayoutConnector.GridLayoutServerRPC; | |||
import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler; | |||
/** | |||
* A layout where the components are laid out on a grid using cell coordinates. | |||
@@ -51,8 +54,15 @@ import com.vaadin.terminal.gwt.client.ui.GridLayoutConnector; | |||
public class GridLayout extends AbstractLayout implements | |||
Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier { | |||
private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; | |||
private GridLayoutServerRPC rpc = new GridLayoutServerRPC() { | |||
public void layoutClick(MouseEventDetails mouseDetails, | |||
Connector clickedConnector) { | |||
fireEvent(LayoutClickEvent.createEvent(GridLayout.this, | |||
mouseDetails, clickedConnector)); | |||
} | |||
}; | |||
/** | |||
* Initial grid columns. | |||
*/ | |||
@@ -121,6 +131,7 @@ public class GridLayout extends AbstractLayout implements | |||
public GridLayout(int columns, int rows) { | |||
setColumns(columns); | |||
setRows(rows); | |||
registerRpcImplementation(rpc, GridLayoutServerRPC.class); | |||
} | |||
/** | |||
@@ -1414,12 +1425,14 @@ public class GridLayout extends AbstractLayout implements | |||
} | |||
public void addListener(LayoutClickListener listener) { | |||
addListener(CLICK_EVENT, LayoutClickEvent.class, listener, | |||
addListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, | |||
LayoutClickEvent.class, listener, | |||
LayoutClickListener.clickMethod); | |||
} | |||
public void removeListener(LayoutClickListener listener) { | |||
removeListener(CLICK_EVENT, LayoutClickEvent.class, listener); | |||
removeListener(LayoutClickEventHandler.LAYOUT_CLICK_EVENT_IDENTIFIER, | |||
LayoutClickEvent.class, listener); | |||
} | |||
} |
@@ -16,7 +16,9 @@ import com.vaadin.terminal.PaintException; | |||
import com.vaadin.terminal.PaintTarget; | |||
import com.vaadin.terminal.Scrollable; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.ui.ClickEventHandler; | |||
import com.vaadin.terminal.gwt.client.ui.PanelConnector; | |||
import com.vaadin.terminal.gwt.client.ui.PanelConnector.PanelServerRPC; | |||
import com.vaadin.terminal.gwt.client.ui.PanelConnector.PanelState; | |||
import com.vaadin.ui.Component.Focusable; | |||
@@ -34,8 +36,6 @@ public class Panel extends AbstractComponentContainer implements Scrollable, | |||
ComponentContainer.ComponentAttachListener, | |||
ComponentContainer.ComponentDetachListener, Action.Notifier, Focusable { | |||
private static final String CLICK_EVENT = PanelConnector.CLICK_EVENT_IDENTIFIER; | |||
/** | |||
* Content of the panel. | |||
*/ | |||
@@ -47,6 +47,12 @@ public class Panel extends AbstractComponentContainer implements Scrollable, | |||
*/ | |||
protected ActionManager actionManager; | |||
private PanelServerRPC rpc = new PanelServerRPC() { | |||
public void click(MouseEventDetails mouseDetails) { | |||
fireEvent(new ClickEvent(Panel.this, mouseDetails)); | |||
} | |||
}; | |||
/** | |||
* Creates a new empty panel. A VerticalLayout is used as content. | |||
*/ | |||
@@ -62,6 +68,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, | |||
* the content for the panel. | |||
*/ | |||
public Panel(ComponentContainer content) { | |||
registerRpcImplementation(rpc, PanelServerRPC.class); | |||
setContent(content); | |||
setWidth(100, Unit.PERCENTAGE); | |||
getState().setTabIndex(-1); | |||
@@ -287,10 +294,6 @@ public class Panel extends AbstractComponentContainer implements Scrollable, | |||
public void changeVariables(Object source, Map<String, Object> variables) { | |||
super.changeVariables(source, variables); | |||
if (variables.containsKey(CLICK_EVENT)) { | |||
fireClick((Map<String, Object>) variables.get(CLICK_EVENT)); | |||
} | |||
// Get new size | |||
final Integer newWidth = (Integer) variables.get("width"); | |||
final Integer newHeight = (Integer) variables.get("height"); | |||
@@ -489,8 +492,8 @@ public class Panel extends AbstractComponentContainer implements Scrollable, | |||
* The listener to add | |||
*/ | |||
public void addListener(ClickListener listener) { | |||
addListener(CLICK_EVENT, ClickEvent.class, listener, | |||
ClickListener.clickMethod); | |||
addListener(ClickEventHandler.CLICK_EVENT_IDENTIFIER, ClickEvent.class, | |||
listener, ClickListener.clickMethod); | |||
} | |||
/** | |||
@@ -501,19 +504,8 @@ public class Panel extends AbstractComponentContainer implements Scrollable, | |||
* The listener to remove | |||
*/ | |||
public void removeListener(ClickListener listener) { | |||
removeListener(CLICK_EVENT, ClickEvent.class, listener); | |||
} | |||
/** | |||
* Fire a click event to all click listeners. | |||
* | |||
* @param object | |||
* The raw "value" of the variable change from the client side. | |||
*/ | |||
private void fireClick(Map<String, Object> parameters) { | |||
MouseEventDetails mouseDetails = MouseEventDetails | |||
.deSerialize((String) parameters.get("mouseDetails")); | |||
fireEvent(new ClickEvent(this, mouseDetails)); | |||
removeListener(ClickEventHandler.CLICK_EVENT_IDENTIFIER, | |||
ClickEvent.class, listener); | |||
} | |||
/** |
@@ -30,6 +30,7 @@ import com.vaadin.terminal.Resource; | |||
import com.vaadin.terminal.WrappedRequest; | |||
import com.vaadin.terminal.WrappedRequest.BrowserDetails; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.ui.RootConnector.RootServerRPC; | |||
import com.vaadin.terminal.gwt.client.ui.VNotification; | |||
import com.vaadin.terminal.gwt.client.ui.VView; | |||
import com.vaadin.tools.ReflectTools; | |||
@@ -412,12 +413,18 @@ public abstract class Root extends AbstractComponentContainer implements | |||
private DirtyConnectorTracker dirtyConnectorTracker = new DirtyConnectorTracker( | |||
this); | |||
private RootServerRPC rpc = new RootServerRPC() { | |||
public void click(MouseEventDetails mouseDetails) { | |||
fireEvent(new ClickEvent(Root.this, mouseDetails)); | |||
} | |||
}; | |||
/** | |||
* Creates a new empty root without a caption. This root will have a | |||
* {@link VerticalLayout} with margins enabled as its content. | |||
*/ | |||
public Root() { | |||
// Nothing to do here? | |||
registerRpcImplementation(rpc, RootServerRPC.class); | |||
} | |||
/** | |||
@@ -429,6 +436,7 @@ public abstract class Root extends AbstractComponentContainer implements | |||
* @see #setContent(ComponentContainer) | |||
*/ | |||
public Root(ComponentContainer content) { | |||
this(); | |||
setContent(content); | |||
} | |||
@@ -443,6 +451,7 @@ public abstract class Root extends AbstractComponentContainer implements | |||
* @see #setCaption(String) | |||
*/ | |||
public Root(String caption) { | |||
this(); | |||
setCaption(caption); | |||
} | |||
@@ -15,14 +15,17 @@ import com.vaadin.event.FieldEvents.BlurNotifier; | |||
import com.vaadin.event.FieldEvents.FocusEvent; | |||
import com.vaadin.event.FieldEvents.FocusListener; | |||
import com.vaadin.event.FieldEvents.FocusNotifier; | |||
import com.vaadin.event.MouseEvents.ClickEvent; | |||
import com.vaadin.event.ShortcutAction; | |||
import com.vaadin.event.ShortcutAction.KeyCode; | |||
import com.vaadin.event.ShortcutAction.ModifierKey; | |||
import com.vaadin.event.ShortcutListener; | |||
import com.vaadin.terminal.PaintException; | |||
import com.vaadin.terminal.PaintTarget; | |||
import com.vaadin.terminal.gwt.client.MouseEventDetails; | |||
import com.vaadin.terminal.gwt.client.ui.VView; | |||
import com.vaadin.terminal.gwt.client.ui.WindowConnector; | |||
import com.vaadin.terminal.gwt.client.ui.WindowConnector.WindowServerRPC; | |||
import com.vaadin.terminal.gwt.client.ui.WindowConnector.WindowState; | |||
/** | |||
@@ -113,6 +116,13 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier { | |||
*/ | |||
private boolean resizeLazy = false; | |||
private WindowServerRPC rpc = new WindowServerRPC() { | |||
public void click(MouseEventDetails mouseDetails) { | |||
fireEvent(new ClickEvent(Window.this, mouseDetails)); | |||
} | |||
}; | |||
/** | |||
* Creates a new unnamed window with a default layout. | |||
*/ | |||
@@ -140,6 +150,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier { | |||
*/ | |||
public Window(String caption, ComponentContainer content) { | |||
super(caption, content); | |||
registerRpcImplementation(rpc, WindowServerRPC.class); | |||
setSizeUndefined(); | |||
} | |||