Perforce 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 Perforce 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
When you expand or select a tree node, its children are loaded from the 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 Perforce JViews.
Then, go to the installation directory
of the sample and type:
ant run
Topics Covered
- Subclassing ilog.cpl.datasource.IlpDefaultDataSource to support load-on-demand
- Creating an ilog.cpl.model.IlpObjectimplementation to wrap
java.io.File
instances - Subclassing ilog.cpl.util.IlpDefaultTypeConverter to support the conversion from
Long
toDate
. This conversion is used for thelast Modified
attribute (see table) - Implementing ilog.cpl.css.function.IlpCSSFunction to get the length of a file in a nicer format, like 23 KB or 45 MB
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
-
ilog.cpl.IlpSystem
The class that initializes a JViews TGO application.
-
ilog.cpl.datasource.IlpDefaultDataSource
The default datasource implementation.
-
ilog.cpl.datasource.structure.IlpChild
The interface which defines structural information for a business objects.
-
ilog.cpl.datasource.structure.IlpContainer
The interface which defines structural information for a business objects.
-
ilog.cpl.model.IlpObject
The interface that defines a business object.
-
ilog.cpl.util.IlpDefaultTypeConverter
The class used by the default context implementation.
-
ilog.cpl.IlpTree
The JViews TGO Tree component.
-
ilog.cpl.IlpTable
The JViews TGO Table component.
-
ilog.cpl.css.function.IlpCSSFunction
The interface that specifies a custom CSS function.
Source Files
-
datasource.explorer.Main
The entry point of the sample.
-
datasource.explorer.FileDataSource
The datasource custom implementation.
-
datasource.explorer.FileObject
The business object custom implementation.
-
datasource.explorer.OriginFilter
The filter that specifies which objects are displayed in the Table view.
-
datasource.explorer.ByteFunction
The custom CSS function to convert the file size to be displayed in a table cell.