SOURCECODE

How to... create a Table


Description:
A Table normally is used to display the content of a data container like a Catalog or a CountingStock. To make your own datastrucure fully compatible to the framwork, it is quite important to understand which classes participate in the displaying and editing process.

JAbstractTable
First of all there is the JAbstractTable, which just displays any table. To let it know, which kind of data it shall display and how to do this, it needs an AbstractTableModel, which is being added in the constructor.

AbstractTableModel
The ATM, deals with technical issues, like the properities of the cells of each column, for example the ability to edit them or how the data shall fit into the rows. This is also where the association of records to cells is being resolved. The ATM itself needs a TableEntryDescriptor to resolve the input of each cell from the given data container.

TableEntryDescriptor
As said above, a TED handles the input of each cell and the association of records with them, processing each row and filling it column by column. A row represents an entry of the data container.
Here is the place, where the number of columns is being defined and which cells shall be editable. In such a case, the TableCellEditor is being assigned to the cell. This is also the place where the most mistakes are being made, because you also have to define the CellRenderers for each cell, which causes classCastExceptions when done wrong.

All these parts are already defined for the default data structure of the Framework. There are SingleTableFormSheets and TwoTableFormSheets (FormSheets with two SingleTables on them and some more functionality) which have static create methods where you only have to add a caption, a DataBasket and the data container(s) you want to be displayed while the Framework puts everything together. You then only have to define the buttons and at the TwoTableFormSheets the MoveStrategy for the interaction between the two SingleTables.

Lets display for example the content of the tutorial's "Video-Catalog" on a SingleTableFormSheet, without any editing or buttons. Just a table and the Content and all put together in a Process triggered by a MenuItem in the Office.

ToDo's:
  1. Initialize the Gate where the FormSheet shall be displayed in
  2. Get the Catalog the content shall be displayed of
I
  1. Call SingleTableFormSheet.create(String caption, Catalog c, Gate g) to initialize the SingleTableFormSheet AND assign it to the UIGate

OR

II
  1. Initialize a new JAbstractTable with
  2. the TableModel (here it is a CatalogTableModel) containing
  3. the catalog
  4. a DataBasket, when needed and
  5. a Comparator, when needed (if the data container isn't sorted or the display shall be orderd differnently) and
  6. a new TED (here it is a DefaultCatalogItemTED, because it is specialized on processing CatalogItems, which are contained in the Catalog.
  7. Put the JComponent on the FormSheet,
  8. Assign the fs to the UIGate

The second possibility enables you to redefine any part of the Table to fit to your own data structure.
For more information on redefining, please refer to
How to...

and of course to the SalesPoint API.

Uses:
FormSheet  SaleProcess  SingleTableFormSheet  AbstractTableEntryDescriptor  AbstractTableModel  
JAbstractTable  Catalog  CatalogTableModel  DefaultCatalogItemTED  



SourceCode

import sale.*;
import data.stdforms.*;
import util.swing.*;
import data.*;
import data.swing.*;

public class SeeVideos extends SaleProcess {
    protected UIGate viewGate;

    public SeeVideos() {
        super ("SeeVideoProcess");
    }

    public void setupMachine() {

         1
        //The UIGate where the table shall be displayed in
        viewGate = new UIGate(null, null);

         2
        //The Catalog that is to be displayed (the VideoCatalog of the Tutorial)
        Catalog c = Shop.getTheShop().getCatalog("Video-Catalog");

         I.1
        //This single call has the same effect as the four calls below
        SingleTableFormSheet stfs = SingleTableFormSheet.create("VideoCatalog",
                                                c,
                                                viewGate,
                                                new DefaultCatalogItemTED());

         OR

         II.1
        //The Table, which will be just the same as the one created above
        JAbstractTable jat = new JAbstractTable(
        
                         II.2
                        //The TableModel
                        new CatalogTableModel(
                        
                                         II.3
                                        c, //the Video-Catalog
                                        
                                         II.4
                                        null, //no DataBasket
                                        
                                         II.5
                                        null, //no Comparator
                                        
                                         II.6
                                        //a TED specialized on CatalogItems
                                        new DefaultCatalogItemTED()));

         II.7
        //The FormSheet to display the Component
        FormSheet fs = new FormSheet("VideoCatalog", jat);

         II.8
        //Add the FormSheet to the UIGate
        viewGate.setFormSheet(fs);
    }


    public Gate getInitialGate() {
        setupMachine();
        return viewGate;
    }

}