ISIS-993: entity page now remembers the selected tab (in session) on a 
per-object basis


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/d83b2cfe
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/d83b2cfe
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/d83b2cfe

Branch: refs/heads/ISIS-993
Commit: d83b2cfed6e9d437d77e0f4e4edd0a7756509f72
Parents: c3b614c
Author: Dan Haywood <d...@haywood-associates.co.uk>
Authored: Wed Jan 13 09:01:18 2016 +0000
Committer: Dan Haywood <d...@haywood-associates.co.uk>
Committed: Mon Jan 25 14:38:24 2016 +0000

----------------------------------------------------------------------
 .../entity/tabgroups/EntityTabGroupsPanel.java  | 55 +++++++++++++++++++-
 .../dom/simple/SimpleObject.layout.xml          | 22 ++++----
 2 files changed, 64 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/d83b2cfe/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/tabgroups/EntityTabGroupsPanel.java
----------------------------------------------------------------------
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/tabgroups/EntityTabGroupsPanel.java
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/tabgroups/EntityTabGroupsPanel.java
index 6b274a5..671ccd1 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/tabgroups/EntityTabGroupsPanel.java
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/tabgroups/EntityTabGroupsPanel.java
@@ -26,6 +26,7 @@ import com.google.common.collect.Lists;
 
 import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
 import org.apache.wicket.extensions.markup.html.tabs.ITab;
+import org.apache.wicket.extensions.markup.html.tabs.TabbedPanel;
 import org.apache.wicket.markup.html.list.ListItem;
 import org.apache.wicket.markup.html.list.ListView;
 import org.apache.wicket.markup.html.panel.Panel;
@@ -35,8 +36,12 @@ import 
org.apache.isis.applib.layout.v1_0.ObjectLayoutMetadata;
 import org.apache.isis.applib.layout.v1_0.Tab;
 import org.apache.isis.applib.layout.v1_0.TabGroup;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
 import org.apache.isis.core.metamodel.facets.members.cssclass.CssClassFacet;
 import 
org.apache.isis.core.metamodel.facets.object.layoutmetadata.ObjectLayoutMetadataFacet;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.viewer.wicket.model.mementos.ObjectAdapterMemento;
 import org.apache.isis.viewer.wicket.model.models.EntityModel;
 import org.apache.isis.viewer.wicket.ui.ComponentType;
 import org.apache.isis.viewer.wicket.ui.panels.PanelAbstract;
@@ -81,6 +86,7 @@ public class EntityTabGroupsPanel extends 
PanelAbstract<EntityModel> {
                 .from(objectLayoutMetadata.getTabGroups())
                 .filter(TabGroup.Predicates.notEmpty())
                 .toList();
+        final int[] tabGroupCount = new int[]{0};
         final ListView<TabGroup> tabGroupsList =
                 new ListView<TabGroup>(ID_TAB_GROUPS, tabGroups) {
 
@@ -104,14 +110,59 @@ public class EntityTabGroupsPanel extends 
PanelAbstract<EntityModel> {
                         }
                     });
                 }
-                item.add(new AjaxBootstrapTabbedPanel(ID_TAB_GROUP, tabs));
+                final AjaxBootstrapTabbedPanel ajaxBootstrapTabbedPanel = 
newTabbedPanel(tabs, tabGroupCount[0]);
+
+                item.add(ajaxBootstrapTabbedPanel);
+
+                tabGroupCount[0]++;
+            }
+
+            private AjaxBootstrapTabbedPanel newTabbedPanel(final List<ITab> 
tabs, final int tabGroupNumber) {
+                final AjaxBootstrapTabbedPanel tabbedPanel = new 
AjaxBootstrapTabbedPanel(ID_TAB_GROUP, tabs) {
+                    @Override
+                    public TabbedPanel setSelectedTab(final int index) {
+                        saveSelectedTabInSession(tabGroupNumber, index);
+                        return super.setSelectedTab(index);
+                    }
+                };
+                setSelectedTabFromSessionIfAny(tabbedPanel, tabGroupNumber);
+                return tabbedPanel;
+
+            }
+
+            private void setSelectedTabFromSessionIfAny(
+                    final AjaxBootstrapTabbedPanel ajaxBootstrapTabbedPanel,
+                    final int tabGroupNumber) {
+                final String key = buildKey(tabGroupNumber);
+                final String value = (String) getSession().getAttribute(key);
+                if(value != null) {
+                    final int tabIndex = Integer.parseInt(value);
+                    ajaxBootstrapTabbedPanel.setSelectedTab(tabIndex);
+                }
             }
+
+            private void saveSelectedTabInSession(final int tabGroupNumber, 
final int tabIndex) {
+                final String key = buildKey(tabGroupNumber);
+                getSession().setAttribute(key, "" + tabIndex);
+            }
+
+            private String buildKey(final int tabGroupNumber) {
+                final ObjectAdapterMemento objectAdapterMemento = 
EntityTabGroupsPanel.this.getModel().getObjectAdapterMemento();
+                final RootOid oid = (RootOid) 
objectAdapterMemento.getObjectAdapter(
+                        AdapterManager.ConcurrencyChecking.NO_CHECK).getOid();
+                final String key =
+                        IsisContext.getOidMarshaller().marshalNoVersion(oid) + 
"." + tabGroupNumber + ".selectedTab";
+                return key;
+            }
+
         };
+
         add(tabGroupsList);
 
-        
+
     }
 
+
     private static class EntityTabPanel extends PanelAbstract {
         private static final long serialVersionUID = 1L;
 

http://git-wip-us.apache.org/repos/asf/isis/blob/d83b2cfe/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.layout.xml
----------------------------------------------------------------------
diff --git 
a/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.layout.xml
 
b/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.layout.xml
index e49e937..1c56232 100644
--- 
a/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.layout.xml
+++ 
b/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.layout.xml
@@ -4,6 +4,17 @@
         <action id="delete"/>
     </actions>
     <tabGroup>
+        <tab name="Metadata">
+            <left span="6">
+                <propertyGroup name="Persistence">
+                    <actions>
+                        <action id="downloadJdoMetadata"/>
+                        <action id="downloadLayoutXml"/>
+                    </actions>
+                    <property id="versionSequence"/>
+                </propertyGroup>
+            </left>
+        </tab>
         <tab name="Common">
             <left span="6">
                 <propertyGroup name="General">
@@ -19,17 +30,6 @@
                 <collection id="others" defaultView="hide"/>
             </right>
         </tab>
-        <tab name="Metadata">
-            <left span="6">
-                <propertyGroup name="Persistence">
-                    <actions>
-                        <action id="downloadJdoMetadata"/>
-                        <action id="downloadLayoutXml"/>
-                    </actions>
-                    <property id="versionSequence"/>
-                </propertyGroup>
-            </left>
-        </tab>
     </tabGroup>
 <!--
     <tabGroup>

Reply via email to