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())
}
// Send detach event if the component have been connected to a window
- if (getSession() != null) {
+ if (isAttached()) {
detach();
}
this.parent = parent;
// Send attach event if connected to an application
- if (getSession() != null) {
+ if (isAttached()) {
attach();
}
}
return parent;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.server.ClientConnector#isAttached()
+ */
+ @Override
+ public boolean isAttached() {
+ return getSession() != null;
+ }
+
@Override
public void attach() {
markAsDirty();
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).
* <p>
* 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.
* </p>
*
* <p>
public void attach();
/**
- * Notifies the connector that it is detached from the application.
+ * Notifies the connector that it is detached from its VaadinSession.
*
* <p>
* 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.
+ *
* </p>
*/
public void detach();
@Override
public void removeDetachListener(DetachListener listener) {
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.server.ClientConnector#isAttached()
+ */
+ @Override
+ public boolean isAttached() {
+ return true;
+ }
}
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");
}
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");
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.");
}
@SuppressWarnings("unchecked")
private ArrayBlockingQueue<Color> getColorHistory() {
- if (getSession() != null) {
+ if (isAttached()) {
Object colorHistory = getSession().getAttribute(
"colorPickerHistory");
if (colorHistory instanceof ArrayBlockingQueue<?>) {