summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2012-11-21 14:05:51 +0200
committerHenri Sara <hesara@vaadin.com>2012-11-21 14:05:51 +0200
commitf52babe2f00763d23ec91a2789224e363b2708e0 (patch)
tree3c3912f8ba68352818788b67842b58ae5e849e47 /server/src/com/vaadin
parent416b8a6d6b9eb580454f006b38a72ffe7f484638 (diff)
downloadvaadin-framework-f52babe2f00763d23ec91a2789224e363b2708e0.tar.gz
vaadin-framework-f52babe2f00763d23ec91a2789224e363b2708e0.zip
Implement HasComponents directly in PopupView (#10238)
Change-Id: If0bd9d3cf92c4f040e63f693da214aacac421168
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r--server/src/com/vaadin/ui/PopupView.java119
1 files changed, 16 insertions, 103 deletions
diff --git a/server/src/com/vaadin/ui/PopupView.java b/server/src/com/vaadin/ui/PopupView.java
index b6d5012e20..843f306d2a 100644
--- a/server/src/com/vaadin/ui/PopupView.java
+++ b/server/src/com/vaadin/ui/PopupView.java
@@ -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();