]> source.dussan.org Git - vaadin-framework.git/commitdiff
Made TabSheet work again and removed TabSheet tab caching for now
authorArtur Signell <artur@vaadin.com>
Wed, 14 Mar 2012 12:36:19 +0000 (14:36 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 14 Mar 2012 14:01:19 +0000 (16:01 +0200)
(part 2)

src/com/vaadin/ui/TabSheet.java

index 59f33867320a0e458e0ba45ce776864378c90493..d614832cd2fc7442001a0fc0ae44d5af000a12e7 100644 (file)
@@ -152,7 +152,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
             tabs.remove(c);
             if (c.equals(selected)) {
                 if (components.isEmpty()) {
-                    selected = null;
+                    setSelected(null);
                 } else {
                     // select the first enabled and visible tab, if any
                     updateSelection();
@@ -279,7 +279,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
 
             tabs.put(c, tab);
             if (selected == null) {
-                selected = c;
+                setSelected(c);
                 fireSelectedTabChange();
             }
             super.addComponent(c);
@@ -569,22 +569,34 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
      */
     public void setSelectedTab(Component c) {
         if (c != null && components.contains(c) && !c.equals(selected)) {
-            selected = c;
+            setSelected(c);
             updateSelection();
             fireSelectedTabChange();
             requestRepaint();
-            // Repaint of the selected component is needed as only the selected
-            // component is communicated to the client. Otherwise this will be a
-            // "cached" update even though the client knows nothing about the
-            // connector
-            if (selected instanceof ComponentContainer) {
-                ((ComponentContainer) selected).requestRepaintAll();
-            } else {
-                selected.requestRepaint();
-            }
         }
     }
 
+    /**
+     * Sets the selected tab in the TabSheet. Ensures that the selected tab is
+     * repainted if needed.
+     * 
+     * @param c
+     *            The new selection or null for no selection
+     */
+    private void setSelected(Component c) {
+        selected = c;
+        // Repaint of the selected component is needed as only the selected
+        // component is communicated to the client. Otherwise this will be a
+        // "cached" update even though the client knows nothing about the
+        // connector
+        if (selected instanceof ComponentContainer) {
+            ((ComponentContainer) selected).requestRepaintAll();
+        } else if (selected != null) {
+            selected.requestRepaint();
+        }
+
+    }
+
     /**
      * Checks if the current selection is valid, and updates the selection if
      * the previously selected component is not visible and enabled. The first
@@ -619,14 +631,14 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
                 // The current selection is not valid so we need to change
                 // it
                 if (tab.isEnabled() && tab.isVisible()) {
-                    selected = component;
+                    setSelected(component);
                     break;
                 } else {
                     /*
                      * The current selection is not valid but this tab cannot be
                      * selected either.
                      */
-                    selected = null;
+                    setSelected(null);
                 }
             }
         }
@@ -685,7 +697,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
 
         if (selected == oldComponent) {
             // keep selection w/o selectedTabChange event
-            selected = newComponent;
+            setSelected(newComponent);
         }
 
         Tab newTab = tabs.get(newComponent);