TabBar.setTabText(text) now sets wordWrap to false.  TabBar.Tab now implements HasWordWrap, which allows users to set wordWrap on the underlying widget.  If the underlying widget doesn't implement HasWordWrap, an UnsupportedOperationException is thrown.  Users can check this using TabBar.Tab.hasWordWrap().

Patch by: jlabanca
Review by: ecc
Issue: 2910

git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4292 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/TabBar.java b/user/src/com/google/gwt/user/client/ui/TabBar.java
index 482658b..2350fd8 100644
--- a/user/src/com/google/gwt/user/client/ui/TabBar.java
+++ b/user/src/com/google/gwt/user/client/ui/TabBar.java
@@ -69,7 +69,13 @@
    * Note that this set might expand over time, so implement this interface at
    * your own risk.
    */
-  public interface Tab extends HasAllKeyHandlers, HasClickHandlers {
+  public interface Tab extends HasAllKeyHandlers, HasClickHandlers, HasWordWrap {
+    /**
+     * Check if the underlying widget implements {@link HasWordWrap}.
+     *  
+     * @return true if the widget implements {@link HasWordWrap}
+     */
+    boolean hasWordWrap();
   }
 
   /**
@@ -117,6 +123,20 @@
       return focusablePanel;
     }
 
+    @Override
+    public boolean getWordWrap() {
+      if (hasWordWrap()) {
+        return ((HasWordWrap) focusablePanel.getWidget()).getWordWrap();
+      }
+      throw new UnsupportedOperationException(
+          "Widget does not implement HasWordWrap");
+    }
+
+    @Override
+    public boolean hasWordWrap() {
+      return focusablePanel.getWidget() instanceof HasWordWrap;
+    }
+
     public boolean isEnabled() {
       return enabled;
     }
@@ -148,6 +168,16 @@
     public void setEnabled(boolean enabled) {
       this.enabled = enabled;
     }
+
+    @Override
+    public void setWordWrap(boolean wrap) {
+      if (hasWordWrap()) {
+        ((HasWordWrap) focusablePanel.getWidget()).setWordWrap(wrap);
+      } else {
+        throw new UnsupportedOperationException(
+            "Widget does not implement HasWordWrap");
+      }
+    }
   }
 
   private static final String STYLENAME_DEFAULT = "gwt-TabBarItem";
@@ -455,7 +485,7 @@
 
     ClickDelegatePanel delPanel = (ClickDelegatePanel) panel.getWidget(index + 1);
     SimplePanel focusablePanel = delPanel.getFocusablePanel();
-    focusablePanel.setWidget(new HTML(html));
+    focusablePanel.setWidget(new HTML(html, false));
   }
 
   /**
@@ -473,7 +503,7 @@
     // It is not safe to check if the current widget is an instanceof Label and
     // reuse it here because HTML is an instanceof Label. Leaving an HTML would
     // throw off the results of getTabHTML(int).
-    focusablePanel.setWidget(new Label(text));
+    focusablePanel.setWidget(new Label(text, false));
   }
 
   /**
diff --git a/user/test/com/google/gwt/user/client/ui/TabBarTest.java b/user/test/com/google/gwt/user/client/ui/TabBarTest.java
index 0c4bed9..3909bcc 100644
--- a/user/test/com/google/gwt/user/client/ui/TabBarTest.java
+++ b/user/test/com/google/gwt/user/client/ui/TabBarTest.java
@@ -162,6 +162,71 @@
   }
 
   /**
+   * Verify that wordWrap works when adding widgets that implement HasWordWrap.
+   */
+  public void testWordWrapWithSupport() {
+    TabBar bar = createTabBar();
+    Label tabContent0 = new Label("Tab 0", false);
+    Label tabContent1 = new Label("Tab 1", true);
+    bar.addTab(tabContent0);
+    bar.addTab(tabContent1);
+    bar.addTab("Tab 2");
+
+    // hasWordWrap()
+    {
+      assertTrue(bar.getTab(0).hasWordWrap());
+      assertTrue(bar.getTab(1).hasWordWrap());
+      assertTrue(bar.getTab(2).hasWordWrap());
+    }
+
+    // getWordWrap()
+    {
+      assertFalse(bar.getTab(0).getWordWrap());
+      assertTrue(bar.getTab(1).getWordWrap());
+      assertFalse(bar.getTab(2).getWordWrap());
+    }
+
+    // setWordWrap()
+    {
+      bar.getTab(0).setWordWrap(true);
+      bar.getTab(1).setWordWrap(true);
+      bar.getTab(2).setWordWrap(true);
+      assertTrue(bar.getTab(0).getWordWrap());
+      assertTrue(bar.getTab(1).getWordWrap());
+      assertTrue(bar.getTab(2).getWordWrap());
+      assertTrue(tabContent0.getWordWrap());
+    }
+  }
+
+  /**
+   * Verify that wordWrap works when adding widgets that do not implement
+   * HasWordWrap.
+   */
+  public void testWordWrapWithoutSupport() {
+    TabBar bar = createTabBar();
+    bar.addTab(new Button("Tab 0"));
+
+    // hasWordWrap
+    assertFalse(bar.getTab(0).hasWordWrap());
+
+    // getWordWrap();
+    try {
+      bar.getTab(0).getWordWrap();
+      fail("Expected UnsupportedOperationException");
+    } catch (UnsupportedOperationException e) {
+      assertTrue(true);
+    }
+
+    // setWordWrap();
+    try {
+      bar.getTab(0).setWordWrap(true);
+      fail("Expected UnsupportedOperationException");
+    } catch (UnsupportedOperationException e) {
+      assertTrue(true);
+    }
+  }
+
+  /**
    * Create a new, empty tab bar.
    */
   protected TabBar createTabBar() {