Author: julien_viet
Date: 2011-05-21 19:18:00 -0400 (Sat, 21 May 2011)
New Revision: 6521
Modified:
components/mop/branches/1.0.x/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationImpl.java
components/mop/branches/1.0.x/core/src/test/java/org/gatein/mop/core/api/workspace/NavigationTestCase.java
Log:
GTNMOP-39 : Preserve navigation index when renaming
Modified:
components/mop/branches/1.0.x/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationImpl.java
===================================================================
---
components/mop/branches/1.0.x/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationImpl.java 2011-05-21
23:07:50 UTC (rev 6520)
+++
components/mop/branches/1.0.x/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationImpl.java 2011-05-21
23:18:00 UTC (rev 6521)
@@ -88,10 +88,15 @@
public void setName(String name)
{
- // todo: change to setNodeName when it is fixed
- NavigationContainer parent = getParentContainer();
- Map<String, NavigationImpl> map = parent.getNavigationMap();
- map.put(name, this);
+ // Capture the current index
+ int index = getIndex();
+
+ // Rename (will change the index to the last / JCR move)
+ setNodeName(name);
+
+ // Set index back to original value
+ List<NavigationImpl> siblings = getParentContainer().getNavigationList();
+ siblings.add(index, this);
}
public int getIndex()
Modified:
components/mop/branches/1.0.x/core/src/test/java/org/gatein/mop/core/api/workspace/NavigationTestCase.java
===================================================================
---
components/mop/branches/1.0.x/core/src/test/java/org/gatein/mop/core/api/workspace/NavigationTestCase.java 2011-05-21
23:07:50 UTC (rev 6520)
+++
components/mop/branches/1.0.x/core/src/test/java/org/gatein/mop/core/api/workspace/NavigationTestCase.java 2011-05-21
23:18:00 UTC (rev 6521)
@@ -72,8 +72,10 @@
Site portal = model.getWorkspace().addSite(ObjectType.PORTAL_SITE,
"portal_for_navigation");
Navigation root = portal.getRootNavigation();
Navigation n1 = root.addChild("1");
+ Navigation n2 = root.addChild("2");
assertEquals("1", n1.getName());
- n1.setName("2");
- assertEquals("2", n1.getName());
+ n1.setName("3");
+ assertEquals("3", n1.getName());
+ assertEquals(0, n1.getIndex());
}
}