aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2012-11-21 13:58:29 +0200
committerHenri Sara <hesara@vaadin.com>2012-11-21 13:59:12 +0200
commit30c3c87e294f09318b5aecaeb2944a0601988c2b (patch)
tree0dbbf9169163e0f4083fa3df06c7f647abdcb57e
parent416b8a6d6b9eb580454f006b38a72ffe7f484638 (diff)
downloadvaadin-framework-30c3c87e294f09318b5aecaeb2944a0601988c2b.tar.gz
vaadin-framework-30c3c87e294f09318b5aecaeb2944a0601988c2b.zip
Implement HasComponents directly in CustomComponent (#10235)
Change-Id: Ic39a14e8239e921a85437cfad67eac149b41a8d3
-rw-r--r--client/src/com/vaadin/client/ui/customcomponent/CustomComponentConnector.java5
-rw-r--r--server/src/com/vaadin/ui/CustomComponent.java96
-rw-r--r--uitest/src/com/vaadin/tests/dd/DragDropPane.java1
3 files changed, 17 insertions, 85 deletions
diff --git a/client/src/com/vaadin/client/ui/customcomponent/CustomComponentConnector.java b/client/src/com/vaadin/client/ui/customcomponent/CustomComponentConnector.java
index 7a7a7c3456..7543f3b428 100644
--- a/client/src/com/vaadin/client/ui/customcomponent/CustomComponentConnector.java
+++ b/client/src/com/vaadin/client/ui/customcomponent/CustomComponentConnector.java
@@ -17,15 +17,14 @@ package com.vaadin.client.ui.customcomponent;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
-import com.vaadin.client.ui.AbstractComponentContainerConnector;
+import com.vaadin.client.ui.AbstractHasComponentsConnector;
import com.vaadin.client.ui.VCustomComponent;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.Connect.LoadStyle;
import com.vaadin.ui.CustomComponent;
@Connect(value = CustomComponent.class, loadStyle = LoadStyle.EAGER)
-public class CustomComponentConnector extends
- AbstractComponentContainerConnector {
+public class CustomComponentConnector extends AbstractHasComponentsConnector {
@Override
public VCustomComponent getWidget() {
diff --git a/server/src/com/vaadin/ui/CustomComponent.java b/server/src/com/vaadin/ui/CustomComponent.java
index d3d5bb43b0..11cd1cd9eb 100644
--- a/server/src/com/vaadin/ui/CustomComponent.java
+++ b/server/src/com/vaadin/ui/CustomComponent.java
@@ -16,7 +16,7 @@
package com.vaadin.ui;
-import java.io.Serializable;
+import java.util.Collections;
import java.util.Iterator;
/**
@@ -32,7 +32,7 @@ import java.util.Iterator;
* @since 3.0
*/
@SuppressWarnings("serial")
-public class CustomComponent extends AbstractComponentContainer {
+public class CustomComponent extends AbstractComponent implements HasComponents {
/**
* The root component implementing the custom component.
@@ -91,13 +91,18 @@ public class CustomComponent extends AbstractComponentContainer {
*/
protected void setCompositionRoot(Component compositionRoot) {
if (compositionRoot != root) {
- if (root != null) {
+ if (root != null && root.getParent() == this) {
// remove old component
- super.removeComponent(root);
+ root.setParent(null);
}
if (compositionRoot != null) {
// set new component
- super.addComponent(compositionRoot);
+ if (compositionRoot.getParent() != null) {
+ // If the component already has a parent, try to remove it
+ AbstractSingleComponentContainer
+ .removeFromParent(compositionRoot);
+ }
+ compositionRoot.setParent(this);
}
root = compositionRoot;
markAsDirty();
@@ -106,30 +111,13 @@ public class CustomComponent extends AbstractComponentContainer {
/* Basic component features ------------------------------------------ */
- private class ComponentIterator implements Iterator<Component>,
- Serializable {
- boolean first = getCompositionRoot() != null;
-
- @Override
- public boolean hasNext() {
- return first;
- }
-
- @Override
- public Component next() {
- first = false;
- return root;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
@Override
public Iterator<Component> iterator() {
- return new ComponentIterator();
+ if (getCompositionRoot() != null) {
+ return Collections.singletonList(getCompositionRoot()).iterator();
+ } else {
+ return Collections.<Component> emptyList().iterator();
+ }
}
/**
@@ -138,62 +126,8 @@ public class CustomComponent extends AbstractComponentContainer {
*
* @return the number of contained components (zero or one)
*/
- @Override
public int getComponentCount() {
return (root != null ? 1 : 0);
}
- /**
- * This method is not supported by CustomComponent.
- *
- * @see com.vaadin.ui.ComponentContainer#replaceComponent(com.vaadin.ui.Component,
- * com.vaadin.ui.Component)
- */
- @Override
- public void replaceComponent(Component oldComponent, Component newComponent) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * This method is not supported by CustomComponent. Use
- * {@link CustomComponent#setCompositionRoot(Component)} to set
- * CustomComponents "child".
- *
- * @see com.vaadin.ui.AbstractComponentContainer#addComponent(com.vaadin.ui.Component)
- */
- @Override
- public void addComponent(Component c) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * This method is not supported by CustomComponent.
- *
- * @see com.vaadin.ui.AbstractComponentContainer#moveComponentsFrom(com.vaadin.ui.ComponentContainer)
- */
- @Override
- public void moveComponentsFrom(ComponentContainer source) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * This method is not supported by CustomComponent.
- *
- * @see com.vaadin.ui.AbstractComponentContainer#removeAllComponents()
- */
- @Override
- public void removeAllComponents() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * This method is not supported by CustomComponent.
- *
- * @see com.vaadin.ui.AbstractComponentContainer#removeComponent(com.vaadin.ui.Component)
- */
- @Override
- public void removeComponent(Component c) {
- throw new UnsupportedOperationException();
- }
-
}
diff --git a/uitest/src/com/vaadin/tests/dd/DragDropPane.java b/uitest/src/com/vaadin/tests/dd/DragDropPane.java
index 970e1b0141..6296051ee2 100644
--- a/uitest/src/com/vaadin/tests/dd/DragDropPane.java
+++ b/uitest/src/com/vaadin/tests/dd/DragDropPane.java
@@ -33,7 +33,6 @@ public class DragDropPane extends DragAndDropWrapper implements DropHandler {
setDragStartMode(DragStartMode.COMPONENT);
}
- @Override
public void addComponent(Component c) {
root.addComponent(c);
}