Show TOC Start of Content Area

Syntax documentation Ordering Collections Locate the document in its SAP Library structure

By default, the resources in a collection have an arbitrary sequence and no special order. If you want to explicitly specify an order, you can:

     Set the ordering of the collection to manual with the setOrderType()method offered by the ICollection interface

     Use the methods of  IReorderList to change the sequence of the resources in the collection

The UML diagram shows the main classes and interfaces involved in the ordering of collections.

This graphic is explained in the accompanying text

Interfaces and Classes

Interface or Class

Purpose

IReorderList

Offers methods to reposition resources.
The methods require an
IPositioning object that stores the new position of a resource.

IPositioning

Stores the name of the resource that is to be repositioned and references the IPosition object that contains the target position.

IPosition,

A container for the target position of a resource. The target position is specified using the definitions provided by enum.OrderPosition:

     OrderPosition.FIRST
The first resource

     OrderPosition.LAST
The last resource

     OrderPosition.BEFORE
The predecessor of another resource

     OrderPosition.AFTER
The successor of another resource

Setting Ordering for a Collection

To enable the resources in a collection to be ordered, you first set the ordering of the collection to manual:

 

ICollection coll = …;
coll.setOrderType(OrderType.MANUAL);

 

If a collection does not support ordering, the exception NotSupportedException is thrown.

Repositioning Resources

Once ordering is set to manual, you can reposition the resources as required. The code extract shows how a collection with the children 1st, 2nd, 3rd, 4th (ordered in this sequence) is reordered to 4th, 3rd, 1st, 2nd. The ReorderList.add()method repositions the resources according to the information provided by the Positioning object that is passed to the method as an argument. The IPositioning object contains the name of the resource involved and its new position.

Note

When the new position is relative, for example, OrderPosition.BEFORE, then it is specified in relationship to another resource. For example, the following code line specifies that the resource 3rd must be moved behind the resource 4th :
reordering.add(new Positioning(″3rd″, new Position(″4th″, OrderPosition.AFTER)))

 

IReorderList reordering = new ReorderList();
reordering.add(
  new Positioning(″4th″, new Position.createFirstPosition())
); 
reordering.add(
  new Positioning(″1st″, new Position.createLastPosition())
); 
reordering.add(
  new Positioning(″2nd″, new Position(″1st″, OrderPosition.BEFORE)) 
); 
reordering.add(
  new Positioning(″3rd″, new Position(″4th″, OrderPosition.AFTER)) 
); 
orderedCollection.reorder(reordering);
End of Content Area