Business Objects and Data Sources > Shelves and Cards > Shelves > Creating a Shelf with the API

This section shows how to create a shelf using the API and how to add it to the data source.

All you have to do is create a shelf using the class IltShelf and add it to a data source, as shown below.

How to Create a Linear Shelf with the API
IltShelf s1 = new IltShelf(10,//Number of slots in the shelf
   20,//Width of all the slots in the shelf
   100,//Height of all the slots in the shelf
   0);//Value of the first slot number
IlpDataSource dataSource = new IltDefaultDataSource();
dataSource.addObject(s1);

The result looks like this:

images/Image189.gif

Figure 8.2 A Linear Shelf without Cards

The following code creates an empty 4x3 array shelf:

How to Create an Array Shelf with the API
IltShelf s1 = new IltShelf(4,//Number of slots along the x axis
   25,//Width of a slot on the x axis
   3,//Number of slots along the y axis
   30,//Width of a slot on the y axis
   0);//Value of the first slot number
s1.setAttributeValue(IltShelf.PositionAttribute, new IlpPoint(50, 50));
IlpDataSource dataSource = new IltDefaultDataSource();
dataSource.addObject(s1);

The result looks like this:

images/figure290.gif

Figure 8.3 An Empty 4x3 Array Shelf with Fixed-Width Slots