Recommitting r4292 after making it Java 1.5 compatible.
Patch by: jlabanca
Review by: ecc
git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4296 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..55baec4 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,18 @@
return focusablePanel;
}
+ public boolean getWordWrap() {
+ if (hasWordWrap()) {
+ return ((HasWordWrap) focusablePanel.getWidget()).getWordWrap();
+ }
+ throw new UnsupportedOperationException(
+ "Widget does not implement HasWordWrap");
+ }
+
+ public boolean hasWordWrap() {
+ return focusablePanel.getWidget() instanceof HasWordWrap;
+ }
+
public boolean isEnabled() {
return enabled;
}
@@ -148,6 +166,15 @@
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
+
+ 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";
@@ -347,12 +374,14 @@
* you need to access to the individual tabs, add a click handler to each
* {@link Tab} element instead.
*/
+ @Deprecated
public void onClick(Widget sender) {
}
/**
* @deprecated add a key down handler to the individual tab wrappers instead.
*/
+ @Deprecated
public void onKeyDown(Widget sender, char keyCode, int modifiers) {
}
@@ -361,6 +390,7 @@
* if what you wanted to do was to listen to key press events on tabs, add the
* key press handler to the individual tab wrappers instead.
*/
+ @Deprecated
public void onKeyPress(Widget sender, char keyCode, int modifiers) {
}
@@ -370,6 +400,7 @@
* key up handler to the individual tab wrappers instead.
*
*/
+ @Deprecated
public void onKeyUp(Widget sender, char keyCode, int modifiers) {
}
@@ -455,7 +486,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 +504,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() {