summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Alhroos <john.ahlroos@itmill.com>2010-09-21 07:43:16 +0000
committerJohn Alhroos <john.ahlroos@itmill.com>2010-09-21 07:43:16 +0000
commite0a85e864db84846bc6e25615d2ef22892cb6e05 (patch)
tree7db5c1c7b3439ac1815283c415d85463be1030cc
parentf82b43282e1a08783bef1ddf6a7123d7223d3e15 (diff)
downloadvaadin-framework-e0a85e864db84846bc6e25615d2ef22892cb6e05.tar.gz
vaadin-framework-e0a85e864db84846bc6e25615d2ef22892cb6e05.zip
Fixes component attach/detach events to trigger at the right times #5625
svn changeset:15091/svn branch:6.4
-rw-r--r--src/com/vaadin/ui/AbsoluteLayout.java16
-rw-r--r--src/com/vaadin/ui/AbstractOrderedLayout.java31
-rw-r--r--src/com/vaadin/ui/GridLayout.java18
3 files changed, 47 insertions, 18 deletions
diff --git a/src/com/vaadin/ui/AbsoluteLayout.java b/src/com/vaadin/ui/AbsoluteLayout.java
index 02b184e104..15ef32d4a4 100644
--- a/src/com/vaadin/ui/AbsoluteLayout.java
+++ b/src/com/vaadin/ui/AbsoluteLayout.java
@@ -1,4 +1,4 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.vaadin.ui;
@@ -71,8 +71,13 @@ public class AbsoluteLayout extends AbstractLayout {
@Override
public void addComponent(Component c) {
components.add(c);
- super.addComponent(c);
- requestRepaint();
+ try {
+ super.addComponent(c);
+ requestRepaint();
+ } catch (IllegalArgumentException e) {
+ components.remove(c);
+ throw e;
+ }
}
/*
@@ -85,6 +90,7 @@ public class AbsoluteLayout extends AbstractLayout {
@Override
public void removeComponent(Component c) {
components.remove(c);
+ componentToCoordinates.remove(c);
super.removeComponent(c);
requestRepaint();
}
@@ -119,7 +125,9 @@ public class AbsoluteLayout extends AbstractLayout {
* layout.
*/
public ComponentPosition getPosition(Component component) {
- if (componentToCoordinates.containsKey(component)) {
+ if (component.getParent() != this) {
+ return null;
+ } else if (componentToCoordinates.containsKey(component)) {
return componentToCoordinates.get(component);
} else {
ComponentPosition coords = new ComponentPosition();
diff --git a/src/com/vaadin/ui/AbstractOrderedLayout.java b/src/com/vaadin/ui/AbstractOrderedLayout.java
index 89b72b0f88..b0587f8d38 100644
--- a/src/com/vaadin/ui/AbstractOrderedLayout.java
+++ b/src/com/vaadin/ui/AbstractOrderedLayout.java
@@ -1,4 +1,4 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
@@ -53,9 +53,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
*/
@Override
public void addComponent(Component c) {
- super.addComponent(c);
components.add(c);
- requestRepaint();
+ try {
+ super.addComponent(c);
+ requestRepaint();
+ } catch (IllegalArgumentException e) {
+ components.remove(c);
+ throw e;
+ }
}
/**
@@ -66,9 +71,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
* the component to be added.
*/
public void addComponentAsFirst(Component c) {
- super.addComponent(c);
components.addFirst(c);
- requestRepaint();
+ try {
+ super.addComponent(c);
+ requestRepaint();
+ } catch (IllegalArgumentException e) {
+ components.remove(c);
+ throw e;
+ }
}
/**
@@ -81,9 +91,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
* in and after the position are shifted forwards.
*/
public void addComponent(Component c, int index) {
- super.addComponent(c);
components.add(index, c);
- requestRepaint();
+ try {
+ super.addComponent(c);
+ requestRepaint();
+ } catch (IllegalArgumentException e) {
+ components.remove(c);
+ throw e;
+ }
}
/**
@@ -94,10 +109,10 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
*/
@Override
public void removeComponent(Component c) {
- super.removeComponent(c);
components.remove(c);
componentToAlignment.remove(c);
componentToExpandRatio.remove(c);
+ super.removeComponent(c);
requestRepaint();
}
diff --git a/src/com/vaadin/ui/GridLayout.java b/src/com/vaadin/ui/GridLayout.java
index 51610912d1..9b37065712 100644
--- a/src/com/vaadin/ui/GridLayout.java
+++ b/src/com/vaadin/ui/GridLayout.java
@@ -1,4 +1,4 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
@@ -185,9 +185,6 @@ public class GridLayout extends AbstractLayout implements
// Checks that newItem does not overlap with existing items
checkExistingOverlaps(area);
- // first attemt to add to super
- super.addComponent(component);
-
// Inserts the component to right place at the list
// Respect top-down, left-right ordering
// component.setParent(this);
@@ -209,6 +206,15 @@ public class GridLayout extends AbstractLayout implements
components.addLast(component);
}
+ // Attempt to add to super
+ try {
+ super.addComponent(component);
+ } catch (IllegalArgumentException e) {
+ areas.remove(area);
+ components.remove(component);
+ throw e;
+ }
+
// update cursor position, if it's within this area; use first position
// outside this area, even if it's occupied
if (cursorX >= column1 && cursorX <= column2 && cursorY >= row1
@@ -341,8 +347,6 @@ public class GridLayout extends AbstractLayout implements
return;
}
- super.removeComponent(component);
-
Area area = null;
for (final Iterator i = areas.iterator(); area == null && i.hasNext();) {
final Area a = (Area) i.next();
@@ -358,6 +362,8 @@ public class GridLayout extends AbstractLayout implements
componentToAlignment.remove(component);
+ super.removeComponent(component);
+
requestRepaint();
}