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

This section shows how to create a card using the API and add it to the data source. The following example shows how to create a shelf with a card using the API.

How to Create a Shelf with a Card through the API
IlpDataSource dataSource = new IltDefaultDataSource();
// create shelf, set its position and add to datasources
IltShelf s1 = new IltShelf(3, 30, 90, 0);
s1.setAttributeValue(IltShelf.PositionAttribute, new IlpPoint(20, 50));
dataSource.addObject(s1);
 
// create card, set its position (relative to the shelf slots) and
// add to datasources
IltCard c1 = new IltCard(null, "card");
c1.setAttributeValue(IltCard.PositionAttribute, 
                     new IlpShelfItemPosition(0, 0, 1, 1));
dataSource.addObject(c1);
 
// set parent-child relationship
dataSource.setParent(c1.getIdentifier(), s1.getIdentifier());

The result looks like this:

images/cardAPI92.gif

Figure 8.5 A Card in a Shelf

The following code illustrates cards associated with an array shelf through the use of slot spanning.

How to Associate Cards with an Array Shelf by Spanning Slots
// create datasource
IltDefaultDataSource dataSource = new IltDefaultDataSource();
 
// Create shelf
IltShelf s1 = new IltShelf(5, 20, 4, 25, 0);
s1.setAttributeValue(IltShelf.PositionAttribute, 
  new IlpPoint(50, 50));
dataSource.addObject(s1);
 
// Create cards
IltCard c1 = new IltCard(null, "c1");
c1.setAttributeValue(IltCard.PositionAttribute, 
  new IlpShelfItemPosition(0, 0, 2.8f, 1.9f));
dataSource.addObject(c1);
IltCard c2 = new IltCard(null, "c2");
c2.setAttributeValue(IltCard.PositionAttribute, 
  new IlpShelfItemPosition(0, 2, 2.8f, 1.9f));
dataSource.addObject(c2);
IltCard c3 = new IltCard(null, "c3");
c3.setAttributeValue(IltCard.PositionAttribute, 
  new IlpShelfItemPosition(3, 0, 1.8f, 3.9f));
dataSource.addObject(c3);
 
// create relationship
dataSource.setParent(c1.getIdentifier(), s1.getIdentifier());
dataSource.setParent(c2.getIdentifier(), s1.getIdentifier());
dataSource.setParent(c3.getIdentifier(), s1.getIdentifier());

The result looks like this:

images/figure593.gif

Figure 8.6 An Array Shelf with Spanned Cards