aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-06-10 19:28:57 +0300
committerVaadin Code Review <review@vaadin.com>2013-06-11 08:08:47 +0000
commit424af57c0a99bf93066d331fe6a3a870cc44cf24 (patch)
tree701ed59ab57c4279bb92bdde9c6879432ce05a4b /server/src/com/vaadin/ui
parent5adb5c2cfa5cb3d5c148e1116bd99523998e95fa (diff)
downloadvaadin-framework-424af57c0a99bf93066d331fe6a3a870cc44cf24.tar.gz
vaadin-framework-424af57c0a99bf93066d331fe6a3a870cc44cf24.zip
Move ClientConnector.setParent to Component and Extension (#11777)
Change-Id: I1f0b2597f621160329ddc432869277b2758efd52
Diffstat (limited to 'server/src/com/vaadin/ui')
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java34
-rw-r--r--server/src/com/vaadin/ui/Component.java26
-rw-r--r--server/src/com/vaadin/ui/Window.java3
3 files changed, 52 insertions, 11 deletions
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 {