]> source.dussan.org Git - vaadin-framework.git/commitdiff
Made TabSheet work again and removed TabSheet tab caching for now
authorArtur Signell <artur@vaadin.com>
Tue, 13 Mar 2012 18:39:00 +0000 (20:39 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 14 Mar 2012 14:00:53 +0000 (16:00 +0200)
src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java
src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/ui/AbstractComponent.java
src/com/vaadin/ui/TabSheet.java

index 0c44068cf55d13b910837caf2c72296773dac91e..bca4163185b2e0e764cf1a09124dbe1e6748c6e7 100644 (file)
@@ -9,7 +9,6 @@ import java.util.Iterator;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.ComponentConnector;
-import com.vaadin.terminal.gwt.client.ConnectorMap;
 import com.vaadin.terminal.gwt.client.UIDL;
 
 public abstract class TabsheetBaseConnector extends
@@ -37,7 +36,7 @@ public abstract class TabsheetBaseConnector extends
         // Render content
         final UIDL tabs = uidl.getChildUIDL(0);
 
-        // Paintables in the TabSheet before update
+        // Widgets in the TabSheet before update
         ArrayList<Widget> oldWidgets = new ArrayList<Widget>();
         for (Iterator<Widget> iterator = getWidget().getWidgetIterator(); iterator
                 .hasNext();) {
@@ -75,23 +74,19 @@ public abstract class TabsheetBaseConnector extends
 
         for (int i = 0; i < getWidget().getTabCount(); i++) {
             ComponentConnector p = getWidget().getTab(i);
-            // During the initial rendering the paintable might be null (this is
-            // weird...)
+            // null for PlaceHolder widgets
             if (p != null) {
                 oldWidgets.remove(p.getWidget());
             }
         }
 
-        // Perform unregister for any paintables removed during update
+        // Detach any old tab widget, should be max 1
         for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator
                 .hasNext();) {
             Widget oldWidget = iterator.next();
-            ComponentConnector oldPaintable = ConnectorMap.get(client)
-                    .getConnector(oldWidget);
             if (oldWidget.isAttached()) {
                 oldWidget.removeFromParent();
             }
-            ConnectorMap.get(client).unregisterConnector(oldPaintable);
         }
 
     }
index b30483c2cdb09c4e9ec5a4567f109856fea27bda..67bdddce204c93d29de340d4cdf0c5af2150568f 100644 (file)
@@ -896,9 +896,10 @@ public class VTabsheet extends VTabsheetBase implements Focusable,
 
     private void renderContent(final UIDL contentUIDL) {
         final ComponentConnector content = client.getPaintable(contentUIDL);
+        Widget newWidget = content.getWidget();
         if (tp.getWidgetCount() > activeTabIndex) {
             Widget old = tp.getWidget(activeTabIndex);
-            if (old != content) {
+            if (old != newWidget) {
                 tp.remove(activeTabIndex);
                 ConnectorMap paintableMap = ConnectorMap.get(client);
                 if (paintableMap.isConnector(old)) {
index 615112168b772bf69ac72aaf6df7beee0a12610b..c509cbb33e640a85bdb394ff2ca0f89818d726bf 100644 (file)
@@ -951,8 +951,7 @@ public abstract class AbstractCommunicationManager implements
                     JSONArray children = new JSONArray();
 
                     for (Component child : getChildComponents(parent)) {
-                        if (child.getState().isVisible()
-                                && parent.isComponentVisible(child)) {
+                        if (child.isVisible()) {
                             String childConnectorId = getPaintableId(child);
                             children.put(childConnectorId);
                         }
@@ -962,8 +961,8 @@ public abstract class AbstractCommunicationManager implements
                     } catch (JSONException e) {
                         throw new PaintException(
                                 "Failed to send hierarchy information about "
-                                        + parentConnectorId + " to the client: "
-                                        + e.getMessage());
+                                        + parentConnectorId
+                                        + " to the client: " + e.getMessage());
                     }
                 }
             }
index 5791ff21cd46be52a35c1b9a4b21f8e01dc55a60..b9e8f1836817b03dab37fc6d271ac0874a93afb6 100644 (file)
@@ -409,8 +409,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      * @see com.vaadin.ui.Component#isVisible()
      */
     public boolean isVisible() {
-        return getState().isVisible()
-                && (getParent() == null || getParent().isVisible());
+        if (getParent() == null) {
+            return getState().isVisible();
+        } else {
+            return getState().isVisible() && getParent().isVisible()
+                    && ((HasComponents) getParent()).isComponentVisible(this);
+        }
     }
 
     /*
@@ -1699,4 +1703,9 @@ public abstract class AbstractComponent implements Component, MethodEventSource
             return Collections.unmodifiableList(result);
         }
     }
+
+    public String getConnectorId() {
+        throw new RuntimeException(
+                "TODO: Move connector id handling to AbstractComponent");
+    }
 }
index 96e9feb6d35451da624baf8a463ed63c831c66ca..59f33867320a0e458e0ba45ce776864378c90493 100644 (file)
@@ -7,10 +7,8 @@ package com.vaadin.ui;
 import java.io.Serializable;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -28,7 +26,6 @@ import com.vaadin.terminal.Resource;
 import com.vaadin.terminal.gwt.client.ui.TabsheetBaseConnector;
 import com.vaadin.terminal.gwt.client.ui.TabsheetConnector;
 import com.vaadin.terminal.gwt.client.ui.VTabsheet;
-import com.vaadin.terminal.gwt.server.CommunicationManager;
 import com.vaadin.ui.Component.Focusable;
 import com.vaadin.ui.themes.Reindeer;
 import com.vaadin.ui.themes.Runo;
@@ -94,11 +91,6 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
      */
     private boolean tabsHidden;
 
-    /**
-     * Tabs that have been shown to the user (have been painted as selected).
-     */
-    private HashSet<Component> paintedTabs = new HashSet<Component>();
-
     /**
      * Handler to be called when a tab is closed.
      */
@@ -380,13 +372,9 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
 
         target.startTag("tabs");
 
-        Collection<Component> orphaned = new HashSet<Component>(paintedTabs);
-
         for (final Iterator<Component> i = getComponentIterator(); i.hasNext();) {
             final Component component = i.next();
 
-            orphaned.remove(component);
-
             Tab tab = tabs.get(component);
 
             target.startTag("tab");
@@ -436,17 +424,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
             target.addAttribute("key", keyMapper.key(component));
             if (component.equals(selected)) {
                 target.addAttribute("selected", true);
-                if (!paintedTabs.contains(component)) {
-                    // Ensure the component is painted if it hasn't already been
-                    // painted in this tabsheet
-                    component.requestRepaint();
-                    paintedTabs.add(component);
-                }
                 component.paint(target);
-            } else if (paintedTabs.contains(component)) {
-                component.paint(target);
-            } else {
-                component.requestRepaintRequests();
             }
             target.endTag("tab");
         }
@@ -457,10 +435,6 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
             target.addVariable(this, "selected", keyMapper.key(selected));
         }
 
-        // clean possibly orphaned entries in paintedTabs
-        for (Component component2 : orphaned) {
-            paintedTabs.remove(component2);
-        }
     }
 
     /**
@@ -599,6 +573,15 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
             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();
+            }
         }
     }
 
@@ -880,16 +863,6 @@ public class TabSheet extends AbstractComponentContainer implements Focusable,
         fireEvent(new SelectedTabChangeEvent(this));
     }
 
-    @Override
-    public void removeListener(RepaintRequestListener listener) {
-        super.removeListener(listener);
-        if (listener instanceof CommunicationManager) {
-            // clean the paintedTabs here instead of detach to avoid subtree
-            // caching issues when detached-attached without render
-            paintedTabs.clear();
-        }
-    }
-
     /**
      * Tab meta-data for a component in a {@link TabSheet}.
      *