From fb791dafcf7d2e128610590628a0af23fb653b9d Mon Sep 17 00:00:00 2001 From: Fabian Peters Date: Fri, 6 Nov 2015 13:14:42 +0100 Subject: [PATCH] Use the tab name instead of the tab index to determine the current tab. This ensures the current tab will be kept active when a switch from e.g. inspect to edit causes the number of tabs or their order to change. If the current tab is no longer available, fall back to the first tab. Implement equals() with comparising limited to the name, as the default will only compare memory addresses, resulting in false negatives. --- .../er/directtoweb/ERD2WContainer.java | 23 +++++++++++++++++++ .../er/directtoweb/pages/ERD2WPage.java | 18 ++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/ERD2WContainer.java b/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/ERD2WContainer.java index 1222a44673c..6f99f6c658c 100644 --- a/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/ERD2WContainer.java +++ b/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/ERD2WContainer.java @@ -50,4 +50,27 @@ public String toString() { sb.append(keys); return sb.toString(); } + + public boolean equals(Object something) { + boolean equals = true; + if (something == null) { + equals = false; + } + if (equals && !getClass().equals(something.getClass())) { + equals = false; + } + if (equals) { + ERD2WContainer other = (ERD2WContainer) something; + // verify name equality + if (name == null && other.name != null) { + equals = false; + } + if (equals && name != null && !name.equals(other.name)) { + equals = false; + } + // we don't verify display name and keys equality + } + return equals; + } + } diff --git a/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/pages/ERD2WPage.java b/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/pages/ERD2WPage.java index eeb763aa93c..161ef751c19 100644 --- a/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/pages/ERD2WPage.java +++ b/Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/pages/ERD2WPage.java @@ -992,14 +992,16 @@ public NSArray sectionsForCurrentTab() { /** Returns the {@link er.directtoweb.ERD2WContainer} defining the current tab. */ public ERD2WContainer currentTab() { - if (_currentTab == null && tabSectionsContents() != null && tabSectionsContents().count() > 0) { - //If firstTab is not null, then try to find the tab named firstTab - Integer tabIndex = (Integer) d2wContext().valueForKey(Keys.tabIndex); - if(tabIndex!=null && tabIndex.intValue() <= tabSectionsContents().count()){ - setCurrentTab(tabSectionsContents().objectAtIndex(tabIndex.intValue())); - } - if(_currentTab==null) - setCurrentTab(tabSectionsContents().objectAtIndex(0)); + String tabName = (String) d2wContext().valueForKey(Keys.tabKey); + if (_currentTab == null && !ERXStringUtilities.stringIsNullOrEmpty(tabName)) { + for (ERD2WContainer aTab : tabSectionsContents()) { + if (tabName.equals(aTab.name)) { + setCurrentTab(aTab); + } + } + } + if (_currentTab == null) { + _currentTab = tabSectionsContents().objectAtIndex(0); } return _currentTab; }