Creating an equipment component: a sample

This topic shows you how to create the following equipment view:
equipmentsample.gif
An equipment view
The following example describes the steps of creating a frame as an equipment container, creating an instance of IlpEquipment, creating a data source and connecting it to the equipment, and finally reading in the equipment data.

How to create a basic equipment component

  1. Create a frame to contain the equipment.
    // Create a frame.
    JFrame frame = new JFrame("JTGO equipment sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
  2. Create the equipment component.
    IlpEquipment equipment = new IlpEquipment(sampleConfigurationFile, context);
    frame.getContentPane().add(equipment);
    
    You need to create a new instance of an equipment and make sure that the appropriate configuration is assigned. The equipment configuration is normally read in from a CSS file. You ensure that the equipment configuration file is taken into account and parsed by passing the URL and context or, as in the example, by passing the filename and context as arguments of IlpEquipment. For more information on how to create the equipment configuration, see Configuring an equipment component through CSS . Then you add the equipment component to the frame.
  3. Create the data source and connect it to the equipment component.
    // Creates the data source
    IltDefaultDataSource dataSource = new IltDefaultDataSource(context);
    // Set data source for the equipment component
    equipment.setDataSource(dataSource);
    
    Once the equipment component is created, you need to associate it with a data source. By default, no data source is set for the equipment component. The data source holds the business objects that will be converted into representation objects by the equipment adapter through the data source API.
  4. Read in an XML file, equipment.xml , that contains the equipment nodes and links.
    dataSource.parse("equipment.xml");
    
    The default data source creates the business objects by parsing an XML file or stream where the objects are described, as shown. You could instead create your own data source from a file or database, or even create a complex data source based on proprietary object definitions.
For information on how to define an XML file, refer to Defining the business model in XML .

How to add business objects to the data source for an equipment component through an XML File

The easiest way to populate the data source for an equipment is to read an XML data file.
The business object IDs in the XML file must be unique within the given equipment.
The following example shows an object definition in the XML file.
<addObject id="1004035002697 60">
  <class>
    ilog.tgo.model.IltShelf
  </class>
      ...
</addObject>

How to add business objects to the data source for an equipment component through the API

An alternative way to populate the data source for an equipment is to create business objects and insert them in the data source through the API.
The following example shows how to insert a shelf.
// Creates an empty shelf using API
IlpObject obj = new IltShelf(3, 40, 30, 0);
// Add object to data source
dataSource.addObject(obj);
// Set its position to 200, 50 in the view
obj.setAttributeValue(IltShelf.PositionAttribute, new IlpPoint(200, 50));