Author: [EMAIL PROTECTED]
Date: Mon Sep 22 09:15:18 2008
New Revision: 3671
Modified:
trunk/user/src/com/google/gwt/user/client/ui/TabBar.java
trunk/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome.css
trunk/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome_rtl.css
trunk/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark.css
trunk/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark_rtl.css
trunk/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard.css
trunk/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard_rtl.css
trunk/user/test/com/google/gwt/user/client/ui/TabBarTest.java
Log:
Added TabBar.setTabEnabled() option to disable tabs in a TabBar.
Patch by: jlabanca
Review by: ecc
Issue: 2527
Modified: trunk/user/src/com/google/gwt/user/client/ui/TabBar.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/TabBar.java (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/TabBar.java Mon Sep 22
09:15:18 2008
@@ -39,6 +39,10 @@
* tabs } </li>
* <li>.gwt-TabBar .gwt-TabBarItem-wrapper-selected { table cell around
* selected tab }</li>
+ * <li>.gwt-TabBar .gwt-TabBarItem-disabled { additional style for disabled
+ * tabs } </li>
+ * <li>.gwt-TabBar .gwt-TabBarItem-wrapper-disabled { table cell around
+ * disabled tab }</li>
* </ul>
* <p>
* <h3>Example</h3>
@@ -57,6 +61,7 @@
private SimplePanel focusablePanel;
private ClickListener clickDelegate;
private KeyboardListener keyDelegate;
+ private boolean enabled = true;
ClickDelegatePanel(Widget child, ClickListener cDelegate,
KeyboardListener kDelegate) {
@@ -80,8 +85,16 @@
return focusablePanel;
}
+ public boolean isEnabled() {
+ return enabled;
+ }
+
@Override
public void onBrowserEvent(Event event) {
+ if (!enabled) {
+ return;
+ }
+
// No need for call to super.
switch (DOM.eventGetType(event)) {
@@ -95,6 +108,10 @@
break;
}
}
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
}
private static final String STYLENAME_DEFAULT = "gwt-TabBarItem";
@@ -252,6 +269,19 @@
insertTabWidget(widget, beforeIndex);
}
+ /**
+ * Check if a tab is enabled or disabled. If disabled, the user cannot
+ * select the tab.
+ *
+ * @param index the index of the tab
+ * @return true if the tab is enabled, false if disabled
+ */
+ public boolean isTabEnabled(int index) {
+ assert (index >= 0) && (index < getTabCount()) : "Tab index out of
bounds";
+ ClickDelegatePanel delPanel = (ClickDelegatePanel)
panel.getWidget(index + 1);
+ return delPanel.isEnabled();
+ }
+
public void onClick(Widget sender) {
selectTabByTabWidget(sender);
}
@@ -321,6 +351,23 @@
tabListeners.fireTabSelected(this, index);
}
return true;
+ }
+
+ /**
+ * Enable or disable a tab. When disabled, users cannot select the tab.
+ *
+ * @param index the index of the tab to enable or disable
+ * @param enabled true to enable, false to disable
+ */
+ public void setTabEnabled(int index, boolean enabled) {
+ assert (index >= 0) && (index < getTabCount()) : "Tab index out of
bounds";
+
+ // Style the wrapper
+ ClickDelegatePanel delPanel = (ClickDelegatePanel)
panel.getWidget(index + 1);
+ delPanel.setEnabled(enabled);
+
setStyleName(delPanel.getElement(), "gwt-TabBarItem-disabled", !enabled);
+ setStyleName(delPanel.getElement().getParentElement(),
+ "gwt-TabBarItem-wrapper-disabled", !enabled);
}
/**
Modified:
trunk/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome.css
==============================================================================
---
trunk/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome.css
(original)
+++
trunk/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome.css
Mon Sep 22 09:15:18 2008
@@ -881,6 +881,10 @@
cursor: default;
background: #bcbcbc;
}
+.gwt-TabBar .gwt-TabBarItem-disabled {
+ cursor: default;
+ color: #999999;
+}
.gwt-TabPanel {
}
.gwt-TabPanelBottom {
@@ -989,6 +993,10 @@
cursor: default;
background: #bcbcbc url(images/hborder.png) repeat-x 0px -2511px;
color: white;
+}
+.gwt-DecoratedTabBar .gwt-TabBarItem-disabled .tabMiddleCenter {
+ cursor: default;
+ color: #999999;
}
.gwt-TextArea {
Modified:
trunk/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome_rtl.css
==============================================================================
---
trunk/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome_rtl.css
(original)
+++
trunk/user/src/com/google/gwt/user/theme/chrome/public/gwt/chrome/chrome_rtl.css
Mon Sep 22 09:15:18 2008
@@ -881,6 +881,10 @@
cursor: default;
background: #bcbcbc;
}
+.gwt-TabBar .gwt-TabBarItem-disabled {
+ cursor: default;
+ color: #999999;
+}
.gwt-TabPanel {
}
.gwt-TabPanelBottom {
@@ -989,6 +993,10 @@
cursor: default;
background: #bcbcbc url(images/hborder.png) repeat-x 0px -2511px;
color: white;
+}
+.gwt-DecoratedTabBar .gwt-TabBarItem-disabled .tabMiddleCenter {
+ cursor: default;
+ color: #999999;
}
.gwt-TextArea {
Modified:
trunk/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark.css
==============================================================================
--- trunk/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark.css
(original)
+++ trunk/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark.css
Mon Sep 22 09:15:18 2008
@@ -783,6 +783,10 @@
color: black;
background: #00CCFF;
}
+.gwt-TabBar .gwt-TabBarItem-disabled {
+ cursor: default;
+ color: #777777;
+}
.gwt-TabPanel {
}
.gwt-TabPanelBottom {
@@ -890,6 +894,10 @@
cursor: default;
color: black;
background: #00CCFF;
+}
+.gwt-DecoratedTabBar .gwt-TabBarItem-disabled .tabMiddleCenter {
+ cursor: default;
+ color: #777777;
}
.gwt-TextArea {
Modified:
trunk/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark_rtl.css
==============================================================================
---
trunk/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark_rtl.css
(original)
+++
trunk/user/src/com/google/gwt/user/theme/dark/public/gwt/dark/dark_rtl.css
Mon Sep 22 09:15:18 2008
@@ -783,6 +783,10 @@
color: black;
background: #00CCFF;
}
+.gwt-TabBar .gwt-TabBarItem-disabled {
+ cursor: default;
+ color: #777777;
+}
.gwt-TabPanel {
}
.gwt-TabPanelBottom {
@@ -890,6 +894,10 @@
cursor: default;
color: black;
background: #00CCFF;
+}
+.gwt-DecoratedTabBar .gwt-TabBarItem-disabled .tabMiddleCenter {
+ cursor: default;
+ color: #777777;
}
.gwt-TextArea {
Modified:
trunk/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard.css
==============================================================================
---
trunk/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard.css
(original)
+++
trunk/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard.css
Mon Sep 22 09:15:18 2008
@@ -881,6 +881,10 @@
cursor: default;
background: #92c1f0;
}
+.gwt-TabBar .gwt-TabBarItem-disabled {
+ cursor: default;
+ color: #999999;
+}
.gwt-TabPanel {
}
.gwt-TabPanelBottom {
@@ -988,6 +992,10 @@
.gwt-DecoratedTabBar .gwt-TabBarItem-selected .tabMiddleCenter {
cursor: default;
background: #92c1f0;
+}
+.gwt-DecoratedTabBar .gwt-TabBarItem-disabled .tabMiddleCenter {
+ cursor: default;
+ color: #999999;
}
.gwt-TextArea {
Modified:
trunk/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard_rtl.css
==============================================================================
---
trunk/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard_rtl.css
(original)
+++
trunk/user/src/com/google/gwt/user/theme/standard/public/gwt/standard/standard_rtl.css
Mon Sep 22 09:15:18 2008
@@ -881,6 +881,10 @@
cursor: default;
background: #92c1f0;
}
+.gwt-TabBar .gwt-TabBarItem-disabled {
+ cursor: default;
+ color: #999999;
+}
.gwt-TabPanel {
}
.gwt-TabPanelBottom {
@@ -988,6 +992,10 @@
.gwt-DecoratedTabBar .gwt-TabBarItem-selected .tabMiddleCenter {
cursor: default;
background: #92c1f0;
+}
+.gwt-DecoratedTabBar .gwt-TabBarItem-disabled .tabMiddleCenter {
+ cursor: default;
+ color: #999999;
}
.gwt-TextArea {
Modified: trunk/user/test/com/google/gwt/user/client/ui/TabBarTest.java
==============================================================================
--- trunk/user/test/com/google/gwt/user/client/ui/TabBarTest.java
(original)
+++ trunk/user/test/com/google/gwt/user/client/ui/TabBarTest.java Mon Sep
22 09:15:18 2008
@@ -54,6 +54,19 @@
UIObjectTest.assertDebugId("myBar-tab-wrapper2", DOM.getChild(tr, 3));
}
+ public void testEnableDisable() {
+ final TabBar bar = createTabBar();
+ bar.addTab("foo");
+ bar.addTab("bar");
+ bar.addTab("baz");
+
+ assertTrue(bar.isTabEnabled(1));
+ bar.setTabEnabled(1, false);
+ assertFalse(bar.isTabEnabled(1));
+ bar.setTabEnabled(1, true);
+ assertTrue(bar.isTabEnabled(1));
+ }
+
public void testSelect() {
// Create a tab bar with three items.
final TabBar bar = createTabBar();
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---