]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixes component attach/detach events to trigger at the right times #5625
authorJohn Alhroos <john.ahlroos@itmill.com>
Tue, 21 Sep 2010 07:43:16 +0000 (07:43 +0000)
committerJohn Alhroos <john.ahlroos@itmill.com>
Tue, 21 Sep 2010 07:43:16 +0000 (07:43 +0000)
svn changeset:15091/svn branch:6.4

src/com/vaadin/ui/AbsoluteLayout.java
src/com/vaadin/ui/AbstractOrderedLayout.java
src/com/vaadin/ui/GridLayout.java

index 02b184e1048012c5afcc0092de8edd7ca35d5d43..15ef32d4a4931230c1185c00e2236cfa0ae81fb1 100644 (file)
@@ -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();
index 89b72b0f883b08ca7a821f65aa2553fbdcbf58c5..b0587f8d380a3a8693aff51bdcd23613a73c89b9 100644 (file)
@@ -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();
     }
 
index 51610912d1d112eb95efbf203d4c054e1c7c9687..9b37065712a0cd76835dd0b8b65b020c30d82901 100644 (file)
@@ -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();
     }