This section shows you how to create the following equipment view:
Figure 3.1 An Equipment View
The following example walks you through 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
-
Create a frame to contain the equipment.
JFrame frame = new JFrame("ILOG JTGO equipment sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
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. See
Configuring an Equipment Component through CSS for more information on how to create the equipment configuration.
Then, you add the equipment component to the frame.
-
Create the data source and connect it to the equipment component.
// Creates the data source
IltDefaultDataSource dataSource = new IltDefaultDataSource(context);
// Set data source to 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 to the equipment component. The data source stores the business objects that will be converted into representation objects by the equipment adapter through the data source API. The default data source creates the business objects by parsing an XML file or stream where the objects are described (see step 4). However, users can also create their own data sources from a file, a database or even complex data sources based on proprietary object definitions.
-
Read in an XML file,
equipment.xml, that contains the equipment nodes and links.
dataSource.parse("equipment.xml");
How to Add Business Objects in the Data Source for an Equipment Component through an XML File
The easiest way to populate an equipment is to read an XML data file into the data source.
Note that the business object IDs must be unique within the given equipment:
<addObject id="1004035002697 60">
How to Add Business Objects in the Data Source for an Equipment Component through the API
You can also create business objects and insert them in the data source through the API. The following example shows how to insert an JViews TGO 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));
For information on how to define an XML file, refer to Defining the Business Model in XML in the Business Objects and Data Sources documentation.