Generating tables

 

Overview

J services are provided to create tables for the RTF and HTML formats.

 

Note:      For the ASCII and Postscript formats, each column of the table is separated by a blank.

 

The ... J service

is used to ...

generateTableStart

define the table.

generateTableLine

define a line in the table.

generateTableEnd

end generation of the table.

 

 

Detailed description

String generateTableStart (in String width,

                           in String align,

                           in boolean border,

                           in String caption,

                           in String captionAlign)

 

 

The ... parameter

designates ...

width

the width of the table on the page.  This width is expressed as a percentage (from 0 to 100).

align

the alignment of the table on the page.  Possible values are "left", "right" and "center".

border

the possibility of adding a border to the table.

caption

the table's caption.

captionAlign

the position of the caption with regard to the table.  Possible values are "top" (the caption is before the table) and "bottom" (the caption is after the table).

 

 

String generateTableLine (in boolean header,

                          in String [] cells,

                          in String [] columnWidth,

                          in String columnAlign)

 

 

The ... parameter

designates ...

header

the line used as the header of the table.

In RTF, all this line's cells have a style different to that of the other lines.  This style can be parameterized in the "styles.dot" Word model.  In RTF, this line is also repeated at the top of every page, where the table is generated over several pages.

cells

cell text in the form of a set of Strings.

columnWidth

the width of the columns in the form of a set of Strings.  This width is expressed as a percentage with regard to the size of the table (from 0 to 100).

columnAlign

the alignment of the column's text in the form of a set of Strings.  Possible values are  "left", "right", "center" and "justify".

 

 

String generateTableEnd()

 

This service is essential to stopping the definition of the table.  If this service is not called, Microsoft Word runs the risk of not being able to open the RTF document generated.  Similarly, internet browsers are not able to display the generated document correctly.

 

 

Example

The following example allows the generation of a table containing the operations of a class.  This table will contain two columns:

·         the name of the method

·         the description of the method

 

To run this code, you should simply:

·         create a generation method which can be referenced by a document template item (for further information, please see "Creating rules")

·         define a document item which browses the classes of a package, and reference the previous method as a pre-generation method

·         enter the following code for the pre-generation method

 

String   result;

String[] cells;

String[] columnWidth;

String[] columnAlign;

 

// Definition of column width

columnWidth.addElement ("25");

columnWidth.addElement ("75");

 

// Definition of column alignment

columnAlign.addElement ("left");

columnAlign.addElement ("left");

 

if (PartOperation.size() != 0) {

    result.strcat (generateTableStart

                   ("80", "center", true, "", ""));

    // Definition of table header

    cells.addElement ("Name");

    cells.addElement ("Description");

 

    result.strcat (generateTableLine (true, cells,

                   columnWidth, columnAlign));

 

    PartOperation {

        // Generation of a line per operation of the

           class

        String description = “”;

        cells.clear();

        cells.addElement (Name);

 

        // Retrieval of "description" note contents

        DescriptorNote.<select (ModelNoteType.Name ==

                                "description") {

            description = description + Content;

        }

 

        cells.addElement (description);

        result.strcat (generateTableLine (false, cells, columnWidth, columnAlign));

    }

    result.strcat (generateTableEnd());

}

 

return result;

 

 

The result is shown in Figure 36 below.

 

Figure 36. The newly-created table