summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-11-21 13:32:15 +0000
committerVaadin Code Review <review@vaadin.com>2012-11-21 13:32:15 +0000
commitf45008647e5fabf1510852eea82cdf325dc6cf1b (patch)
tree38fe376007607e65d40d804a9f70dd31b0913d9f
parent35a12aa1e9da359e2cbec9a15e195c90f0e29d52 (diff)
parentf52babe2f00763d23ec91a2789224e363b2708e0 (diff)
downloadvaadin-framework-f45008647e5fabf1510852eea82cdf325dc6cf1b.tar.gz
vaadin-framework-f45008647e5fabf1510852eea82cdf325dc6cf1b.zip
Merge "Implement HasComponents directly in PopupView (#10238)"
-rw-r--r--client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java4
-rw-r--r--server/src/com/vaadin/ui/PopupView.java119
2 files changed, 18 insertions, 105 deletions
diff --git a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java
index 7fdd986d93..d4567c19f2 100644
--- a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java
+++ b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java
@@ -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;
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();