private ArrayList<Extension> extensions = new ArrayList<Extension>();
- private ClientConnector parent;
-
/**
* The EventRouter used for the event model.
*/
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)
*
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
Class<? extends ClientConnector> supportedParentType = getSupportedParentType();
if (parent == null || supportedParentType.isInstance(parent)) {
- super.setParent(parent);
+ internalSetParent(parent);
previouslyAttached = true;
} else {
throw new IllegalArgumentException(getClass().getName()
}
}
+ /**
+ * 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;
+ }
+
}
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;
*/
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.
*
}
- @Override
- public void setParent(ClientConnector parent) {
- // TODO Auto-generated method stub
-
- }
-
@Override
public void attach() {
// TODO Auto-generated method stub
* 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);
+
}
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;
private boolean visible = true;
+ private HasComponents parent;
+
/* Constructor */
/**
*/
@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();
}
}
*/
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.
*
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;
* )
*/
@Override
- public void setParent(ClientConnector parent) {
+ public void setParent(HasComponents parent) {
if (parent == null || parent instanceof UI) {
super.setParent(parent);
} else {