Rogue Wave JViews TGO Sample: Data Source - Custom Business Classes


Description

This sample shows how to implement a custom data source that loads directories on demand. It is similar to the Rogue Wave JViews TGO Data Source - JavaBeans Sample, except that here the java.io.File is wrapped by a custom ilog.cpl.model.IlpObject class instead of being considered as JavaBeans.

How to Use the Sample

The main frame is similar to a file explorer: it contains a tree on the left, and a table on the right. The tree shows the file hierarchy. It allows you to select and expand tree nodes. The table shows the contents of the directory selected in the tree.

When you expand or select a tree node, its children are loaded from the file system.

This sample does not work as an applet, as it accesses the local file system.

All available drives will be accessed, including floppy drives. If you do not have a floppy inserted, the drive will be ignored. Files that cannot be read by the application are not listed in the table and tree components.

How to Run the Sample as an Application

This sample can be run as an application. The installation directory contains an executable JAR file, datasource-explorer2.jar, that allows you to execute the sample with a double click from a file browser. Note that if you are using Internet Explorer, you can open the installation directory and execute the JAR file from the browser. This technique may not work in other Web browsers.

Alternatively, you can run the sample application from the command line. First check that the Ant utility is properly configured. If not, see the instructions on how to configure Ant for Rogue Wave JViews.

Then, go to the installation directory of the sample and type:

ant run

Topics Covered

Detailed Description

This sample shows how to write an implementation of ilog.cpl.model.IlpObject to wrap java.io.File instances, and how to extend ilog.cpl.datasource.IlpDefaultDataSource to work with this ilog.cpl.model.IlpObject implementation and load on demand these ilog.cpl.model.IlpObject instances. The tree and table work like in a regular file explorer.

The code of the custom ilog.cpl.model.IlpObject is defined in the datasource.explorer.FileObject class.

The code of the custom data source is defined in the datasource.explorer.FileDataSource class. This data source implementation first initializes the file system root objects as ilog.cpl.model.IlpObject instances. Then, to support load-on-demand, it redefines the method ilog.cpl.datasource.IlpDefaultDataSource.getContainerInterface to return its own implementation of the ilog.cpl.datasource.structure.IlpContainer interface for a directory. As this implementation does not store the containment relationship for files and directories, the ilog.cpl.datasource.IlpDefaultDataSource.getChildInterface method is also redefined to return a custom implementation of the ilog.cpl.datasource.structure.IlpChild interface for files.

Installation Directory

The Data Source - Custom Business Classes sample is installed here.

Classes Involved

Source Files

Copyright © Rogue Wave Software, Inc. 1997, 2015. All rights reserved. Legal terms.