Author: julien_viet
Date: 2011-05-23 17:20:03 -0400 (Mon, 23 May 2011)
New Revision: 6529
Modified:
components/mop/trunk/
components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Navigation.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationContainer.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationImpl.java
components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/NavigationTestCase.java
Log:
GTNMOP-39 : Preserve navigation index when renaming
GTNMOP-38 : Navigation index method to ease client
Property changes on: components/mop/trunk
___________________________________________________________________
Added: svn:mergeinfo
+ /components/mop/branches/1.0.x:6520-6521
Modified:
components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Navigation.java
===================================================================
---
components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Navigation.java 2011-05-23
17:56:55 UTC (rev 6528)
+++
components/mop/trunk/api/src/main/java/org/gatein/mop/api/workspace/Navigation.java 2011-05-23
21:20:03 UTC (rev 6529)
@@ -49,6 +49,13 @@
void setName(String name);
/**
+ * Returns the index of this navigation.
+ *
+ * @return the navigation index
+ */
+ int getIndex();
+
+ /**
* Extends the object type to navigation.
*
* @return the object type
@@ -95,6 +102,19 @@
Navigation addChild(String name) throws NullPointerException,
IllegalArgumentException;
/**
+ * Adds a child navigation that will be added to the specified position among the
ordered children list. When
+ * the the index is not specified, the child is appended at the last position.
+ *
+ * @param index the child index
+ * @param name the child name
+ * @return the child navigation
+ * @throws NullPointerException when a null name is provided
+ * @throws IndexOutOfBoundsException if the index is out of bounds
+ * @throws IllegalArgumentException when an illegal name is provided
+ */
+ Navigation addChild(Integer index, String name) throws NullPointerException,
IndexOutOfBoundsException, IllegalArgumentException;
+
+ /**
* Destroys this navigation.
*/
void destroy();
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationContainer.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationContainer.java 2011-05-23
17:56:55 UTC (rev 6528)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationContainer.java 2011-05-23
21:20:03 UTC (rev 6529)
@@ -53,11 +53,19 @@
@Create
public abstract NavigationImpl createNavigation();
- public NavigationImpl addNavigation(String name)
+ public NavigationImpl addNavigation(Integer index, String name)
{
NavigationImpl page = createNavigation();
page.setNodeName(name);
- getNavigationList().add(page);
+ List<NavigationImpl> list = getNavigationList();
+ if (index != null)
+ {
+ list.add(index, page);
+ }
+ else
+ {
+ list.add(page);
+ }
return page;
}
}
\ No newline at end of file
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationImpl.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationImpl.java 2011-05-23
17:56:55 UTC (rev 6528)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationImpl.java 2011-05-23
21:20:03 UTC (rev 6529)
@@ -88,12 +88,30 @@
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()
+ {
+ NavigationImpl parent = getParent();
+ if (parent == null)
+ {
+ return 0;
+ }
+ else
+ {
+ return parent.getChildren().indexOf(this);
+ }
+ }
+
public ObjectType<? extends Navigation> getObjectType()
{
return ObjectType.NAVIGATION;
@@ -131,12 +149,17 @@
return childrenContainer.getNavigationMap().get(name);
}
- public NavigationImpl addChild(String name)
+ public NavigationImpl addChild(Integer index, String name) throws
NullPointerException, IndexOutOfBoundsException, IllegalArgumentException
{
NavigationContainer childrenContainer = getChildrenContainer();
- return childrenContainer.addNavigation(name);
+ return childrenContainer.addNavigation(index, name);
}
+ public NavigationImpl addChild(String name)
+ {
+ return addChild(null, name);
+ }
+
public <L extends Link> L linkTo(ObjectType<L> linkType)
{
setLink(null);
Modified:
components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/NavigationTestCase.java
===================================================================
---
components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/NavigationTestCase.java 2011-05-23
17:56:55 UTC (rev 6528)
+++
components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/NavigationTestCase.java 2011-05-23
21:20:03 UTC (rev 6529)
@@ -32,14 +32,18 @@
*/
public class NavigationTestCase extends AbstractPOMTestCase
{
- public void testNavigationOrder()
+ public void testOrder()
{
ModelImpl model = pomService.getModel();
Site portal = model.getWorkspace().addSite(ObjectType.PORTAL_SITE,
"portal_for_navigation");
Navigation root = portal.getRootNavigation();
+ assertEquals(0, root.getIndex());
Navigation n1 = root.addChild("1");
+ assertEquals(0, n1.getIndex());
Navigation n2 = root.addChild("2");
+ assertEquals(1, n2.getIndex());
Navigation n3 = root.addChild("3");
+ assertEquals(2, n3.getIndex());
List<? extends Navigation> ns = root.getChildren();
assertEquals(3, ns.size());
assertSame(n1, ns.get(0));
@@ -47,14 +51,31 @@
assertSame(n3, ns.get(2));
}
+ public void testIndexAdd()
+ {
+ ModelImpl model = pomService.getModel();
+ Site portal = model.getWorkspace().addSite(ObjectType.PORTAL_SITE,
"portal_for_navigation");
+ Navigation root = portal.getRootNavigation();
+ Navigation n1 = root.addChild("1");
+ Navigation n3 = root.addChild("3");
+ Navigation n2 = root.addChild(1, "2");
+ List<? extends Navigation> ns = root.getChildren();
+ assertEquals(3, ns.size());
+ assertSame(n1, ns.get(0));
+ assertSame(n2, ns.get(1));
+ assertSame(n3, ns.get(2));
+ }
+
public void testSetName()
{
ModelImpl model = pomService.getModel();
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());
}
}