Author: julien_viet
Date: 2011-05-21 19:07:50 -0400 (Sat, 21 May 2011)
New Revision: 6520
Modified:
components/mop/branches/1.0.x/api/src/main/java/org/gatein/mop/api/workspace/Navigation.java
components/mop/branches/1.0.x/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationContainer.java
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-38 : Navigation index method to ease client
Modified:
components/mop/branches/1.0.x/api/src/main/java/org/gatein/mop/api/workspace/Navigation.java
===================================================================
---
components/mop/branches/1.0.x/api/src/main/java/org/gatein/mop/api/workspace/Navigation.java 2011-05-20
17:28:52 UTC (rev 6519)
+++
components/mop/branches/1.0.x/api/src/main/java/org/gatein/mop/api/workspace/Navigation.java 2011-05-21
23:07:50 UTC (rev 6520)
@@ -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/branches/1.0.x/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationContainer.java
===================================================================
---
components/mop/branches/1.0.x/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationContainer.java 2011-05-20
17:28:52 UTC (rev 6519)
+++
components/mop/branches/1.0.x/core/src/main/java/org/gatein/mop/core/api/workspace/NavigationContainer.java 2011-05-21
23:07:50 UTC (rev 6520)
@@ -51,11 +51,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/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-20
17:28:52 UTC (rev 6519)
+++
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)
@@ -94,6 +94,19 @@
map.put(name, 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 +144,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/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-20
17:28:52 UTC (rev 6519)
+++
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)
@@ -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,6 +51,21 @@
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();
Show replies by date