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

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

When creating a card carrier from the API, you must specify the number of slots it uses. This value is set in the constructor. The following example shows how to create an empty card carrier with two free slots.

How to Create a Card Carrier with the API
IltDefaultDataSource dataSource = new IltDefaultDataSource();
IltShelf s1 = new IltShelf(4, 20, 100, 0);
s1.setAttributeValue(IltShelf.PositionAttribute, new IlpPoint(50, 50));
dataSource.addObject(s1);
 
IltCardCarrier cc1 = new IltCardCarrier(null, 2);  // number of slots
cc1.setAttributeValue(IltCardCarrier.PositionAttribute, 
  new IlpShelfItemPosition(1, 0, 1, 1));
dataSource.addObject(cc1);
 
dataSource.setParent(cc1.getIdentifier(), s1.getIdentifier());

The result looks like this:

images/Image598.gif

Figure 8.11 Shelf with a Card Carrier Containing Two Free Slots

The following code creates a shelf with two card carriers.

How to Create a Shelf with Two Card Carriers
// Create a datasource
IltDefaultDataSource dataSource = new IltDefaultDataSource();
 
// create shelf, set its position and add to datasource
IltShelf s1 = new IltShelf(4, 20, 200, 0);
s1.setAttributeValue(IltShelf.PositionAttribute, new IlpPoint(50, 50));
dataSource.addObject(s1);
 
// create card carrier 1, set its position (relative to s1)
// and add to datasource
IltCardCarrier cc1 = new IltCardCarrier(null, 2);
cc1.setAttributeValue(IltCardCarrier.PositionAttribute, 
  IlpShelfItemPosition(1, 0, 1, 1));
dataSource.addObject(cc1);
 
// create card carrier 2, set its position (relative to s1)
// and add to datasource
IltCardCarrier cc2 = new IltCardCarrier(null, 1);
cc2.setAttributeValue(IltCardCarrier.PositionAttribute,
  new IlpShelfItemPosition(3, 0, 1, 1));
dataSource.addObject(cc2);
 
// create card 1, set its position (relative to cc1) and add 
// to datasource
// note that the position is instance of IlpPoint, not
// IlpShelfItemPosition (card carriers require just one slot index and span)
IltCard c1 = new IltCard(null, "card1");
c1.setAttributeValue(IltCard.PositionAttribute, new IlpPoint(1, 1));
dataSource.addObject(c1);
 
// create card 2, set its position (relative to cc2) and add
// to datasource
IltCard c2 = new IltCard(null, "card2");
c2.setAttributeValue(IltCard.PositionAttribute, new IlpPoint(0, 1));
dataSource.addObject(c2);
 
// set relationship
dataSource.setParent(c1.getIdentifier(), cc1.getIdentifier());
dataSource.setParent(c2.getIdentifier(), cc2.getIdentifier());
dataSource.setParent(cc1.getIdentifier(), s1.getIdentifier());
dataSource.setParent(cc2.getIdentifier(), s1.getIdentifier());

The result looks like this:

images/Image699.gif

Figure 8.12 Shelf with Two Card Carriers

In Figure 8.12, the carrier of card1 has a free slot also. The second card carrier is fully occupied by card2 only.