diff options
author | Artur Signell <artur@vaadin.com> | 2013-06-10 19:28:57 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-06-11 08:08:47 +0000 |
commit | 424af57c0a99bf93066d331fe6a3a870cc44cf24 (patch) | |
tree | 701ed59ab57c4279bb92bdde9c6879432ce05a4b /server/src | |
parent | 5adb5c2cfa5cb3d5c148e1116bd99523998e95fa (diff) | |
download | vaadin-framework-424af57c0a99bf93066d331fe6a3a870cc44cf24.tar.gz vaadin-framework-424af57c0a99bf93066d331fe6a3a870cc44cf24.zip |
Move ClientConnector.setParent to Component and Extension (#11777)
Change-Id: I1f0b2597f621160329ddc432869277b2758efd52
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/server/AbstractClientConnector.java | 34 | ||||
-rw-r--r-- | server/src/com/vaadin/server/AbstractExtension.java | 33 | ||||
-rw-r--r-- | server/src/com/vaadin/server/ClientConnector.java | 33 | ||||
-rw-r--r-- | server/src/com/vaadin/server/DragAndDropService.java | 6 | ||||
-rw-r--r-- | server/src/com/vaadin/server/Extension.java | 21 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/AbstractComponent.java | 34 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/Component.java | 26 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/Window.java | 3 |
8 files changed, 105 insertions, 85 deletions
diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index 01f7d9af42..c3101924dd 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -84,8 +84,6 @@ public abstract class AbstractClientConnector implements ClientConnector, private ArrayList<Extension> extensions = new ArrayList<Extension>(); - private ClientConnector parent; - /** * The EventRouter used for the event model. */ @@ -563,38 +561,6 @@ public abstract class AbstractClientConnector implements ClientConnector, markAsDirty(); } - @Override - public void setParent(ClientConnector parent) { - - // If the parent is not changed, don't do anything - if (parent == this.parent) { - return; - } - - if (parent != null && this.parent != null) { - throw new IllegalStateException(getClass().getName() - + " already has a parent."); - } - - // Send detach event if the component have been connected to a window - if (isAttached()) { - detach(); - } - - // Connect to new parent - this.parent = parent; - - // Send attach event if connected to an application - if (isAttached()) { - attach(); - } - } - - @Override - public ClientConnector getParent() { - return parent; - } - /* * (non-Javadoc) * diff --git a/server/src/com/vaadin/server/AbstractExtension.java b/server/src/com/vaadin/server/AbstractExtension.java index 00496aed4a..0387ad1b08 100644 --- a/server/src/com/vaadin/server/AbstractExtension.java +++ b/server/src/com/vaadin/server/AbstractExtension.java @@ -33,6 +33,8 @@ public abstract class AbstractExtension extends AbstractClientConnector implements Extension { private boolean previouslyAttached = false; + private ClientConnector parent; + /** * Gets a type that the parent must be an instance of. Override this if the * extension only support certain targets, e.g. if only TextFields can be @@ -69,7 +71,7 @@ public abstract class AbstractExtension extends AbstractClientConnector Class<? extends ClientConnector> supportedParentType = getSupportedParentType(); if (parent == null || supportedParentType.isInstance(parent)) { - super.setParent(parent); + internalSetParent(parent); previouslyAttached = true; } else { throw new IllegalArgumentException(getClass().getName() @@ -79,4 +81,33 @@ public abstract class AbstractExtension extends AbstractClientConnector } } + /** + * Actually sets the parent and calls required listeners. + * + * @since 7.1 + * @param parent + * The parent to set + */ + private void internalSetParent(ClientConnector parent) { + + // Send a detach event if the component is currently attached + if (isAttached()) { + detach(); + } + + // Connect to new parent + this.parent = parent; + + // Send attach event if the component is now attached + if (isAttached()) { + attach(); + } + + } + + @Override + public ClientConnector getParent() { + return parent; + } + } diff --git a/server/src/com/vaadin/server/ClientConnector.java b/server/src/com/vaadin/server/ClientConnector.java index 9e328bb6ef..3c06d5743c 100644 --- a/server/src/com/vaadin/server/ClientConnector.java +++ b/server/src/com/vaadin/server/ClientConnector.java @@ -27,8 +27,6 @@ import com.vaadin.event.ConnectorEvent; import com.vaadin.event.ConnectorEventListener; import com.vaadin.shared.Connector; import com.vaadin.shared.communication.SharedState; -import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.UI; import com.vaadin.util.ReflectTools; @@ -195,37 +193,6 @@ public interface ClientConnector extends Connector { public void markAsDirtyRecursive(); /** - * Sets the parent connector of the connector. - * - * <p> - * This method automatically calls {@link #attach()} if the connector - * becomes attached to the application, regardless of whether it was - * attached previously. Conversely, if the parent is {@code null} and the - * connector is attached to the application, {@link #detach()} is called for - * the connector. - * </p> - * <p> - * This method is rarely called directly. One of the - * {@link ComponentContainer#addComponent(Component)} or - * {@link AbstractClientConnector#addExtension(Extension)} methods are - * normally used for adding connectors to a parent and they will call this - * method implicitly. - * </p> - * - * <p> - * It is not possible to change the parent without first setting the parent - * to {@code null}. - * </p> - * - * @param parent - * the parent connector - * @throws IllegalStateException - * if a parent is given even though the connector already has a - * parent - */ - public void setParent(ClientConnector parent); - - /** * Checks if the connector is attached to a VaadinSession. * * @since 7.1 diff --git a/server/src/com/vaadin/server/DragAndDropService.java b/server/src/com/vaadin/server/DragAndDropService.java index df2361e887..cef1bb86e7 100644 --- a/server/src/com/vaadin/server/DragAndDropService.java +++ b/server/src/com/vaadin/server/DragAndDropService.java @@ -315,12 +315,6 @@ public class DragAndDropService implements VariableOwner, ClientConnector { } @Override - public void setParent(ClientConnector parent) { - // TODO Auto-generated method stub - - } - - @Override public void attach() { // TODO Auto-generated method stub diff --git a/server/src/com/vaadin/server/Extension.java b/server/src/com/vaadin/server/Extension.java index 2e632fc6c9..0f3d81598e 100644 --- a/server/src/com/vaadin/server/Extension.java +++ b/server/src/com/vaadin/server/Extension.java @@ -35,4 +35,25 @@ public interface Extension extends ClientConnector { * removed, it cannot be attached again. */ void remove(); + + /** + * Sets the parent connector of the connector. + * + * This method automatically calls {@link #attach()} if the connector + * becomes attached to the session. + * <p> + * This method is rarely called directly. + * {@link AbstractClientConnector#addExtension(Extension)} is normally used + * for adding extensions to a parent and it will call this method + * implicitly. + * </p> + * + * @param parent + * the parent connector + * @throws IllegalStateException + * if a parent is given even though the connector already has a + * parent + */ + public void setParent(ClientConnector parent); + } diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index 9ff36a42d2..0bf27435fb 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -28,7 +28,6 @@ import java.util.regex.Pattern; import com.vaadin.event.ActionManager; import com.vaadin.event.ShortcutListener; import com.vaadin.server.AbstractClientConnector; -import com.vaadin.server.ClientConnector; import com.vaadin.server.ComponentSizeValidator; import com.vaadin.server.ErrorHandler; import com.vaadin.server.ErrorMessage; @@ -94,6 +93,8 @@ public abstract class AbstractComponent extends AbstractClientConnector private boolean visible = true; + private HasComponents parent; + /* Constructor */ /** @@ -451,17 +452,32 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public HasComponents getParent() { - return (HasComponents) super.getParent(); + return parent; } @Override - public void setParent(ClientConnector parent) { - if (parent == null || parent instanceof HasComponents) { - super.setParent(parent); - } else { - throw new IllegalArgumentException( - "The parent of a Component must implement HasComponents, which " - + parent.getClass() + " doesn't do."); + public void setParent(HasComponents parent) { + // If the parent is not changed, don't do anything + if (parent == this.parent) { + return; + } + + if (parent != null && this.parent != null) { + throw new IllegalStateException(getClass().getName() + + " already has a parent."); + } + + // Send a detach event if the component is currently attached + if (isAttached()) { + detach(); + } + + // Connect to new parent + this.parent = parent; + + // Send attach event if the component is now attached + if (isAttached()) { + attach(); } } diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java index 20958812fc..485327bb54 100644 --- a/server/src/com/vaadin/ui/Component.java +++ b/server/src/com/vaadin/ui/Component.java @@ -333,6 +333,32 @@ public interface Component extends ClientConnector, Sizeable, Serializable { public void setVisible(boolean visible); /** + * Sets the parent connector of the component. + * + * <p> + * This method automatically calls {@link #attach()} if the component + * becomes attached to the session, regardless of whether it was attached + * previously. Conversely, if the component currently is attached to the + * session, {@link #detach()} is called for the connector before attaching + * it to a new parent. + * </p> + * <p> + * This method is rarely called directly. + * {@link ComponentContainer#addComponent(Component)} or a + * {@link HasComponents} specific method is normally used for adding + * components to a parent and the used method will call this method + * implicitly. + * </p> + * + * @param parent + * the parent connector + * @throws IllegalStateException + * if a parent is given even though the connector already has a + * parent + */ + public void setParent(HasComponents parent); + + /** * Gets the parent component of the component. * * <p> diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index 9f64c9118e..700d0eb387 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -31,7 +31,6 @@ 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.server.ClientConnector; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.shared.MouseEventDetails; @@ -139,7 +138,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * ) */ @Override - public void setParent(ClientConnector parent) { + public void setParent(HasComponents parent) { if (parent == null || parent instanceof UI) { super.setParent(parent); } else { |