String nextSiblingId )
throws PortalException
{
// make sure sibling exists and is a child of nodeId
if(nextSiblingId!=null) {
IUserLayoutNodeDescription sibling=getNode(nextSiblingId);
if(sibling==null) {
throw new PortalException("Unable to find a sibling node " +
"with id=\""+nextSiblingId+"\". Occurred " +
"in layout for "
+ owner.getAttribute(IPerson.USERNAME) + ".");
}
if(!parent.getId().equals(getParentId(nextSiblingId))) {
throw new PortalException("Given sibling (\""+nextSiblingId
+"\") is not a child of a given parentId (\""
+parent.getId()+"\"). Occurred " +
"in layout for "
+ owner.getAttribute(IPerson.USERNAME) + ".");
}
}
if ( parent == null ||
! node.isMoveAllowed() )
return false;
if ( parent instanceof IUserLayoutFolderDescription &&
! ( (IUserLayoutFolderDescription) parent).isAddChildAllowed() )
return false;
if ( nextSiblingId == null ) // end of list targeted
return true;
// so lets see if we can place it at the end of the sibling list and
// hop left until we get into the correct position.
Enumeration sibIds = getVisibleChildIds( parent.getId() );
List sibs = Collections.list(sibIds);
if ( sibs.size() == 0 ) // last node in list so should be ok
return true;
// reverse scan so that as changes are made the order of the, as yet,
// unprocessed nodes is not altered.
for( int idx = sibs.size() - 1;
idx >= 0;
idx-- )
{
IUserLayoutNodeDescription prev = getNode((String) sibs.get(idx));
if ( ! MovementRules.canHopLeft( node, prev ) )
return false;
if ( prev.getId().equals( nextSiblingId ) )
return true;
}
return false; // oops never found the sib
}