summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@itmill.com>2010-05-25 06:39:34 +0000
committerHenri Sara <henri.sara@itmill.com>2010-05-25 06:39:34 +0000
commit06f72ea079f5a91181652b432fd7b10b489d4ca2 (patch)
tree0da26565162d6629925292b32f1725b57b6b8537
parent72f0c03a6ef00ecc7d9852dee210c8543b9c2f6b (diff)
downloadvaadin-framework-06f72ea079f5a91181652b432fd7b10b489d4ca2.tar.gz
vaadin-framework-06f72ea079f5a91181652b432fd7b10b489d4ca2.zip
#3698 and #4505 fire tab change event when current tab gets disabled/hidden/removed
svn changeset:13337/svn branch:6.3
-rw-r--r--src/com/vaadin/ui/TabSheet.java79
1 files changed, 54 insertions, 25 deletions
diff --git a/src/com/vaadin/ui/TabSheet.java b/src/com/vaadin/ui/TabSheet.java
index 77f2653f0a..a69e89ee17 100644
--- a/src/com/vaadin/ui/TabSheet.java
+++ b/src/com/vaadin/ui/TabSheet.java
@@ -101,7 +101,8 @@ public class TabSheet extends AbstractComponentContainer {
if (components.isEmpty()) {
selected = null;
} else {
- selected = components.getFirst();
+ // select the first enabled and visible tab, if any
+ updateSelection();
fireSelectedTabChange();
}
}
@@ -217,30 +218,6 @@ public class TabSheet extends AbstractComponentContainer {
Tab tab = tabs.get(component);
- /*
- * If we have no selection, if the current selection is invisible or
- * if the current selection is disabled (but the whole component is
- * not) we select this tab instead
- */
- Tab selectedTabInfo = null;
- if (selected != null) {
- selectedTabInfo = tabs.get(selected);
- }
- if (selected == null || selectedTabInfo == null
- || !selectedTabInfo.isVisible()
- || !selectedTabInfo.isEnabled()) {
-
- // The current selection is not valid so we need to change it
- if (tab.isEnabled() && tab.isVisible()) {
- selected = component;
- } else {
- /*
- * The current selection is not valid but this tab cannot be
- * selected either.
- */
- selected = null;
- }
- }
target.startTag("tab");
if (!tab.isEnabled() && tab.isVisible()) {
target.addAttribute("disabled", true);
@@ -414,12 +391,58 @@ public class TabSheet extends AbstractComponentContainer {
public void setSelectedTab(Component c) {
if (c != null && components.contains(c) && !c.equals(selected)) {
selected = c;
+ updateSelection();
fireSelectedTabChange();
requestRepaint();
}
}
/**
+ * Checks if the current selection is valid, and updates the selection if
+ * the previously selected component is not visible and enabled.
+ *
+ * This method does not fire tab change events, but the caller should do so
+ * if appropriate.
+ *
+ * @return true if selection was changed, false otherwise
+ */
+ private boolean updateSelection() {
+ Component originalSelection = selected;
+ for (final Iterator<Component> i = getComponentIterator(); i.hasNext();) {
+ final Component component = i.next();
+
+ Tab tab = tabs.get(component);
+
+ /*
+ * If we have no selection, if the current selection is invisible or
+ * if the current selection is disabled (but the whole component is
+ * not) we select this tab instead
+ */
+ Tab selectedTabInfo = null;
+ if (selected != null) {
+ selectedTabInfo = tabs.get(selected);
+ }
+ if (selected == null || selectedTabInfo == null
+ || !selectedTabInfo.isVisible()
+ || !selectedTabInfo.isEnabled()) {
+
+ // The current selection is not valid so we need to change
+ // it
+ if (tab.isEnabled() && tab.isVisible()) {
+ selected = component;
+ } else {
+ /*
+ * The current selection is not valid but this tab cannot be
+ * selected either.
+ */
+ selected = null;
+ }
+ }
+ }
+ return originalSelection != selected;
+ }
+
+ /**
* Gets the selected tab.
*
* @return the selected tab.
@@ -795,6 +818,9 @@ public class TabSheet extends AbstractComponentContainer {
public void setEnabled(boolean enabled) {
this.enabled = enabled;
+ if (updateSelection()) {
+ fireSelectedTabChange();
+ }
requestRepaint();
}
@@ -804,6 +830,9 @@ public class TabSheet extends AbstractComponentContainer {
public void setVisible(boolean visible) {
this.visible = visible;
+ if (updateSelection()) {
+ fireSelectedTabChange();
+ }
requestRepaint();
}