How to format the data in a view at runtime.
| |
You can run this technique code from:
NOTE First make sure that database is running on your localhost SilverStream Server | |
See the chapter on using Java-based views in the Programmer's Guide |
In this example, the view displays data from a database table. The view defines two band formats. The value of the data in a particular column determines which band format is used to display the data. All products with a unit price greater than $500 appears red and bold--the format definition of band 2. (See the dataProductAgcData control properties for further details.)
In this example, the data is stored in a table named products. This table is located in Examples3_Java tables. To add a data control to the form:
if products.unitprice > 500 then "Band2" else "Band1" endif
Rules for using the [Bandname] property
The following code creates column formats for a band. It defines the properties of each column and appends it to the band. The following shows the code for creating one column (Product ID) of the three columns in band 1, and the same column in band 2. Note that for band 2, the column uses a different text color and a different font from that of band 1.
//Code fragment in formActivate() // Set the width in one place for both bands int iProdIdWidth = 80; int iProdNameWidth = 220; int iUnitPriceWidth = 100; // Create the format, band and column variables AgoViewFormat vwFormatObject = new AgoViewFormat(); AgoBandFormat bndFormatObject; AgoColumnText colTextObject; // Write the code for Band1 bndFormatObject = new AgoBandFormat("Band1"); colTextObject = new AgoColumnText(); colTextObject.setPropertyName("productid"); colTextObject.setWidth(iProdIdWidth); bndFormatObject.appendColumnFormat(colTextObject); ... vwFormatObject.appendBandFormat(bndFormatObject); // Write the code for Band2 // this band is a different color and a different font Color colObject = new Color(255, 0, 0); AgoFontIdentifier fntIdObject = new AgoFontIdentifier(colTextObject.getFontIdentifier()); bndFormatObject = new AgoBandFormat("Band2"); colTextObject = new AgoColumnText(); colTextObject.setWidth(iProdIdWidth); fntIdObject.setStyle(fntIdObject.BOLD); colTextObject.setFontIdentifier(fntIdObject); colTextObject.setPropertyName("productid"); colTextObject.setColor(colObject); bndFormatObject.appendColumnFormat(colTextObject);
For band 1, create a column and set its name and its width.
AgoBandFormat
) object. This is band 1.
AgoColumnText
.
setPropertyName()
.
setWidth()
.
bndFormatObject.appendColumnformat()
. After each column is created, append it to band 1.
For band 2, create a column and set its name, width, font, text style, and color.
Color
object and initialize it to red. (The first parameter in its constructor represents the red value. Set it to 255).
AgoFontIdentifier
object that has the same font as the columns in band 1.
setColor()
.
The following code uses appendBandFormat()
to append a band to the view format. Call this method after creating each of the two bands.
//Code fragment in formActivate() vwFormatObject.appendBandFormat(bndFormatObject);
bndFormatObject
holds all the column formats, each appended to bndFormatObject after the column's properties were set.
appendBandFormat
after creating band 1 to add it to the view format. Call this method again after creating band 2 to add it to the view format as well.
The following code dynamically associates the view with data and the format for viewing the data.
//Code fragment in formActivate() vwProducts.initView(dataProduct, vwFormatObject);
initView()
associates the view with an object that provides the data and a format in which to view the data.
dataProduct
provides the rows of data that the view will display.
vwFormatObject
is the view format object that defines the two bands and the column formats in each of them. It contains all the code for creating column formats, appending them to bands, and appending the bands to this view format object.