From: Artur Signell Date: Mon, 27 May 2013 13:37:32 +0000 (+0300) Subject: Added ComponentConnector.isAttached (#11928) X-Git-Tag: 7.1.0~90^2~36 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e52df7cdf8bbee662f539b1cee7344debb07c586;p=vaadin-framework.git Added ComponentConnector.isAttached (#11928) Change-Id: I70d7d78a0d9de76080f6e0770a48504af8abdd84 --- diff --git a/server/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java b/server/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java index 65c1050fb0..0cc2f0a1a5 100644 --- a/server/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java +++ b/server/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java @@ -48,7 +48,7 @@ public class SourceIs extends ClientSideCriterion { int paintedComponents = 0; for (int i = 0; i < components.length; i++) { Component c = components[i]; - if (c.getUI() != null && c.getUI().getSession() != null) { + if (c.isAttached()) { target.addAttribute("component" + paintedComponents++, c); } else { Logger.getLogger(SourceIs.class.getName()) diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index e998b8ed55..01f7d9af42 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -577,7 +577,7 @@ public abstract class AbstractClientConnector implements ClientConnector, } // Send detach event if the component have been connected to a window - if (getSession() != null) { + if (isAttached()) { detach(); } @@ -585,7 +585,7 @@ public abstract class AbstractClientConnector implements ClientConnector, this.parent = parent; // Send attach event if connected to an application - if (getSession() != null) { + if (isAttached()) { attach(); } } @@ -595,6 +595,16 @@ public abstract class AbstractClientConnector implements ClientConnector, return parent; } + /* + * (non-Javadoc) + * + * @see com.vaadin.server.ClientConnector#isAttached() + */ + @Override + public boolean isAttached() { + return getSession() != null; + } + @Override public void attach() { markAsDirty(); diff --git a/server/src/com/vaadin/server/ClientConnector.java b/server/src/com/vaadin/server/ClientConnector.java index 3b52fbc730..9e328bb6ef 100644 --- a/server/src/com/vaadin/server/ClientConnector.java +++ b/server/src/com/vaadin/server/ClientConnector.java @@ -226,14 +226,22 @@ public interface ClientConnector extends Connector { public void setParent(ClientConnector parent); /** - * Notifies the connector that it is connected to an application. + * Checks if the connector is attached to a VaadinSession. * + * @since 7.1 + * @return true if the connector is attached to a session, false otherwise + */ + public boolean isAttached(); + + /** + * Notifies the connector that it is connected to a VaadinSession (and + * therefore also to a UI). *

* The caller of this method is {@link #setParent(ClientConnector)} if the - * parent is itself already attached to the application. If not, the parent - * will call the {@link #attach()} for all its children when it is attached - * to the application. This method is always called before the connector's - * data is sent to the client-side for the first time. + * parent is itself already attached to the session. If not, the parent will + * call the {@link #attach()} for all its children when it is attached to + * the session. This method is always called before the connector's data is + * sent to the client-side for the first time. *

* *

@@ -243,13 +251,13 @@ public interface ClientConnector extends Connector { public void attach(); /** - * Notifies the connector that it is detached from the application. + * Notifies the connector that it is detached from its VaadinSession. * *

* The caller of this method is {@link #setParent(ClientConnector)} if the - * parent is in the application. When the parent is detached from the - * application it is its responsibility to call {@link #detach()} for each - * of its children. + * parent is in the session. When the parent is detached from the session it + * is its responsibility to call {@link #detach()} for each of its children. + * *

*/ public void detach(); diff --git a/server/src/com/vaadin/server/DragAndDropService.java b/server/src/com/vaadin/server/DragAndDropService.java index a83e83ef7f..cc571853fe 100644 --- a/server/src/com/vaadin/server/DragAndDropService.java +++ b/server/src/com/vaadin/server/DragAndDropService.java @@ -375,4 +375,14 @@ public class DragAndDropService implements VariableOwner, ClientConnector { @Override public void removeDetachListener(DetachListener listener) { } + + /* + * (non-Javadoc) + * + * @see com.vaadin.server.ClientConnector#isAttached() + */ + @Override + public boolean isAttached() { + return true; + } } diff --git a/server/src/com/vaadin/server/LegacyApplication.java b/server/src/com/vaadin/server/LegacyApplication.java index 54550ce134..44649067c5 100644 --- a/server/src/com/vaadin/server/LegacyApplication.java +++ b/server/src/com/vaadin/server/LegacyApplication.java @@ -64,7 +64,7 @@ public abstract class LegacyApplication implements ErrorHandler { if (this.mainWindow != null) { throw new IllegalStateException("mainWindow has already been set"); } - if (mainWindow.getSession() != null) { + if (mainWindow.isAttached()) { throw new IllegalStateException( "mainWindow is attached to another application"); } diff --git a/server/src/com/vaadin/ui/LegacyWindow.java b/server/src/com/vaadin/ui/LegacyWindow.java index 1b66b608c1..458b09390d 100644 --- a/server/src/com/vaadin/ui/LegacyWindow.java +++ b/server/src/com/vaadin/ui/LegacyWindow.java @@ -125,7 +125,7 @@ public class LegacyWindow extends UI { public void setName(String name) { this.name = name; // The name can not be changed in application - if (getSession() != null) { + if (isAttached()) { throw new IllegalStateException( "Window name can not be changed while " + "the window is in application"); diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 234a309c06..bbc1d0cd33 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -419,7 +419,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements throw new NullPointerException("Argument must not be null"); } - if (window.getUI() != null && window.getUI().getSession() != null) { + if (window.isAttached()) { throw new IllegalArgumentException( "Window is already attached to an application."); } diff --git a/server/src/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java b/server/src/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java index 2902585f56..de8c5db195 100644 --- a/server/src/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java +++ b/server/src/com/vaadin/ui/components/colorpicker/ColorPickerHistory.java @@ -95,7 +95,7 @@ public class ColorPickerHistory extends CustomComponent implements @SuppressWarnings("unchecked") private ArrayBlockingQueue getColorHistory() { - if (getSession() != null) { + if (isAttached()) { Object colorHistory = getSession().getAttribute( "colorPickerHistory"); if (colorHistory instanceof ArrayBlockingQueue) {