]> source.dussan.org Git - vaadin-framework.git/commitdiff
Implement HasComponents directly in PopupView (#10238) 19/319/1
authorHenri Sara <hesara@vaadin.com>
Wed, 21 Nov 2012 12:05:51 +0000 (14:05 +0200)
committerHenri Sara <hesara@vaadin.com>
Wed, 21 Nov 2012 12:05:51 +0000 (14:05 +0200)
Change-Id: If0bd9d3cf92c4f040e63f693da214aacac421168

client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java
server/src/com/vaadin/ui/PopupView.java

index 7fdd986d93c986f4bb84416ce1e8b22c99771455..d4567c19f2a1b8b704b5cd48750a1de00a1a3220 100644 (file)
@@ -24,7 +24,7 @@ import com.vaadin.client.ConnectorHierarchyChangeEvent;
 import com.vaadin.client.VCaption;
 import com.vaadin.client.VCaptionWrapper;
 import com.vaadin.client.communication.StateChangeEvent;
-import com.vaadin.client.ui.AbstractComponentContainerConnector;
+import com.vaadin.client.ui.AbstractHasComponentsConnector;
 import com.vaadin.client.ui.PostLayoutListener;
 import com.vaadin.client.ui.VPopupView;
 import com.vaadin.shared.ui.ComponentStateUtil;
@@ -34,7 +34,7 @@ import com.vaadin.shared.ui.popupview.PopupViewState;
 import com.vaadin.ui.PopupView;
 
 @Connect(PopupView.class)
-public class PopupViewConnector extends AbstractComponentContainerConnector
+public class PopupViewConnector extends AbstractHasComponentsConnector
         implements PostLayoutListener, VisibilityChangeHandler {
 
     private boolean centerAfterLayout = false;
index b6d5012e2030cc2df1d60d36caf9e3576d8c8526..843f306d2a329984df5901c7cddd12f09377b1e7 100644 (file)
@@ -17,6 +17,7 @@ package com.vaadin.ui;
 
 import java.io.Serializable;
 import java.lang.reflect.Method;
+import java.util.Collections;
 import java.util.Iterator;
 
 import com.vaadin.shared.ui.popupview.PopupViewServerRpc;
@@ -32,7 +33,7 @@ import com.vaadin.shared.ui.popupview.PopupViewState;
  * @author Vaadin Ltd.
  */
 @SuppressWarnings("serial")
-public class PopupView extends AbstractComponentContainer {
+public class PopupView extends AbstractComponent implements HasComponents {
 
     private Content content;
     private Component visibleComponent;
@@ -58,42 +59,6 @@ public class PopupView extends AbstractComponentContainer {
         }
     };
 
-    /**
-     * Iterator for the visible components (zero or one components), used by
-     * {@link PopupView#getComponentIterator()}.
-     */
-    private static class SingleComponentIterator implements
-            Iterator<Component>, Serializable {
-
-        private final Component component;
-        private boolean first;
-
-        public SingleComponentIterator(Component component) {
-            this.component = component;
-            first = (component == null);
-        }
-
-        @Override
-        public boolean hasNext() {
-            return !first;
-        }
-
-        @Override
-        public Component next() {
-            if (!first) {
-                first = true;
-                return component;
-            } else {
-                return null;
-            }
-        }
-
-        @Override
-        public void remove() {
-            throw new UnsupportedOperationException();
-        }
-    }
-
     /* Constructors */
 
     /**
@@ -177,9 +142,16 @@ public class PopupView extends AbstractComponentContainer {
                     throw new java.lang.IllegalStateException(
                             "PopupView.Content did not return Component to set visible");
                 }
-                super.addComponent(visibleComponent);
+                if (visibleComponent.getParent() != null) {
+                    // If the component already has a parent, try to remove it
+                    AbstractSingleComponentContainer
+                            .removeFromParent(visibleComponent);
+                }
+                visibleComponent.setParent(this);
             } else {
-                super.removeComponent(visibleComponent);
+                if (visibleComponent.getParent() == this) {
+                    visibleComponent.setParent(null);
+                }
                 visibleComponent = null;
             }
             fireEvent(new PopupVisibilityEvent(this));
@@ -240,7 +212,11 @@ public class PopupView extends AbstractComponentContainer {
      */
     @Override
     public Iterator<Component> iterator() {
-        return new SingleComponentIterator(visibleComponent);
+        if (content != null) {
+            return Collections.singletonList(visibleComponent).iterator();
+        } else {
+            return Collections.<Component> emptyList().iterator();
+        }
     }
 
     /**
@@ -249,73 +225,10 @@ public class PopupView extends AbstractComponentContainer {
      * 
      * @return the number of contained components (zero or one)
      */
-    @Override
     public int getComponentCount() {
         return (visibleComponent != null ? 1 : 0);
     }
 
-    /**
-     * Not supported in this implementation.
-     * 
-     * @see com.vaadin.ui.AbstractComponentContainer#removeAllComponents()
-     * @throws UnsupportedOperationException
-     */
-    @Override
-    public void removeAllComponents() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Not supported in this implementation.
-     * 
-     * @see com.vaadin.ui.AbstractComponentContainer#moveComponentsFrom(com.vaadin.ui.ComponentContainer)
-     * @throws UnsupportedOperationException
-     */
-    @Override
-    public void moveComponentsFrom(ComponentContainer source)
-            throws UnsupportedOperationException {
-
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Not supported in this implementation.
-     * 
-     * @see com.vaadin.ui.AbstractComponentContainer#addComponent(com.vaadin.ui.Component)
-     * @throws UnsupportedOperationException
-     */
-    @Override
-    public void addComponent(Component c) throws UnsupportedOperationException {
-        throw new UnsupportedOperationException();
-
-    }
-
-    /**
-     * Not supported in this implementation.
-     * 
-     * @see com.vaadin.ui.ComponentContainer#replaceComponent(com.vaadin.ui.Component,
-     *      com.vaadin.ui.Component)
-     * @throws UnsupportedOperationException
-     */
-    @Override
-    public void replaceComponent(Component oldComponent, Component newComponent)
-            throws UnsupportedOperationException {
-
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Not supported in this implementation
-     * 
-     * @see com.vaadin.ui.AbstractComponentContainer#removeComponent(com.vaadin.ui.Component)
-     */
-    @Override
-    public void removeComponent(Component c)
-            throws UnsupportedOperationException {
-        throw new UnsupportedOperationException();
-
-    }
-
     @Override
     protected PopupViewState getState() {
         return (PopupViewState) super.getState();