ElegantJBeans – Data Tables
Programmers’ Guide
Table of Content
3.1.1.1 Setup,
Navigation and Editing
3.1.1.2 Formatting
and Appearance
3.1.2.1 Setup,
Navigation and Editing
3.1.2.2 Formatting
and Appearance
3.2 ElegantJ Data Access Components
3.2.1 ElegantJ
Database Access Component
3.2.2 ElegantJ
Text Data Access Component
3.2.2.1 ElegantJ
Text via File
3.2.2.2 ElegantJ
Text via HTTP
3.2.3 ElegantJ
XML Data Access Component
5 Installation and
Registration
5.4.2 Using
with Graphical User Interface of IDE
5.4.3 Using
directly with source code
6.1.1.1 Creating
an instance of AWTDataGrid
6.1.1.2 Applying
general formatting features
6.1.1.3 Applying
advanced features of formatting and appearance
6.1.1.4 Setting
up row and column header
6.1.1.5 Configuring
cell renderers and cell editors
6.1.1.6 Implementing
row – column resizing functionalities
6.1.1.7 Setting
actions for key strokes
6.1.1.8 Working
with selection and selection style
6.1.1.9 Setting
up editing functionalities
6.1.1.10 Setting up row heights
6.1.1.11 Setting up column widths
6.1.1.12 Setting up grid properties
6.1.1.13 Configuring search panel
6.1.1.14 Searching for information
6.1.1.15 Sorting of information
6.1.1.16 Setting visibility of popup menu
6.1.1.17 Configuring data with AWTDataGrid
6.1.1.18 Implementing paper size and paper
type for printing
6.1.1.19 Setting up margins and header and
footer for printing
6.1.1.20 Setting page orientation for printing
6.1.1.21 Setting number of copies for printing
6.1.1.22 Setting line below header and line
above footer for printing
6.1.1.23 Doing page setup for printing
6.1.1.24 Opening print preview for printing
6.1.1.25 Handling bulk print jobs (by
controlling spool size)
6.1.1.26 Implementing printing – methods to
use
6.1.1.27 Printer listeners and events
6.1.1.28 AWTDataGrid listeners and events
6.1.1.29 Configuring data access component
with AWTDataGrid
6.1.1.30 Handling Data Navigation
6.1.1.31 Handling Data Modification
6.1.2.1 Creating
an instance of DataGrid
6.1.2.2 Applying
general formatting features
6.1.2.3 Applying
advanced formatting features for entire table
6.1.2.4 Implementing
advanced formatting features based on row and columns
6.1.2.5 Setting
up column header
6.1.2.7 Setting
up cell editors and cell renderers
6.1.2.8 Setting
up grid attributes
6.1.2.9 Setting
up row heights and row margins
6.1.2.10 Setting up column widths and column
margins
6.1.2.11 Working with selection and selection
style
6.1.2.12 Configuring editing features
6.1.2.13 Configuring data with DataGrid
6.1.2.14 Setting up auto resizing feature
6.1.2.15 Setting up key strokes insert, delete
and enter key
6.1.2.16 Setting visibility of popup menu
6.1.2.17 Configuring search panel
6.1.2.18 Searching for information
6.1.2.20 Configuring data access component
with ElegantJ DataGrid
6.1.2.21 Handling data navigation
6.1.2.22 Handling data modification
6.2 ElegantJ Data Access Component
6.2.1 ElegantJ
Database Access Component
6.2.1.1 Creating
an instance of Database Access Component
6.2.1.2 Configuring
database connection
6.2.1.3 Configuring
database query
6.2.1.4 Configuring
data retrieval
6.2.1.6 Getting
retrieved data information
6.2.1.7 Navigating
retrieved data
6.2.1.8 Manipulating
retrieved data
6.2.1.12 Exporting data as text
6.2.1.13 Exporting data as XML
6.2.1.14 Exporting data as SQL
6.2.2 ElegantJ
Text Data Access Component
6.2.2.1 ElegantJ
Text via File
6.2.2.2 ElegantJ
Text via HTTP
6.2.3 ElegantJ
XML Data Access Component
6.2.3.1 Creating
an instance of XML Data Access Component
6.2.3.2 Configuring
data source
6.2.3.3 Configuring
data retrieval
6.2.3.5 Getting
retrieved data information
6.2.3.6 Navigating
retrieved data
6.2.3.7 Manipulating
retrieved data
6.2.3.11 Exporting data as Text
6.2.3.12 Exporting data as XML
6.2.3.13 Exporting data as SQL
7 Product and Support
Information
This preface describes the document. The preface contains the following sections:
|
Section |
Page |
|
Purpose of this document |
7 |
|
Assumptions |
7 |
|
Document Organization |
7 |
|
Conventions Used |
8 |
The purpose of this document is to provide the fundamental skills necessary to productively install, program, integrate, and use the ElegantJ DataTable. This document provides both programmer and user perspective to the audience.
This manual assumes that readers are having reasonable level of exposure to fundamentals of Java programming and various architectures.
This document is organized as described in following tables.
Table 1 – Organization of the document
|
Chapter |
Contents |
|
About
ElegantJ Data Tables |
Ø What's New Ø Toolkit |
|
Features |
Ø ElegantJ Data Tables Ø ElegantJ Database Access Ø ElegantJ Text Data Access Ø ElegantJ XML Data Access |
|
Product
Demo |
Ø Installing Demo Ø View Demo |
|
Installation
and Registration |
Ø Prerequisite Ø Installation Procedure Ø Using with Different IDEs Ø Getting Registered |
|
Programmers’
Guide |
Ø Core components and definitions for different data tables Ø Programmer’s guide to frequently asked questions |
|
File |
Italic (slanted) type indicates variable values, instruction operands. |
|
[ | ] { | } |
In syntax definitions, brackets indicate items that are optional and braces indicate items that are required. Vertical bars separating items inside brackets or braces indicate that you choose one item from among those listed. |
|
. . . |
In syntax definitions, a horizontal ellipsis indicates that the preceding item can be repeated one or more times. |
|
// |
An explanation of a particular function performed by preceding code. |
Be it a 4 row by 10 column table or a table to represent a database in tabular form, or a spreadsheet solution, you can depend on ElegantJ Data Tables Bean. From AWT Data Table and JFC Data Table, select the one that suits your need. Both can handle large volume of data. Get the data filled directly from data source. A cell can be edited as a Textbox, TextArea, CheckBox, Combobox, a Button, an icon, boolean, etc. Manage data with maximum flexibility using Bean's formatting, editing, navigating and data handling features. Ready to use Search Panel, functions of insert, add or delete a row as well as column and sorting. ElegantJ Data Tables Bean offers total control over data management through table.
It provides efficient Data handling. Data Access components that are shipped with this bean are so powerful and flexible, they can work in most of the limitations imposed by architectural circumstances, security and accessibility constraints on servers. With ElegantJ Data Access components, you will be able connect and communicate with any computer through protocols like FILE, JDBC, FTP or HTTP.
It is whole New Collection. This collection is derived from our Tables collection. ElegantJ Data Tables is a whole new JavaBeans collection designed to cater when you wish to work with data in tabular form. Use this bean specially when you need Data Aware Tables. Read Overview for more information.
Evaluation Dialog
In case you are using evaluation, an Evaluation Dialog used to popup every 10 minutes. This dialog will now appear only once, making evaluation without interruption.
ElegantJ Data Tables is shipped with two sets of Beans:
ElegantJ Data Tables Bean
Ø AWT Data Table Bean
o ElegantJ AWT Data table (awtdatatablesviewer.jar)
Ø JFC Data Table Bean
o ElegantJ JFC Data Table (datatablesviewer.jar)
ElegantJ Data Providers
ElegantJ Data Tables Bean use following data access components to exchange data from data source. All of these data access components can be bound with AWT Table as well as JFC Data Table.
Ø ElegantJ Sql Data Provider (sqldataprovider.jar)
Ø ElegantJ Text Data Provider (textdataprovider.jar)
Ø ElegantJ HTTP Text Data Provider (httptextdataprovider.jar)
Ø ElegantJ FTP Text Data Provider (ftptextdataprovider.jar)
Ø ElegantJ XML Data Provider (xmldataprovider.jar)
3.1 ElegantJ Data Tables
3.1.1ElegantJ AWT Data Table
3.1.1.1 Setup, Navigation and Editing
Ø Row and column header attributes can be customized in Elegant AWT Data Table JavaBean.
o General appearance like background, borders, fonts, cursor type, etc.
o With ElegantJ AWT Data Table JavaBean, you can customize attributes like Header background, Text, Column header height and row header width, Make header visible or invisible
o You can also resize column / row from header in this JavaBean
Ø Provides wide range of selection attributes
o Wide range of selection attributes. What you can select, how you can select
o You can select a row, column, row interval as well as column interval in ElegantJ JavaBean
o In this JavaBean, you have an option to enable or disable row and column selections. Selection can be restricted to single (row or column or cell) or a range
Ø In this JavaBean, you can control editability at table, row or column level.
Ø Easy Resizing - resize from column header, row header or cell. Also size row or column on double-click.
Ø Auto-scroll on mouse drag.
Ø Update table in real-time during dragging.
Ø Apply Cell Renderers and Cell Editors on entire table or selected rows or columns
o Cell Renderers: Cell renderer is a component which renderers the cell. You can apply any component as a cell renderer for ElegantJ JavaBean. This renderer can be applied at table level, column level or at Row level.
o ElegantJ AWT Data Tables is shipped with following Cell Renderers
§ Text Renderer
§ TextArea Wrap Renderer
§ Checkbox Renderer
§ Combobox Renderer
§ Button Renderer
o Cell Editors: This component is used to edit a cell. You can apply any component as a cell editor for ElegantJ AWT Data Table JavaBean. This editor can be applied at Table level, Column level and low level.
o ElegantJ AWT Data Table JavaBean is shipped with following editors
§ Text Editor
§ TextArea Editor
§ Checkbox Editor
§ Combobox Editor
Ø Delete a row, insert a row and add a row with Delete / Insert / Enter key strokes respectively.
Ø Ready to use Popup menu with much needed options
o ElegantJ AWT Data Table Bean is shipped with ready to use popup menu that can pop on a right-click on mouse.
o You have options to Add a row or column, Insert row or column, Edit a cell and Sort
Ø Limit resizing of row height and column width by applying a minimum and maximum limit.
3.1.1.2 Formatting and Appearance
Ø ElegantJ AWT Data Table JavaBean supports general formatting features like Text, background, locale, border, etc
o General formatting features like Text, background, locale, border, etc.
o ElegantJ AWT Data Table JavaBean offers you control over Color of text and background, Locale, Cursor type, Enability and visibility
o Border style as None, Simple, Raised and Lowered.
Ø Advance Formatting Features for entire table, selected rows or columns
o This JavaBean gives you control over color for selected areas of table. You can control background, text, border, font for Entire table, Selected rows, Selected columns
Ø Better appearance through formatting of Horizontal and vertical grids
o In ElegantJ AWT Data Table JavaBean, you control visibility of grid - Vertical grid, horizontal grid
o Also using ElegantJ AWT Data Table JavaBean, you can control width and color of the grid
Ø Customizable Row and column numbers.
Ø You can conduct sort activity in ascending or descending order. This is available on mouse click on column header as well as on right click menu.
Ø Ready to use Search panel with powerful yet flexible search options
o ElegantJ AWT Data Table JavaBeans offers ready to use Search Panel with placement and formatting options.
o You can choose to place Search Panel on top or bottom.
o You can select color of background and text.
o Search is upwards or downwards, from top or bottom.
o This JavaBean provides search options like Exact match, Starts with, Ends with, Contains.
Ø ElegantJ JavaBean includes an option for Page setup and Print Preview before you print
o In ElegantJ AWT Data Table JavaBean, you have options to choose paper size and orientation.
o Setup facility of margins, and header / footer.
o You can set number of copies, date or a variable as part of header or footer in this JavaBean.
o You have ability to preview page before printing in ElegantJ AWT Data Table JavaBean.
Ø ElegantJ AWT Data Table Bean is shipped with Data Access Components. A table can exchange data from database through Data Access Components.
Ø Seamless connectivity with databases through SQL, XML, FTP, HTTP.
Ø Ready to implement Record Navigation (first, last, previous, next) feature for Data Tables.
3.1.2.1 Setup, Navigation and Editing
Ø Wide range of selection attributes about things that you can select, how it can be selected
o ElegantJ JFC Data Table JavaBeans provides you facility to select a row, column, row interval, column interval and to enable or disable row and column selections
o Selection can be restricted to single (row or column or cell) or a range (contiguous or discontiguous)
Ø Editability can be controlled at table, row or column level.
Ø Easy Resizing of columns and rows - resize from column header, row header or cell. Also, size row or column on double-click.
Ø ElegantJ JFC Data Table JavaBean provides you auto-scroll on mouse drag. Update table in real-time with dragging.
Ø Apply Cell Renderers and Cell Editors on entire table or selected rows or columns
o Cell Renderer: Cell renderer is a component which renderers the cell. You can apply any component as a cell renderer for ElegantJ JFC Data Table JavaBean. This renderer can be applied for whole table, at column level or row level.
o ElegantJ JFC Data Table is shipped with following renderers
§ BooleanRenderer
§ CheckboxRenderer
§ ChoiceRenderer
§ ColorRenderer
§ DateRenderer
§ DefaultRenderer
§ IconRenderer
§ MultiLineRenderer
§ MultiOptionRenderer
§ NumberRenderer
§ ProgressRenderer
§ RadioButtonRenderer
§ TextRenderer
o Cell Editors: Cell Eidtor is a component which is used to edit a cell. You can apply any component as a cell editor for ElegantJ JFC Data Table bean. This editor can be applied for entire table, selected columns or rows.
o ElegantJ JFC Data Table Bean is shipped with following cell editors
§ BooleanEditor
§ CheckboxEditor
§ ChoiceEditor
§ ColorEditor
§ DateEditor
§ DefaultEditor
§ IconEditor
§ MultiLineEditor
§ MultiOptionEditor
§ NumberEditor
§ RadioButtonEditor
§ SliderEditor
Ø Delete / Insert / Enter keystrokes to delete a row, insert a row and add a row.
Ø Ready to use Popup menu with much needed options
o ElegantJ JFC Data Table JavaBean is shipped with ready to use popup menu that can pop on a right-click on mouse. Menu options are Add, Insert, Edit, Remove, Sort Ascending, Sort Descending
o This JavaBean also gives you options to add a row or column, insert row or column, edit a cell or sort
Ø Limit resizing of row height and column width by applying a minimum and maximum limit. Set row height for all rows or selected ones.
Ø Auto Resize of columns
o You can re-size columns. ElegantJ JFC Data Table JavaBean provides ability to switch this option on or off.
o This JavaBean also offers facility to auto-resize Next column, Subsequent columns, Last column, All columns.
3.1.2.2 Formatting and Appearance
Ø General formatting features like Text, background, locale, border, etc.
o This JavaBean provides you control over Color of text, background, Selection of locale, Cursor type, Enability and visibility
o Using ElegantJ JFC Data Table JavaBean you can also have swing look and feel features like Lightweight, Opaque, Tool tip text, Double buffering for painting, Focus receipt and management, Border of component auto scrolling.
Ø Advance Formatting Features for entire table, selected rows or columns
o ElegantJ JFC Data Table JavaBean provides you control over color for selected areas of table Background, Text, Border, Font
o Also, this JavaBean provides formatting of focus cell background and text and Image icon and font
o All these can be applied to Entire table Rows and Columns
Ø Row and column header attributes can be customized in ElegantJ JFC Data Table JavaBean
o In ElegantJ JFC Data Table JavaBeans, you can customize row and column header attributes like Header background, Text, Column header height and row header width, Make header visible or invisible and Resize column / row from header
o You can resize columns and rows. You can reorder columns in this JavaBean
Ø Better appearance through formatting Horizontal and vertical grids
o Control visibility of grid - Vertical grid, horizontal grid in ElegantJ JFC Data Table JavaBean.
o Using this JavaBean, also control width and color of Grid.
Ø Customization of Row and column numbers is possible in this JavaBean.
Ø You can conduct sort activity in ascending or descending order. This is available on mouse click on column header as well as on right click menu.
Ø This JavaBean provides you ready to use Search panel with powerful yet flexible search options
o ElegantJ JFC Data Table JavaBean has ready to use Search Panel with placement and formatting options.
o You can choose to place Search Panel on top or bottom.
o You can select color of background and text.
o In this JavaBean, search can be performed upwards or downwards, from top or bottom.
o Search options like Exact match, Starts with, Ends with and Contains.
Ø Configurable Data Model. Properties you can configure are - total number of columns, total number of rows, column names and Data.
Ø ElegantJ JFC Data Table JavaBean is shipped with Data Access Components. A table can exchange data from database through Data Access Components.
Ø Seamless connectivity with databases through SQL, XML, FTP, HTTP.
Ø Ready to implement Record Navigation (first, last, previous, next) feature for Data Tables.
3.2 ElegantJ Data Access Components
3.2.1ElegantJ Database Access Component
ElegantJ Database Access component provides an interface to carry out database operations. It connects to the database using any type of JDBC driver to retrieve and manipulate data. Features of ElegantJ Database Access component are:
Ø ElegantJ Database Access component supports all the four types of JDBC Connections.
Ø Configurable connection attributes, viz. database URL, driver, username, password, etc.
Ø Reads data from database via a JDBC connection.
Ø Allows to configure SQL query string.
Ø This JavaBean facilitates users to specify parameters in SQL query in the form of retrieval arguments. Value of parameters can be set at run time.
Ø Allows to include columns as where criteria. In ElegantJ Sql Data Access Component JavaBean, you can specify options viz. unique columns, unique and updateable columns, unique and modified columns.
Ø Option to restrict data updating to specific columns as well as tables.
Ø This JavaBean offers an option to update data directly or first delete and followed by insert to the database.
Ø Option to skip lines from begin of file while importing data from text file.
Ø Configurable fetch size to fetch records.
Ø Option to append or replace fetched data in existing client buffer.
Ø Configurable delimiter character for rows and columns.
Ø Ready to use methods for insert, delete, modify, retrieve, filter and sort operations on data stored in data access component.
Ø Modified data (with or without filter) can be exported to any database, XML file or Text file using this JavaBean.
Ø ElegantJ Database Access component provides a method to obtain information about the data retrieved, columns and tables.
Ø Notification is sent to the user whenever a record is changed, inserted, updated or deleted.
3.2.2ElegantJ Text Data Access Component
3.2.2.1 ElegantJ Text via File
ElegantJ Text Data Access component provides an interface to retrieve data from text file separated by row and column separator. Features of ElegantJ Text Data Access Component are:
Ø ElegantJ Text Data Access component reads data from local machine or from remote machine via its URL.
Ø Can parse data with fixed column size or with delimiter. Also parses data by user defined text qualifier.
Ø Option to skip lines from begin of file as well as from the end of file while importing data from text file.
Ø This JavaBean provides facility to configure fetch size to fetch records.
Ø Configurable delimiter character for rows and columns.
Ø Option to append or replace fetched data in existing client buffer.
Ø This JavaBean provides an option to consider the first line as column header.
Ø Column names can be retrieved and stored in data access component.
Ø ElegantJ Text Data Access component provides ready to use methods for insert, delete, modify, retrieve, filter and sort operations on data stored in data access component.
Ø Modified data (with or without filter) can be exported to any database, XML file or Text file.
Ø Notification is sent to the user whenever a record is changed, inserted, updated or deleted.
3.2.2.2 ElegantJ Text via HTTP
ElegantJ HTTP Text Data Access component provides an interface to carry out data operations on Text data through HTTP protocol. It retrieves data from HTTP server through response and POSTs modified data back to HTTP server. This power-packed JavaBean gives your full control to view, insert, update and delete text data on any HTTP web server. As a result, you have liberty to use any server side scripting like ASP, JSP, Servlets, PHP etc., in conjunction with this bean. Features of ElegantJ HTTP Text Data Access component are:
Ø ElegantJ HTTP Text Data Access component reads data from remote file.
Ø Makes use of common methods - GET, POST and HEAD methods for data exchange.
Ø This JavaBean sends file as well as string buffer to HTTP server as an entity.
Ø Can parse data with fixed column size or with delimiter.
Ø Option to skip lines from begin of file while importing data from text file.
Ø Configurable fetch size to fetch records.
Ø Option to append or replace fetched data in existing client buffer.
Ø Configurable delimiter character for rows and columns.
Ø Option to consider the first line as column header.
Ø In ElegantJ HTTP Text Data Access component, you can retrieve and store column names in data access component.
Ø Ready to use methods for insert, delete, modify, retrieve, filter and sort operations on data stored in data access component.
Ø Modified data (with or without filter) can be exported to any database, XML file or Text file.
Ø This JavaBean sends a notification to the user whenever a record is changed, inserted, updated or deleted.
ElegantJ FTP Text Data Access Component provides interface to carry out operations on data from remote FTP servers, and use it within any ElegantJ data aware beans or other Java programs / components which implement this data access interface. You can view, insert, update and delete text file contents via FTP protocol using this powerful JavaBean. Features of ElegantJ FTP Text Data Access component are:
Ø This JavaBean connects to any FTP server.
Ø Reads from remote file.
Ø Can parse data with fixed column size or with delimiter.
Ø Option to skip lines from begin of file while importing data from text file.
Ø ElegantJ FTP Text Data Access component offers configurable fetch size to fetch records.
Ø Option to append or replace fetched data in existing client buffer.
Ø Configurable delimiter character for rows and columns.
Ø Option to configure first line as column header is available in this JavaBean.
Ø Column names can be retrieved and stored in Data Access component.
Ø Ready to use methods for insert, delete, modify, retrieve, filter and sort operations on data stored in data access component.
Ø Modified data (with or without filter) can be exported to any database, XML file or Text file using this JavaBean.
Ø ElegantJ FTP Text Data Access component sends notification to the user whenever a record is changed, inserted, updated or deleted.
3.2.3ElegantJ XML Data Access Component
ElegantJ XML Data Access component provides interface to perform data operation on XML file based on DTD. It parses XML format to give data to viewer. It saves manipulated data in XML format. Features of ElegantJ XML Data Access component are:
Ø Reads data from local machine or from remote machine via its URL.
Ø This JavaBean can parse an XML file by user-defined tags (identifiers of root, row and column).
Ø Option to skip lines from beginning of file while importing data from text file.
Ø ElegantJ XML Data Access component provides an option to consider the first line as column header.
Ø Column names can be retrieved and stored in data access component.
Ø Ready to use methods for insert, delete, modify, retrieve, filter and sort operations on data stored in data access components.
Ø Modified data (with or without filter) can be exported to any database, XML file or Text file.
Ø This JavaBean sends a notification to user whenever a record is changed, inserted, updated or deleted.
Extracted file(archive) contains demos directory. All the demos are located in this demos directory.
Your classpath environment variables must be set correctly in order to run the demos. For windows users we have provided rundemo.bat file which will run demo directly. All Demo Applets contain HTML file to run an Applet associated with it.
For more information on how to set classpath, refer Installation procedure.
AWT Data Table demo application
Description: Demonstrates ElegantJ AWT Data Table application. Here, TextDataProvider is bound with it to populate AWT Data Table directly from text file.
To run this demo application,
Go to ElegantJDataTables\demos\applications\awt\demo1 directory, then execute
java -jar tablesawtapp.jar command.
AWT Data Table demo application using Cell Renderers and Cell Editors
Description: Demonstrates ElegantJ AWT Data Table application. Various Cell Renderers and Cell Editors are applied. Data is populated in AWT Data Table directly from text file using TextDataProvider.
To run this demo application,
Go to ElegantJDataTables\demos\ applications\awt\demo2 directory, then execute java -jar tablesawtapp.jar command.
JFC Data Table demo application
Description: Demonstrates ElegantJ JFC Data Table application. Here TextDataProvider is bound with it to populate JFC Data Table directly from text files.
To run this demo application,
Go to ElegantJDataTables\demos\applications\jfc\demo directory, then execute java -jar tablesjfcapp.jar command.
Note: For windows users, we
have provided the rundemo.bat file to run respective demo application.
Before installing ElegantJBeans, please ensure that your computer system and development environment are setup and working as per expectations. Person evaluating ElegantJBeans is expected to be able to write and execute simple JAVA applications.
We provide free pre-purchase technical support to help you complete process of evaluation. Mail to support@elegantJBeans.com for pre-purchase technical support.
To be able to use ElegantJBeans, your computer systems are required to have -
Ø An IDE that supports Java 2 or higher, or
Ø JDK 1.2.2 or higher
Please note that evaluation version of ElegantJBeans cannot be deployed for commercial, non-commercial or any other purpose in any possible way. You may not build any software, applets or applications for distribution with evaluation version of ElegantJBeans.
This evaluation version is to be solely used by you to evaluate suitability of ElegantJbeans for your needs. For more details please go through License Agreement.
On extracting ejdatatables_v1.zip, following directories will be created inside ElegantJDataTables directory-
Directory [jars] contains Jar file(s)
Directory [demos] contains demo application(s) with source code
Directory [docs] contains path for document(s) access
Installing on Windows 95/98
To include ElegantJ Beanery in CLASSPATH, add following statement to your autoexec.bat file,
set CLASSPATH= %CLASSPATH%;C:\ELEGANTJ\<ELEGANTJ_BENARY_HOME>
\jars\<ELEGANTJ_BEAN>.jar;
Restart Windows to make changes effective.
Installing on Windows NT / 2000
Go to Control Panel and select System. You will find environment variables on Environment tab in Windows NT systems and on Advanced tab in Windows 2000 systems.
Find CLASSPATH environment variable or create it.
To include ElegantJ Beanary in the CLASSPATH, specify or add following value for variable -
[EXISTING-CLASSES];C:\<ELEGANTJ_BEANARY_HOME>\jars\<ELEGANTJ_BEAN>.jar
Installing on UNIX / Linux
Before you begin using ElegantJ Beanary, you must manually configure CLASSPATH environment variable. CLASSPATH must point to the location of classes and installation directory.
For example, to set CLASSPATH for ElegantJ Beanary,
setenv CLASSPATH .:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/
<ELEGANTJ_BEAN>.jar:
If you are using Bourne Shell, commands are,
CLASSPATH= $CLASSPATH:.:/usr/local/<ELEGANTJ_BEANARY_HOME>/jars/
<ELEGANTJ_BEAN>.jar:export CLASSPATH
Follow the steps given below to create a new category and install Bean into Borland JBuilder.
Create a New Category
Ø Click menu Tools > Configure Palette. It opens Palette Properties dialog box.
Ø Click Add button. It opens Add Page Dialog box. Specify name (for example ElegantJ) and click OK. New Category gets created.
Create New Library and Install / Import Bean
Ø On Palette Properties dialog box, click Pages tab. Select Newly created page (for example ElegantJ).
Ø Click button Select Library. Select a Different Library dialog box opens.
Ø Click New button on Select a Different Library dialog box. New Library Wizard dialog box opens.
Ø Specify name for library and click Add button. Select One or More Directory dialog box opens.
Ø Select directory where jar files are located, or select jar file to be imported. Click OK. Dialog box gets closed and New Library Wizard dialog box appears in front.
Ø Click OK on New Library Wizard. It opens Select a Different Library dialog box.
Ø Confirm that newly created library is selected. Click OK. It opens Add Components under Palette Properties.
Ø Click Add from Selected Libraries button. It opens Results dialog box, click OK.
Ø Results dialog box disappears. Click OK on Palette Properties dialog box.
Ø Beans are ready to use.
Follow the steps given below to import ElegantJBeans in Oracle JDeveloper.
To Import beans into a project
Ø Click menu Project > Project Settings. It opens Project Settings dialog box.
Ø Click Libraries entry appearing on the pane on left side.
Ø Click New button. It opens New Library dialog box.
Ø In Library Name entry box, specify Library name. In Location entry box, specify location where you want the library to be located. In Class Path entry box, specify path of jar file of Bean. Browse the location by clicking Edit... button if required.
Ø Click OK. The library you selected appears in Available Libraries list of Project Properties dialog box.
Ø Select the library you want and click > button to add it to Selected Libraries list.
Ø Click menu Tools > Configure Component Palette. It opens Configure Component Palette dialog box.
Ø To create a new palette page, click New Page... button. It opens New Palette Page dialog box. Specify Page Name and Page Type. Click OK. A new page with specified name will be created.
To add component to page
Ø On Configure Component dialog box, from Pages list, select the page and click Add Component button. It opens Add JavaBeans dialog box with available libraries.
Ø Select a library from Library combo box.
Ø Browse the hierarchy and select a component. It displays preview of icon for selected component. Click OK. It shows Palette Confirmation dialog box.
Ø Click Yes on Palette Confirmation dialog box to complete the process.
Ø Beans are ready to use.
You can purchase a license from our web site www.elegantJBeans.com
You can also contact our sales team sales@elegantJBeans.com
On purchasing a license, you will receive a mail having your license key.
License key can be applied to ElegantJ JavaBean using any of the following ways,
Ø Using with Graphical User Interface of IDE
Ø Using directly with source code
While Designing an application or an applet graphically in an Integrated Development Environment, you will find a property named licensekey along with other properties of the bean. Specify key (serial number) in LicenseKey Property.
Note: Instead of typing the
license key, we suggest you to copy the license key from mail and paste it at
required place. Make sure that the
selection does not have any leading or trailing spaces.
When you use the Bean within code, you need to set the key by providing value in setLicenseKey Method.
Note: Instead of typing the
license key, we suggest you to copy the license key from mail and paste it at
required place. Make sure that the
selection does not have leading or trailing spaces.
ClassName object = new ClassName();
object.setLicenseKey("LICENSE_KEY");
Example
AWTTree awtTree = new AWTTree();
awtTree.setLicenseKey("LICENSE_KEY");
6.1.1.1 Creating an instance of AWTDataGrid
ElegantJ AWTDataGrid can be instantiated in following ways,
First way
com.elegantj.data.dataviewer.awt.table.AWTDataGrid awtDataGrid = new com.elegantj.data.dataviewer.awt.table.AWTDataGrid();
This creates AWTDataGrid with row count as zero, columns count as zero and enables the printing support.
Second way
int rowCount = 10;
int columnCount = 5;
boolean isAllowPrinterSupport = false;
com.elegantj.data.dataviewer.awt.table.AWTDataGrid awtDataGrid = new com.elegantj.data.dataviewer.awt.table.AWTDataGrid(rowCount, columnCount, isAllowPrinterSupport);
which creates AWTDataGrid with specified row count, column count and whether printer support is required or not.
6.1.1.2 Applying general formatting features
AWTDataGrid has following general formatting features:
Ø Font
Ø Background
Ø Foreground
Ø Visible
Ø Enable
Ø Locale
Ø Cursor
Ø Bounds
Ø Border
Ø To set Font,
awtDataGrid.setFont (new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); // sets font size to dialog, plain and of size 12
Ø To set Background,
awtDataGrid.setBackground(java.awt.Color.cyan); // sets background color as cyan
Ø To set Foreground,
awtDataGrid.setForeground(java.awt.Color.black); // sets foreground color as black
Ø To set Visibility,
awtDataGrid.setVisible(true); // sets visibility to true - makes table visible
Ø To set Enability,
awtDataGrid.setEnabled(true); // sets the enability to true - to make changes in table possible
Ø To set Locale,
awtDataGrid.setLocale(java.util.Locale.ENGLISH); // sets locale to english
Ø To set Cursor,
awtDataGrid.setCursor
(new java.awt.Cursor
(java.awt.Cursor.HAND_CURSOR)); // sets the cursor to hand cursor
Ø To set Bounds,
int
x = 5;
int
y = 5;
int
width = 300;
int
height = 200;
awtDataGrid.setBounds(x, y, width, height); // sets bounds to x, y, width and height
Ø To set Border,
awtDataGrid.setBorder(new
com.elegnatj.editors.AWTBorder
(com.elegnatj.editors.AWTBorder.SIMPLE,
2, java.awt.Color.black));
// sets border to simple, point size = 2 and border color is black
6.1.1.3 Applying advanced features of formatting and appearance
Following properties can be set for entire table
Ø BackgroundNonSelectionColor
Ø BackgroundSelectionColor
Ø TextNonSelectionColor
Ø TextSelectionColor
Ø BorderSelectionColor
Ø Font
Ø CellRenderer
Ø CellEditor
Ø To set BackgroundNonSelectionColor,
awtDataGrid.setBackgroundNonSelectionColor(java.awt.Color.cyan); // sets background non selection color as cyan
Ø To set BackgroundSelectionColor,
awtDataGrid.setBackgroundSelectionColor(java.awt.Color.blue); // sets background selection color as blue
Ø To set TextNonSelectionColor,
awtDataGrid.setTextNonSelectionColor(java.awt.Color.black); // sets text non selection color as black
Ø To set TextSelectionColor,
awtDataGrid.setTextSelectionColor(java.awt.Color.yellow); // sets text selection color as yellow
Ø To set BorderSelectionColor,
awtDataGrid.setBorderSelectionColor(java.awt.Color.red); // sets border selection color as red
Ø To set Font,
awtDataGrid.setFont
(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); // sets font for whole AWTDataGrid as Dialog, plain and of size 12
Ø To set cell renderer,
Here is a list of basic renderers shipped with this Bean -
Ø
com.elegantj.awt.table.TextRenderer
Ø
com.elegantj.awt.table.CheckboxRenderer
Ø
com.elegantj.awt.table.ChoiceRenderer
Ø
com.elegantj.awt.table.TextAreaWrapRenderer
Ø
com.elegantj.awt.table.TextAreaRenderer
com.elegantj.awt.table.CheckboxTableCellRenderer
renderer =
new
com.elegantj.awt.table.CheckboxTableCellRenderer();
awtDataGrid.setCellRenderer(renderer);
Ø To set cell editor,
Here is a list of basic editors shipped with Bean -
Ø
com.elegantj.awt.table.TextEditor
Ø
com.elegantj.awt.table.CheckboxEditor
Ø
com.elegantj.awt.table.ChoiceEditor
Ø
com.elegantj.awt.table.TextAreaEditor
com.elegantj.awt.table.CheckboxTableCellEditor
editor =
new
com.elegantj.awt.table.CheckboxTableCellEditor();
awtDataGrid.setCellEditor(editor);
Following attributes can also be set to specific row (s) or column (s) -
Ø BackgroundNonSelectionColor
Ø BackgroundSelectionColor
Ø TextNonSelectionColor
Ø TextSelectionColor
Ø BorderSelectionColor
Ø Font
Ø CellRenderer
Ø CellEditor
Ø To set BackgroundNonSelectionColor on row / column basic,
awtDataGrid.setRowBackgroundNonSelectionColorAt(0,
java.awt.Color.cyan);
awtDataGrid.setColumnBackgroundNonSelectionColorAt(0,
java.awt.Color.cyan);
This sets the background non selection color of row 0 and column 0 as cyan
Ø To set BackgroundSelectionColor on row / column basis,
awtDataGrid.setRowBackgroundSelectionColor(0,
java.awt.Color.blue);
awtDataGrid.setColumnBackgroundSelectionColor(0,
java.awt.Color.blue);
This sets the background selection color of row 0 and column 0 as blue
Ø To set TextNonSelectionColor,
awtDataGrid.setRowTextNonSelectionColor(0,
java.awt.Color.black);
awtDataGrid.setColumnTextNonSelectionColor(0,
java.awt.Color.black);
This sets text non selection color of row 0 and column 0 as cyan
Ø To set TextSelectionColor,
awtDataGrid.setRowTextSelectionColor(0,
java.awt.Color.yellow);
awtDataGrid.setColumnTextSelectionColor(0,
java.awt.Color.yellow);
This sets text selection color of row 0 and column 0 as yellow
Ø To set BorderSelectionColor,
awtDataGrid.setRowBorderSelectionColor(0,
java.awt.Color.red);
awtDataGrid.setColumnBorderSelectionColor(0,
java.awt.Color.red);
This sets border selection color of row 0 and column 0 as red
Ø To set Font,
awtDataGrid.setRowFontAt(0,
new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12));
awtDataGrid.setColumnFontAt(0,
new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12));
This sets font of row 0 and column 0 as Dialog, style as plain, size as 12.
Ø To set Cell Renderer,
Here is a list of basic renderers shipped with this Bean -
com.elegantj.awt.table.TextRenderer
com.elegantj.awt.table.CheckboxRenderer
com.elegantj.awt.table.ChoiceRenderer
com.elegantj.awt.table.TextAreaWrapRenderer
com.elegantj.awt.table.TextAreaRenderer
com.elegantj.awt.table.CheckboxTableCellRenderer
renderer = new
com.elegantj.awt.table.CheckboxTableCellRenderer();
awtDataGrid.setRowRendererAt(0,
renderer);
awtDataGrid.setColumnRendererAt(0,
renderer);
This sets renderer for row 0 and column 0 as checkbox.
Ø To set Cell Editor,
Here is a list of basic editors shipped with Bean -
com.elegantj.awt.table.TextEditor
com.elegantj.awt.table.CheckboxEditor
com.elegantj.awt.table.ChoiceEditor
com.elegantj.awt.table.TextAreaEditor
com.elegantj.awt.table.CheckboxTableCellEditor
editor =
new
com.elegantj.awt.table.CheckboxTableCellEditor();
awtDataGrid.setRowEditorAt(0,
editor);
awtDataGrid.setColumnEditorAt(0,
editor);
This sets the editor for row 0 and column 0 to checkbox.
6.1.1.4 Setting up row and column header
With AWTDataGrid, you can set following properties for header -
Ø Sort column on clicking column header
Ø Column/row Header background
Ø Column/row Header foreground
Ø Column/row Header font
Ø Column header height
Ø Row header width
Ø Column header visibility
Ø Row header visibility
Ø Column/row header cell renderer
Ø Column identifiers
Ø IsSizeColumnOnClick - which size column to best fit on clicking gap between two columns
Ø IsSizeRowOnClick - which size row to best fit on clicking gap between two columns
Ø To sort column on clicking column header
awtDataGrid.setSortColumnOnClick(true); // enables sorting of column on column header click
Ø To set header background,
awtDataGrid.setHeaderBackground(Color.gray); // sets header background as gray.
Ø To set header foreground,
awtDataGrid.setHeaderForeground(Color.black); // sets header foreground as black.
Ø To set header font,
awtDataGrid.setHeaderFont(new java.awt.Font("Dialog", Font.BOLD, 12)); // sets header font as dialog, style as bold and size as 12.
Ø To set column header height,
awtDataGrid.setColumnHeaderHeight(30); // sets column header height to 30
Ø To set row header width,
awtDataGrid.setRowHeaderWidth(50); // sets the row header width to 50.
Ø To set column header visibility,
awtDataGrid.setShowColumnHeader(false); // sets column header as invisible.
Ø To set row header visibility,
awtDataGrid.setShowRowHeader(false); // sets the row header invisible.
Ø To set header renderer,
com.elegantj.awt.table.CheckboxTableCellRenderer
renderer =
new
com.elegantj.awt.table.CheckboxTableCellRenderer();
awtDataGrid.setHeaderCellRenderer(renderer);
This sets the header renderer as checkbox.
Ø To set column identifier at the specified index,
awtDataGrid.setColumnIdentifierAt("column 1", 1); // sets the identifier for the column at index 1.
Ø To set column identifiers for all the columns,
java.util.Vector
columnIdentifiers =
new
java.util.Vector();
columnIdentifiers.addElement("column
1");
columnIdentifiers.addElement("column
2");
columnIdentifiers.addElement("column
3");
awtDataGrid.setColumnIdentifiers(columnIdentifiers);
This sets identifiers for all columns.
Ø To enable sizing of specified column to best fit on double clicking area between two columns,
awtDataGrid.setSizeColumnOnClick(true); // enables resizing of column on double click on area between two columns.
Ø To enable sizing of specified row to best fit on double clicking area between two rows,
awtDataGrid.setSizeRowOnClick(true); // enables the sizing of row to best fit on double clicking area between two rows.
6.1.1.5 Configuring cell renderers and cell editors
Using AWTDataGrid, you can apply any cell renderer / cell editor to entire table, row wise, as well as column wise.
Here is a list of basic renderers shipped with this Bean -
Ø com.elegantj.awt.table.TextRenderer
Ø com.elegantj.awt.table.CheckboxRenderer
Ø com.elegantj.awt.table.ChoiceRenderer
Ø com.elegantj.awt.table.TextAreaWrapRenderer
Ø com.elegantj.awt.table.TextAreaRenderer
Here is a list of basic editors shipped with Bean -
Ø com.elegantj.awt.table.TextEditor
Ø com.elegantj.awt.table.CheckboxEditor
Ø com.elegantj.awt.table.ChoiceEditor
Ø com.elegantj.awt.table.TextAreaEditor
Ø To set cell renderer for whole table,
com.elegantj.awt.table.CheckboxTableCellRenderer renderer =
new com.elegantj.awt.table.CheckboxTableCellRenderer();
awtDataGrid.setCellRenderer(renderer);
This sets checkbox as a cell renderer for whole table.
Ø To set cell editor for whole table,
com.elegantj.awt.table.CheckboxTableCellEditor editor =
new com.elegantj.awt.table.CheckboxTableCellEditor();
awtDataGrid.setCellEditor(editor);
This sets checkbox as a cell editor for whole table.
Ø To set cell renderer for specific row,
com.elegantj.awt.table.CheckboxTableCellRenderer renderer =
new com.elegantj.awt.table.CheckboxTableCellRenderer();
awtDataGrid.setRowRendererAt(0, renderer);
This sets checkbox as a cell renderer for row 0.
Ø To set cell renderer for specific column,
com.elegantj.awt.table.CheckboxTableCellRenderer renderer =
new com.elegantj.awt.table.CheckboxTableCellRenderer();
awtDataGrid.setColumnRendererAt(0, renderer);
This sets checkbox as a cell renderer for column 0.
Ø To set cell editor for specific row,
com.elegantj.awt.table.CheckboxTableCellEditor editor =
new com.elegantj.awt.table.CheckboxTableCellEditor();
awtDataGrid.setRowRendererAt(0, editor);
This sets checkbox as a cell editor for row 0.
Ø To set cell editor for specific column,
com.elegantj.awt.table.CheckboxTableCellEditor editor =
new com.elegantj.awt.table.CheckboxTableCellEditor();
awtDataGrid.setColumnRendererAt(0, editor);
This sets checkbox as a cell editor for row 0.
Advanced Implementation for creating custom Cell Renderers
If you wish to use the custom component as cell renderer, Then you need to create your own class for cell renderer and follow following steps,
Ø extend the cell renderer (your own class for cell renderer) from desired component,
Ø implement com.elegantj.awt.table.TableCellRenderer and then,
Ø override paint(java.awt.Graphics g) method, which is called internally to paint the custom renderer.
6.1.1.6 Implementing row – column resizing functionalities
Using AWTDataGrid, you can carry out resizing activity from -
Ø Resizing from Column header
Ø Resizing from Row header
Ø Resizing from Cells
Ø To enable resizing from column header,
awtDataGrid.setResizeFromColumnHeader(true); // enables resizing from column header
Ø To enable resizing from row header,
awtDataGrid.setResizeFromRowHeader(true); // enables resizing from row header.
Ø To enable the resizing from cells,
awtDataGrid.setResizeFromCells(true); // enables the resizing from cells.
6.1.1.7 Setting actions for key strokes
Here is a list of key strokes available (for carrying out operations) for use on a cell of AWTDataGrid -
Ø INSERT - for inserting row on insert key
Ø DELETE - for deleting row on delete key
Ø ENTER - for adding row on enter key at the last row position
Ø To enable use of Insert key to inserting a row,
awtDataGrid.setInsertRowOnInsertKey(true);
Ø To enable use of delete key to delete a row,
awtDataGrid.setDeleteRowOnDeleteKey(true);
Ø To enables the adding row on enter key,
awtDataGrid.setAddRowOnEnterKey(true); // this enables adding of row on enter key, it works on last row only.
6.1.1.8 Working with selection and selection style
AWTDataGrid provides two types of selection -
Ø Single selection - com.elegantj.awt.table.SINGLE_SELECTION
Ø Single range selection –
com.elegantj.awt.table.SINGLE_RANGE_SELECTION
Ø To set selection style,
awtDataGrid.setSelectionStyle(com.elegantj.awt.table.awtDataGrid.SINGLE_SELECTION); // sets selection as single selection
Ø To select row(s),
awtDataGrid.setRowSelectionInterval(0, 5); // sets rows 0 to 5 both inclusive as selected
Ø To select column(s),
awtDataGrid.setColumnSelectionInterval(2, 5); // sets columns 2 to 5 inclusive as selected
Ø To clear selection,
awtDataGrid.clearSelection(); // sets selected part of table as not selected.
6.1.1.9 Setting up editing functionalities
Ø To set row editability,
awtTabe.setRowEditableAt(0, false); // sets row 0 as not editable
Ø To set column editability,
awtDataGrid.setColumnEditableAt(0, false); // sets column 0 as not editable
Ø To start editing,
awtDataGrid.startEditing(); // start editing of AWTDataGrid
Ø To stop editing,
awtDataGrid.stopEditing(); // stop editing of AWTDataGrid
Ø To cancel editing,
awtDataGrid.cancelEditing(); // cancel editing of AWTDataGrid
Ø To check if table is currently being edited,
boolean isEditing = awtDataGrid.isEditing(); // checks if table is currently being edited
Ø To retrieve row / column that is currently being edited,
int editingRow = awtDataGrid.getEditingRow(); // retrieves row that is currently being edited
int editingColumn = awtDataGrid.getEditingColumn(); // retrieve column that is currently being edited
6.1.1.10 Setting up row heights
Ø To set default row height for whole table,
awtDataGrid.setDefaultRowHeight(18); // sets default row height as 18 for whole table
Ø To set row height for a specific row,
awtDataGrid.setRowHeightAt(0, 18); // sets row height as 18 pixels for row at 0th index
Ø To set the default minimum row height for whole table,
awtDataGrid.setDefaultMinimumRowHeight(5); // sets default minimum row height as 5 pixels for whole table
Ø To set the minimum row height for a specific row,
awtDataGrid.setMinimumRowHeightAt(0, 5); // sets minimum row height as 5 pixels for row at 0th index
Ø To set the default maximum row height for whole table,
awtDataGrid.setDefaultMaximumRowHeight(30); // sets default maximum row height as 30 pixels for whole table
Ø To set the maximum row height for a specific row,
awtDataGrid.setMaximumRowHeightAt(0, 30); // sets maximum row height as 30 pixels for row at 0th index.
6.1.1.11 Setting up column widths
Ø To set default column width for whole table,
awtDataGrid.setDefaultColumnWidth(100); // sets default column width to 100 pixels for whole table
Ø To set column width for specified column,
awtDataGrid.setColumnWidthAt(0, 100); // sets the column width to 100 pixels for column at 0th index
Ø To set default minimum columm height for whole table,
awtDataGrid.setDefaultMinimumColumnWidth(5); // sets default minimum column width to 5 pixels for whole table
Ø To set the minimum column width for selected column,
awtDataGrid.setMinimumColumnWidthAt(0, 5); // sets minimum column width to 5 pixels for column at 0th index.
Ø To set the default maximum column width for the whole table,
awtDataGrid.setDefaultMaximumColumnWidth(300); // sets default maximum column width to 300 pixels for whole table.
Ø To set the maximum column width for particular column,
awtDataGrid.setMaximumColumnWidthAt(0, 300); // sets maximum column width to 300 pixels for column at 0th index
6.1.1.12 Setting up grid properties
With ElegantJ AWTDataGrid you can set following properties for grid,
Ø Grid color
Ø Show horizontal grid
Ø Show vertical grid
Ø Horizontal gap
Ø Vertical gap
Ø To set grid color,
awtDataGrid.setGridColor(java.awt.Color.black); // sets the grid color as black
Ø To set visibility of horizontal grid,
awtDataGrid.setShowHorizontalGrid(false); // makes horizontal grid invisible
Ø To set visibility of vertical grid,
awtDataGrid.setShowVerticalGrid(false); // makes vertical grid invisible
Ø To set horizontal gap between two cell,
awtDataGrid.setHorzGap(2); // sets horizontal gap between two cells to 2.
Ø To set vertical gap between two cell,
awtDataGrid.setVertGap(2); // sets vertical gap between two cells to 2.
6.1.1.13 Configuring search panel
Ø To set search panel's visibility,
awtDataGrid.setSearchPanelVisible(false); // makes search panel visible
Ø To set background of search panel,
awtDataGrid.setSearchPanelBackground(java.awt.Color.gray); // sets background color of search panel as gray
Ø To set foreground of search panel,
awtDataGrid.setSearchPanelForeground(java.awt.Color.black); // sets foreground color of search panel as black
Ø To set font property of search panel,
awtDataGrid.setSearchPanelFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12)); // sets search panel font as dialog, style as bold
Ø To set location of search panel,
ElegantJ AWTDataGrid supports following tow search panel placements
Ø com.elegantj.awt.table.awtDataGrid.TOP - To place it at the top
Ø com.elegantj.awt.table.awtDataGrid.BOTTOM - To place it at the bottom
Ø To set search panel location to top
awtDataGrid.setSearchPanelLocation(com.elegantj.awt.table.awtDataGrid.TOP); // sets search panel location to top.
6.1.1.14 Searching for information
Ø To search for specified text with case sensitivity or case insensitivity,
String
searchText = "search text";
boolean
isCaseSensitive = false;
int[]
rowColumnIndexes = awtDataGrid.search(searchText, isCaseSensitive);
This searches whole AWTDataGrid for specified text in case insensitive manner. If specified search text is found, it returns row and column indexes of the cell which contains search text.
Ø To search specified column for the specified text,
String
searchText = "search text";
int
searchOnColumn = 0;
boolean
isCaseSensitive = false;
int[]
rowColumnIndexes = awtDataGrid.search(searchText, searchOnColumn,
isCaseSensitive);
This searches column at index 0 for specified text in case insensitive manner. If specified search text is found, it returns row and column indexes of the cell which contains the search text.
ElegantJ AWTDataGrid supports following Search Options
|
Search Progress From |
Options for Search Progress |
|
First Cell |
com.elegantj.awt.table.awtDataGrid. SEARCH_FROM_FIRST_CELL |
|
Last Cell |
com.elegantj.awt.table.awtDataGrid. SEARCH_FROM_LAST_CELL |
|
Selected Cell, upwards |
com.elegantj.awt.table.awtDataGrid. SEARCH_FROM_SELECTED_CELL_TO_UP |
|
Selected Cell, downwards |
com.elegantj.awt.table.awtDataGrid. SEARCH_FROM_SELECTED_CELL_TO_DOWN |
ElegantJ AWTDataGrid supports following Comparison Options
|
Comparison requirement |
Options for comparison |
|
Search cell for value that starts with given search string |
com.elegantj.awt.table.awtDataGrid.STARTS_WITH |
|
Search cell for value that ends with given search string |
com.elegantj.awt.table.awtDataGrid.ENDS_WITH |
|
Search cell for value or its part equals given search string |
com.elegantj.awt.table.awtDataGrid.CONTAINS |
|
Search cell for value for given string for exact match |
com.elegantj.awt.table.awtDataGrid.EQUALS |
Ø To perform case sensitive search on specified column for specified search text, search option, comparison option,
String
searchText = "search text";
int
searchOption = com.elegantj.awt.table.awtDataGrid.SEARCH_FROM_FIRST_CELL;
int
comparisonOption = com.elegantj.awt.table.awtDataGrid.EQUALS;
int
searchOnColumn = 0;
boolean
isCaseSensitive = true;
int[]
rowColumnIndexes = awtDataGrid.search(searchText, searchOption,
comparisonOption, searchOnColumn, isCaseSensitive);
This performs case sensitive search on column at index 0, from first cell, for equals comparison option, for specified text. If specified search text is found, then it returns the row and column indexes of cell which contains specified search text.
Ø To perform case insensitive search on specified columns for specified search text, search option and comparison option,
String
searchText = "search text";
int
searchOption = com.elegantj.awt.table.awtDataGrid.SEARCH_FROM_FIRST_CELL;
int
comparisonOption = com.elegantj.awt.table.awtDataGrid.EQUALS;
int
searchOnColumns[] = new int[]{1, 2, 3};
boolean
isCaseSensitive = false;
int[]
rowColumnIndexes = awtDataGrid.search(searchText, searchOption,
comparisonOption, searchOnColumns, isCaseSensitive);
This performs case insensitive search on columns at index 1, 2 and 3, from first cell, for equals comparison option, for the specified text. If specified search text is found, then it returns the row and column indexes of the cell which contains search text.
6.1.1.15 Sorting of information
Ø To sort data in specified column,
int
columnIndex = 1;
awtDataGrid.sortColumn(columnIndex);
This sorts data in column at index 1 in ascending-descending-ascending-descending manner. That is, for the 1st time of calling, it sorts in ascending order, on 2nd time in descending order.
Ø To sort specified column in ascending or descending order,
int
columnIndex = 1;
boolean
sortingOrder = true; // i.e. ascending
awtDataGrid.sortColumn(columnIndex,
sortingOrder);
This sorts column at the index 1 in ascending order.
Ø To sort multiple columns,
int
columnIndexes[] = new int[]{1, 2, 3};
awtDataGrid.sortColumns(columnIndexes);
This sorts column at the index 1, 2 and 3 in ascending-descending-ascending-descending manner. That is, for the 1st time of calling it sorts in ascending order, on 2nd time in descending manner as on in this order.
Ø To sort multiple columns with specified sorting order,
int
columnIndexes[] = new int[]{1, 2, 3};
boolean
sortingOrders[] = new boolean[]{true, false, true};
awtDataGrid.sortColumns(columnIndexes,
sortingOrders);
This sorts the 1st column in ascending order, 2nd column in descending order and 3rd column in ascending order.
6.1.1.16 Setting visibility of popup menu
AWTDataGrid provides a ready to use popup menu, having following functionalities -
Ø Add row / column
Ø Insert row / column
Ø Remove row / column
Ø Edit cell
Ø Sort (ascending / descending) column
All the above popup menu operations takes place on selected row / column / cell.
Ø To set the visibility of the popup menu,
awtDataGrid.setShowPopupMenu(true); // allows to open the popup menu on right click.
6.1.1.17 Configuring data with AWTDataGrid
ElegantJ AWTDataGrid provides the following methods to configure data,
Ø To set data with specified 2-dimensional vector as data and 1-dimensional vector as column identifier,
java.util.Vector
data = new java.util.Vector();
java.util.Vector
row1Data = new java.util.Vector();
row1Data.addElement("cell11");
row1Data.addElement("cell12");
row1Data.addElement("cell13");
data.addElement(row1Data);
java.util.Vector
row2Data = new java.util.Vector();
row2Data.addElement("cell21");
row2Data.addElement("cell22");
row2Data.addElement("cell23");
data.addElement(row2Data);
java.util.Vector
row3Data = new java.util.Vector();
row3Data.addElement("cell31");
row3Data.addElement("cell32");
row3Data.addElement("cell33");
data.addElement(row3Data);
java.util.Vector
columnIdentifiers = new java.util.Vector();
columnIdentifiers.addElement("column1");
columnIdentifiers.addElement("column2");
columnIdentifiers.addElement("column3");
awtDataGrid.setData(data,
columnIdentifiers);
This sets data with specified 2-dimensional vector as data and 1-dimensional vector as column identifier.
Ø To set data with specified 2-dimensional object array as data and 1-dimensional object array as column identifier,
Object[][]
data = new Object[][]
{
{"cell11", "cell12", "cell13"},
{"cell21", "cell22", "cell23"},
{"cell31", "cell32", "cell33"}
};
Object[]
columnIdentifiers = new Object[] {"column1", "column2",
"column3"};
awtDataGrid.setData(data,
columnIdentifiers);
This sets specified 2-dimensional object array as data and 1-dimensional object array as column identifiers.
Ø To set data with 2-dimensional vector as data,
java.util.Vector
data = new java.util.Vector();
java.util.Vector
row1Data = new java.util.Vector();
row1Data.addElement("cell11");
row1Data.addElement("cell12");
row1Data.addElement("cell13");
data.addElement(row1Data);
java.util.Vector
row2Data = new java.util.Vector();
row2Data.addElement("cell21");
row2Data.addElement("cell22");
row2Data.addElement("cell23");
data.addElement(row2Data);
java.util.Vector
row3Data = new java.util.Vector();
row3Data.addElement("cell31");
row3Data.addElement("cell32");
row3Data.addElement("cell33");
data.addElement(row3Data);
awtDataGrid.setData(data);
This sets 2-dimensional vector as data.
Ø To set 2-dimensional object array as data,
Object[][]
data = new Object[][]
{
{"cell11", "cell12", "cell13"},
{"cell21", "cell22", "cell23"},
{"cell31", "cell32", "cell33"}
};
awtDataGrid.setData(data);
This sets the 2-dimensional object array as data.
6.1.1.18 Implementing paper size and paper type for printing
ElegantJ AWTDataGrid allow following paper sizes:
|
Paper Types |
Paper Types |
|
A2_ENVELOP_TYPE |
A4_TYPE |
|
A5_TYPE |
A6_CARD_TYPE |
|
B5_TYPE |
C6_ENVELOP_TYPE |
|
CUSTOM_TYPE |
DL_ENVELOP_TYPE |
|
EXECUTIVE_TYPE |
HAGAKI_CARD_TYPE |
|
INDEX_CARD_4x6_TYPE |
INDEX_CARD_5x8_TYPE |
|
LEGAL_TYPE |
LETTER_TYPE |
|
N010_ENVELOP_TYPE |
CUSTOM_TYPE |
Ø To set paper type,
awtDataGrid.setPaperType(com.elegantj.awt.table.awtDataGrid // sets paper type as A4
If paper type as set as CUSTOM_TYPE, then you need to set paper width and height explicitly using following methods,
awtDataGrid.setPaperType(com.elegantj.awt.table.awtDataGrid.CUSTOM_TYPE); awtDataGrid.setPaperSize(10, 8); // sets paper width as 8 inch and height as 10 inch
Ø To retrieve paper width and paper height,
int paperWidth = awtDataGrid.getPaperWidth(); // returns the paper width in inches
int paperHeight = awtDataGrid.getPaperHeight(); // returns the paper height in inches
To retrieve imageable paper width and height, imageable paper width and height are size of paper on to which printing can be done.
int
imageablePaperWidth = awtDataGrid.getImageablePaperWidth();
int
imageablePaperHeight = awtDataGrid.getImageablePaperHeight();
Ø To retrieve actual paper width and height, actual paper width and height are width and height of the paper in which left, right, top and bottom margins are not included.
int
actualPaperWidth = awtDataGrid.getActualPaperWidth();
int
actualPaperHeight = awtDataGrid.getActualPaperHeight();
6.1.1.19 Setting up margins and header and footer for printing
Setting up Margins and Header and footer for Printing
Ø To set left, right, top and bottom margins,
printer.setLeftMargin(1); // margin in inches
printer.setRightMargin(1); // margin in inches
printer.setTopMargin(1); // margin in inches
printer.setBottomMargin(1); // margin in inches
printer.setTopMargin(1); // margin in inches
printer.setBottomMargin(1); // margin in inches
printer.setTopMargin(1); // margin in inches
printer.setBottomMargin(1); // margin in inches
Ø To set left, center, right header and footer,
printer.setLeftHeader("left header"); // sets left header
printer.setCenterHeader("center header"); // sets center header
printer.setRightHeader("right header"); // sets right header
printer.setLeftFooter("left footer"); // sets left footer
printer.setCenterFooter("center footer"); // sets center footer
printer.setRightFooter("right footer"); // sets right footer
Note: You can use following
string constants with header / footer
Ø
Printer.CURRENT_DATE
Ø
Printer.CURRENT_TIME
Ø
Printer.PAGE_NO
Ø
Printer.TOTAL_PAGES
Ø To set current date in header / footer,
setXXXYYY("Date: "+com.elegantj.util.printer.Printer.CURRENT_DATE);
Ø To set current time in header/footer,
setXXXYYY("Date:
"+com.elegantj.util.printer.Printer.CURRENT_TIME);
Ø To set page no. in header/footer,
setXXXYYY("Page
No.: "+com.elegantj.util.printer.Printer.PAGE_NO);
Ø To set page no./total no. of pages,
setXXXYYY("Page:
" + com.elegantj.util.printer.Printer.PAGE_NO + " of " +
com.elegantj.util.printer.Printer.TOTAL_PAGES);
where XXX is Left/Right and YYY = Header/Footer
6.1.1.20 Setting page orientation for printing
Ø To set page orientation,
Orientation can be set as Printer.LANDSCAPE for landscape and Printer.PORTRAIT for portrait.
awtDataGrid.setPageOrientation(com.elegantj.awt.table.awtDataGrid.LANDSCAPE); // sets orientation as landscape
6.1.1.21 Setting number of copies for printing
Ø To set number of copies,
awtDataGrid.setNoOfCopies(5); // sets number of copies as 5. This will print 5 copies of each page
6.1.1.22 Setting line below header and line above footer for printing
Ø To show a line below header and line above footer,
awtDataGrid.setShowLineBelowHeader(true); // which shows a line below header
awtDataGrid.setShowLineAboveFooter(true); // which shows a line above footer
6.1.1.23 Doing page setup for printing
ElegantJ AWTDataGrid provides ready-to-use Page Setup dialog using which user can,
Ø change the left, right, top and bottom margins
Ø set the left, center, right header and footer
Ø set the paper type and paper size
Ø set the page orientation
Ø set no. of copies
Ø turn on/off the line below header and above footer
Ø To open the page setup dialog,
awtDataGrid.pageSetup(); // displays the page setup dialog
or
awtDataGrid.pageSetup(jFrame); // displays the page setup dialog with jFrame as parent
6.1.1.24 Opening print preview for printing
ElegantJ AWTDataGrid provides much needed preview feature. It supports Zoom In, Zoom Out and easy navigation through all the pages.
Ø To open Print Preview dialog,
awtDataGrid.preview(); // displays preview dialog
or
awtDataGrid.preview(jFrame); // displays preview dialog with jFrame as parent
The Process of Printing
Ø To print all the pages
awtDataGrid.print(); // prints all the pages
6.1.1.25 Handling bulk print jobs (by controlling spool size)
Pages are spooled before they are printed. Spooling will take long time if number of pages is more. You can control spool size by printing books individually (at a time). Next two points focuses on how you can control spool size.
Ø Print book individually, and
Ø Book size
Ø Print book individually
Printing of large number of pages takes long time for spooling followed by printing. To reduce delay in printing due to this, it is suggested to print books individually.
Set value of this property to True to stop spooling of entire print job. As a result of this, computer spools a pre-set number of pages (user configurable) and prints it. It print books individually. Each book contains number of pages set as value of BookSize property.
printer.setPrintBookIndividually(true);
Ø Book Size
If PrintBookIndividually property is set to true, then value set in BookSize property is considered for spooling. This way a large print job is divided into smaller print jobs known as individual books.
printer.setPrintBookIndividually(true);
printer.setBookSize(5);
// does not spool all the pages, considers 5 pages per book
e.g.
Divide a 200 page print job in 20 smaller jobs of 10 pages each. This will enable JAVA application to print this big job smoothly without any spooling delays or network congestions.
Printing large number of pages takes long time for spooling followed by printing. To stop spooling, print books individually.
If the value of this property is true, then printer does not spool all the pages before starting to print. It prints books individually. Each book contains number of pages set as value of BookSize property.
6.1.1.26 Implementing printing – methods to use
1. print()
This method prints all pages.
printer.print();
2. print(int pageIndex)
This method prints specified page with pageIndex, pageIndex is zero based page index. This method starts printing without showing print dialog.
printer.print(pageIndex)
3. print(int startPageIndex, int endPageIndex)
This method prints pages range specified with startPageIndex and endPageIndex, both page indexes are inclusive. This method starts printing without showing print dialog.
printer.print(startPageIndex, endPageIndex);
4. print(FileInputStream fis)
This method prints content of FileInputStream on printer target port.
printer.print(fileInputStream);
5. print(FileInputStream fis, String port)
This method prints content of FileInputStream, on specified printer target port.
printer.print(fileInputStream, port);
6. print(byte[] bytes)
This method prints content of bytes array on printer target port.
printer.print(bytes);
7. print(byte[] bytes, String port)
This method prints content of bytes array, on specified printer target port.
printer.print(bytes, port);
6.1.1.27 Printer listeners and events
ElegantJ Printer provides the following event.
PrinterEvent which is invoked when the printing is going on.
6.1.1.28 AWTDataGrid listeners and events
|
Listener Name |
TableCellEditListener |
|
Event that it receives |
TableCellEditEvent |
|
When it fires |
Just before editing is started and after editing is completed. |
|
Listener Name |
TableCellResizeListener |
|
Event that it receives |
TableCellResizeEvent |
|
When it fires |
Any row or column of a table is resized. |
|
Listener Name |
TableColumnsAddedListener |
|
Event that it receives |
TableColumnsAddedEvent |
|
When it fires |
One or more columns are added to the table. |
|
Listener Name |
TableColumnsRemovedListener |
|
Event that it receives |
TableColumnsRemovedEvent |
|
When it fires |
One or more columns are removed from the table. |
|
Listener Name |
TableRowsAddedListener |
|
Event that it receives |
TableRowsAddedEvent |
|
When it fires |
One or more rows are added to the table |
|
Listener Name |
TableRowsRemovedListener |
|
Event that it receives |
TableRowsRemovedEvent |
|
When it fires |
One or more rows are removed from the table |
|
Listener Name |
TableSelectionListener |
|
Event that it receives |
TableSelectionEvent |
|
When it fires |
When selection is changed. |
|
Listener Name |
TableSortListener |
|
Event that it receives |
TableSortEvent |
|
When it fires |
Before sorting and after sorting is done through column header click. |
6.1.1.29 Configuring data access component with AWTDataGrid
You can use ElegantJ AWTDataGrid bean for data exchange from SQL data source, Text, HTTP, FTP or an XML data source. Use method setDataProvider to set a data access component. It also allows to bind data access component to other data viewer or any other data viewing components through method getDataProvider. Data access component provides data which is manipulated by data viewer through data navigator. For more information on ElegantJ data access components refer data access component Usage Matrix and data access component Objects for more information.
You will get following five data access components with this package -
Ø SqlDataProvider - can fetch data from database
Ø TextDataProvider - can fetch data from text (local or remote) file
Ø HTTPTextDataProvider - can fetch data from text file using HTTP protocol
Ø FTPTextDataProvider - can fetch data from text file using FTP protocol
Ø XMLDataProvider - can fetch data from XML files
Any of the above data access components can be easily binded with AWTDataGrid to fetch data from data source.
Ø To bind SqlDataProvider with AWTDataGrid,
String databaseURL = "jdbc:odbc:data";
String databaseDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "";
String password = "";
String sqlString = "select * from data_table";
com.elegantj.data.dataprovider.sql.SqlDataProvider sqlDataProvider =
new com.elegantj.data.dataprovider.sql.SqlDataProvider(); // instantiate the SqlDataProvider
sqlDataProvider.setConnectionProperties(new com.elegantj.data.editors.ConnectionProperties(databaseURL, databaseDriver, userName, password)); // sets the connection properties
sqlDataProvider.setSqlString(sqlString); // sets the sql string to data access component
awtDataGrid.setDataProvider(sqlDataProvider); // binds the SqlDataProvider to AWTDataGrid
awtDataGrid.retrieveData(); // retrieves the data from data access component
Ø To bind TextDataProvider with AWTDataGrid,
String
sourceFilePath = "c:\\data\\data.txt";
com.elegantj.data.dataprovider.text.TextDataProvider
textDataProvider =
new com.elegantj.data.dataprovider.text.TextDataProvider(); // instantiate the TextDataProvider
textDataProvider.setFile(sourceFilePath); // sets the source file path to the TextDataProvider
textDataProvider.setRowSeparator("\n"); // sets the row separator
textDataProvider.setColumnSeparator(","); // sets the column separator
textDataProvider.setTextQualifier("\""); // sets the text qualifier
textDataProvider.setFirstRowAsColumnNames(true); // set the first row as column names
awtDataGrid.setDataProvider(textDataProvider); // binds the TextDataProvider to AWTDataGrid
awtDataGrid.retrieveData(); // retrieves the data from data access component
Ø To bind HTTPTextDataProvider to AWTDataGrid,
java.net.URL
httpURL = new
java.net.URL("http://localhost/myfolder/myfile.txt");
String
httpMethod = "Get";
com.elegantj.data.dataprovider.http.HTTPTextDataProvider
httpTextDataProvider = new
com.elegantj.data.dataprovider.http.HTTPTextDataProvider(); //
instantiate the HTTPTextDataProvider
httpTextDataProvider.setURL(httpURL); // sets the URL
httpTextDataProvider.setMethod(httpMethod); // sets the HTTP-Method
httpTextDataProvider.setRowSeparator("\n"); // sets the row separator
httpTextDataProvider.setColumnSeparator(","); // sets the column separator
httpTextDataProvider.setTextQualifier("\""); // sets the text qualifier
httpTextDataProvider.setFirstRowAsColumnNames(true); // sets the first row as column names
awtDataGrid.setDataProvider(httpTextDataProvider); // binds the HTTPTextDataProvider to AWTDataGrid
awtDataGrid.retrieveData(); // retrieves the data from data access component
Ø To bind FTPTextDataProvider to AWTDataGrid,
String
hostName = "localhost";
int
portNo = 21;
String
userName = "user_name";
String
password = "password";
String
sourceFilePath = "data.txt";
com.elegantj.data.dataprovider.ftp.FTPTextDataProvider
ftpTextDataProvider = new
com.elegantj.data.dataprovider.ftp.FTPTextDataProvider(); // instantiate the FTPTextDataProvider
ftpTextDataProvider.setHostName(hostName); // sets the host name where FTP service is running
ftpTextDataProvider.setPort(portNo); // sets the portNo on which FTP service is running
ftpTextDataProvider.setUserName(userName); // sets the user name, required for the FTP login
ftpTextDataProvider.setPassword(password); // sets the password, required for the FTP login
ftpTextDataProvider.setFile(sourceFilePath); // sets the source file path
ftpTextDataProvider.setRowSeparator("\n"); // sets the row separator
ftpTextDataProvider.setColumnSeparator(","); // sets the column separator
ftpTextDataProvider.setTextQualifier("\""); // sets the text qualifier
ftpTextDataProvider.setFirstRowAsColumnNames(true); // sets the first row as column names
awtDataGrid.setDataProvider(ftpTextDataProvider); // binds the FTPTextDataProvider to AWTDataGrid
awtDataGrid.retrieveData(); // retrieves the data from data access component
Ø To bind XMLDataProvider with AWTDataGrid,
String
sourceFilePath = "c:\\data\\data.xml";
com.elegantj.data.dataprovider.xml.XMLDataProvider
xmlDataProvider =
new com.elegantj.data.dataprovider.xml.XMLDataProvider(); // instantiate the XMLDataProvider
xmlDataProvider.setFile(sourceFilePath); // sets the source file path to XMLDataProvider
xmlDataProvider.setRootTag("Report"); // sets the root tag
xmlDataProvider.setRowTag("Row"); // sets the row tag
xmlDataProvider.setColumnTag("Column"); // sets the column tag
xmlDataProvider.setFirstRowAsColumnNames(true) // set the first row as column names
awtDataGrid.setDataProvider(xmlDataProvider); // binds the XMLDataProvider to AWTDataGrid
awtDataGrid.retrieveData(); // retrieves the data from data access component
Note: For more information
on data access components, go through the programmers guide on data access
components section, of this documentation.
6.1.1.30 Handling Data Navigation
AWTDataGrid has functionality for data navigation. Functionalities include -
|
Where to move |
Function to use |
|
To first record |
FirstRecord |
|
To last record |
LastRecord |
|
To Next record |
NextRecord |
|
To previous record |
PreviousRecord |
|
To specified record |
ScrollToRow |
Ø To move the cursor to first record,
awtDataGrid.firstRecord(); // moves cursor to first record
Ø To move the cursor to last record,
awtDataGrid.lastRecord(); // moves cursor to last record
Ø To move the cursor to next record,
awtDataGrid.nextRecord(); // moves cursor to next record
Ø To move the specific row,
awtDataGrid.scrollToRow(5); // moves cursor to 5th record
6.1.1.31 Handling Data Modification
The following methods are used to modify data through data access component.
|
For what |
Function to use |
|
Refresh the table |
Refresh |
|
To add a default row to the end of the data |
AddRow |
|
To remove selected row |
DeleteRow |
Ø To refresh the table,
awtDataGrid.refresh(); // refreshes AWTDataGrid
Ø To add the row at the end of the data,
awtDataGrid.addRow(); // adds a row at the end of data
Ø To delete the selected row,
awtDataGrid.deleteRow(); // removes selected row
6.1.2.1 Creating an instance of DataGrid
Ø JFC Data Table can be created in the following two ways,
com.elegantj.data.dataviewer.jfc.table.DataGrid dataGrid = new com.elegantj.data.dataviewer.jfc.table.DataGrid();
This creates an instance of DataGrid.
6.1.2.2 Applying general formatting features
DataGrid has following general formatting features -
Ø Font
Ø Background
Ø Foreground
Ø Visible
Ø Enabled
Ø Locale
Ø Cursor
Ø Bounds
Ø Lightweight
Ø Opaque
Ø ToolTipText
Ø DoubleBuffered
Ø Autoscrolls
Ø RequestFocusEnabled
Ø Border
Ø ManagingFocus
Ø To set Font,
dataGrid.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12));
// sets fonts as Dialog, with style as plain, size 12
Ø To set Background,
dataGrid.setBackground(java.awt.Color.cyan); // sets background color as cyan
Ø To set Foreground,
dataGrid.setForeground(java.awt.Color.black); // sets foreground color as black
Ø To set Visibility,
dataGrid.setVisible(true); // which sets visibility as true
Ø To set Enability,
dataGrid.setEnabled(true); // sets enability as true
Ø To set Locale,
dataGrid.setLocale(java.util.Locale.ENGLISH); // sets locale as English
Ø To set Cursor,
dataGrid.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); // sets cursor as hand cursor
Ø To set Bounds,
int x = 5;
int y = 5;
int width = 300;
int height = 200;
dataGrid.setBounds(x, y, width, height); // sets bounds to x, y, width and height
Ø To set Lightweight,
dataGrid.setLightweight(true); // sets Lightweight as true
Ø To set Opaque,
dataGrid.setOpaque(true); // sets opaque as true
Ø To set Tooltip Text,
dataGrid.setTooltipText("DataGrid"); // sets TooltipText as "DataGrid"
Ø To set DoubleBuffered,
dataGrid.setDoubleBuffered(true); // enables double buffering
Ø To set AutoScrolls,
dataGrid.setAutoScrolls(true); // sets auto scrolls as true
Ø To set RequestFocusEnabled,
dataGrid.setRequestFocusEnabled(true); // sets request focus enabled as true
Ø To set Border,
javax.swing.Border lineBorder =
javax.swing.BorderFactory.createLineBorder(java.awt.Color.black);
dataGrid.setBorder(lineBorder); // sets border as black colored line border
Ø To set ManagingFocus,
dataGrid.setManagingFocus(true); // sets managing focus as true
6.1.2.3 Applying advanced formatting features for entire table
ElegantJ DataGrids provides the following advanced look & feel,
Ø BackgroundNonSelectionColor
Ø BackgroundSelectionColor
Ø TextNonSelectionColor
Ø TextSelectionColor
Ø BorderSelectionColor
Ø FocusCellBackgroundColor
Ø FocusCellForegroundColor
Ø Icon
Ø Font
Ø CellRenderer
Ø CellEditor
Ø Editable
Ø To set default BackgroundNonSelectionColor for whole table,
dataGrid.setDefaultBackgroundNonSelectionColor(java.awt.Color.cyan); // sets default background color as cyan for whole table
Ø To set default BackgroundSelectionColor for whole table,
dataGrid.setDefaultBackgroundSelectionColor(java.awt.Color.blue); // sets default background color as blue for whole table
Ø To set default TextNonSelectionColor for whole table,
dataGrid.setDefaultTextNonSelectionColor(java.awt.Color.black); // sets default text color as black for whole table
Ø To set default TextSelectionColor for whole table,
dataGrid.setDefaultTextSelectionColor(java.awt.Color.yellow); // sets default text selection color as yellow for whole table
Ø To set default BorderSelectionColor for whole table,
dataGrid.setDefaultBorderSelectionColor(java.awt.Color.red); // sets default border selection color to red for whole table
Ø To set default FocusCellBackgroundColor for whole table,
dataGrid.setDefaultFocusCellBackgroundColor(java.awt.Color.red); // sets default focus cell background color as red for whole table
Ø To set default FocusCellForegroundColor for whole table,
dataGrid.setDefaultFocusCellForegroundColor(java.awt.Color.blue); // sets default focus cell foreground color as blue for whole table
Ø To set default Font for whole table,
dataGrid.setDefaultFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); // sets default font as dialog font for whole table
Ø To set default image icon for whole table,
javax.swing.ImageIcon
imageIcon =
new
javax.swing.ImageIcon("c:/my_folder/image.jpg");
dataGrid.setDefaultIcon(imageIcon); // sets default icon for whole table
Ø To set default icon path for whole table,
dataGrid.setDefaultIconPath("c:/my_folder/image.jpg"); // sets default icon path for whole table
Ø To set default cell renderer for whole table,
Following cell renderers comes with the ElegantJ DataGrid beanary,
Ø Boolean cell renderer –
com.elegantj.jfc.common.renderers.BooleanRenderer
Ø Checkbox cell renderer –
com.elegantj.jfc.common.renderers.CheckboxRenderer
Ø Choice cell renderer –
com.elegantj.jfc.common.renderers.ChoiceRenderer
Ø Color cell renderer –
com.elegantj.jfc.common.renderers.ColorRenderer
Ø Date cell renderer –
com.elegantj.jfc.common.renderers.DateRenderer
Ø Default cell renderer –
com.elegantj.jfc.common.renderers.DefaultRenderer
Ø Icon cell renderer –
com.elegantj.jfc.common.renderers.IconRenderer
Ø MultiLine cell renderer –
com.elegantj.jfc.common.renderers.MultiLineRenderer
Ø MultiOption cell renderer –
com.elegantj.jfc.common.renderers.MultiOptionRenderer
Ø Number cell renderer –
com.elegantj.jfc.common.renderers.NumberRenderer
Ø Progress cell renderer –
com.elegantj.jfc.common.renderers.ProgressRenderer
Ø RadioButton cell renderer –
com.elegantj.jfc.common.renderers.RadioButtonRenderer
Ø Text cell renderer –
com.elegantj.jfc.common.renderers.TextRenderer
com.elegantj.jfc.common.renderers.CheckboxRenderer
checkboxRenderer =
new
com.elegantj.jfc.common.renderers.CheckboxRenderer();
dataGrid.setDefaultCellRenderer(checkboxRenderer); // sets the default renderer as checkbox for whole table
Ø To set default cell editor,
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
dataGrid.setDefaultCellEditor(checkboxEditor); // sets default editor as checkbox for whole table
Ø To set default editibality,
dataGrid.setDefaultEditable(new Boolean(false)); // sets whole table as not editable
6.1.2.4 Implementing advanced formatting features based on row and columns
DataGrid provides the following advanced formatting features to be set row and columns wise -
Ø BackgroundNonSelectionColor
Ø BackgroundSelectionColor
Ø TextNonSelectionColor
Ø TextSelectionColor
Ø BorderSelectionColor
Ø FocusCellBackgroundColor
Ø FocusCellForegroundColor
Ø Icon
Ø Font
Ø CellRenderer
Ø CellEditor
Ø Editable
Ø To set row / column wise BackgroundNonSelectionColor,
dataGrid.setRowBackgroundNonSelectionColor(java.awt.Color.cyan, 0); // sets background non selection color as cyan for row at 0th index
dataGrid.setColumnBackgroundNonSelectionColor(java.awt.Color.cyan, 0); // sets background non selection color as cyan for column at 0th index
Ø To set row / column wise BackgroundSelectionColor,
dataGrid.setRowBackgroundSelectionColor(java.awt.Color.blue, 0); // sets background selection color as blue for row at 0th index
dataGrid.setColumnBackgroundSelectionColor(java.awt.Color.blue, 0); // sets background selection color as blue for column at 0th index
Ø To set row / column wise TextNonSelectionColor,
dataGrid.setRowTextNonSelectionColor(java.awt.Color.black, 0); // sets text non selection color as black for row at 0th index
dataGrid.setColumnTextNonSelectionColor(java.awt.Color.black, 0); // sets text non selection color as black for column at 0th index
Ø To set row / column wise TextSelectionColor
dataGrid.setRowTextSelectionColor(java.awt.Color.yellow, 0); // sets text selection color as yellow for row at 0th index
dataGrid.setColumnTextSelectionColor(java.awt.Color.yellow, 0); // sets text selection color as yellow for column at 0th index
Ø To set row / column wise BorderSelectionColor
dataGrid.setRowBorderSelectionColor(java.awt.Color.red, 0); // sets border selection color as red for row at 0th index
dataGrid.setColumnBorderSelectionColor(java.awt.Color.red, 0); // sets border selection color as red for column at 0th index
Ø To set row / column wise FocusCellBackgroundColor
dataGrid.setRowFocusCellBackgroundColor(java.awt.Color.red, 0); // sets focus cell background color as red for row at 0th index
dataGrid.setColumnFocusCellBackgroundColor(java.awt.Color.red, 0); // sets focus cell background color as red for column at 0th index
Ø To set row / column wise FocusCellForegroundColor
dataGrid.setRowFocusCellForegroundColor(java.awt.Color.red, 0); // sets focus cell foreground color as red for row at 0th index
dataGrid.setColumnFocusCellForegroundColor(java.awt.Color.red, 0); // sets focus cell foreground color as red for column at 0th index
Ø To set row/column wise Font
dataGrid.setRowFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12), 0); // sets font as dialog, plain, 12 size for row at 0th index
dataGrid.setColumnFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12), 0); // sets font as dialog, plain, 12 size for column at 0th index
Ø To set row / column wise icon
javax.swing.ImageIcon
imageIcon = new
javax.swing.ImageIcon("c:/my_folder/image.jpg");
dataGrid.setRowIcon(imageIcon, 0); // sets icon for row at 0th index
dataGrid.setColumnIcon(imageIcon, 0); // sets icon for column at 0th index
Ø To set row / column wise icon path
dataGrid.setRowIconPath("c:/my_folder/image.jpg", 0); // sets icon path for row at 0th index
dataGrid.setColumnIconPath("c:/my_folder/image.jpg", 0); // sets icon path for column at 0th index
Ø To set row / column wise cell renderer
Following cell renderers comes with the ElegantJ DataGrid beanary,
Ø Boolean cell renderer –
com.elegantj.jfc.common.renderers.BooleanRenderer
Ø Checkbox cell renderer –
com.elegantj.jfc.common.renderers.CheckboxRenderer
Ø Choice cell renderer –
com.elegantj.jfc.common.renderers.ChoiceRenderer
Ø Color cell renderer –
com.elegantj.jfc.common.renderers.ColorRenderer
Ø Date cell renderer –
com.elegantj.jfc.common.renderers.DateRenderer
Ø Default cell renderer –
com.elegantj.jfc.common.renderers.DefaultRenderer
Ø Icon cell renderer –
com.elegantj.jfc.common.renderers.IconRenderer
Ø MultiLine cell renderer –
com.elegantj.jfc.common.renderers.MultiLineRenderer
Ø MultiOption cell renderer –
com.elegantj.jfc.common.renderers.MultiOptionRenderer
Ø Number cell renderer –
com.elegantj.jfc.common.renderers.NumberRenderer
Ø Progress cell renderer –
com.elegantj.jfc.common.renderers.ProgressRenderer
Ø RadioButton cell renderer –
com.elegantj.jfc.common.renderers.RadioButtonRenderer
Ø Text cell renderer –
com.elegantj.jfc.common.renderers.TextRenderer
com.elegantj.jfc.common.renderers.CheckboxRenderer
checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();
dataGrid.setRowCellRenderer(checkboxRenderer, 0); // sets checkbox as a cell renderer for row at 0th index
dataGrid.setColumnCellRenderer(checkboxRenderer, 0); // sets checkbox as a cell renderer for column at 0th index
Ø To set row/column wise cell editor
Following cell editors come with the ElegantJ DataGrid benary,
Ø Boolean cell editor –
com.elegantj.jfc.common.editors.BooleanEditor
Ø Checkbox cell editor –
com.elegantj.jfc.common.editors.CheckboxEditor
Ø Choice cell editor - com.elegantj.jfc.common.editors.ChoiceEditor
Ø Color cell editor - com.elegantj.jfc.common.editors.ColorEditor
Ø Date
cell editor - com.elegantj.jfc.common.editors.DateEditor
Ø Default
cell editor - com.elegantj.jfc.common.editors.DefaultEditor
Ø Icon
cell editor - com.elegantj.jfc.common.editors.IconEditor
Ø MultiLine cell editor –
com.elegantj.jfc.common.editors.MultiLineEditor
Ø MultiOption cell editor –
com.elegantj.jfc.common.editors.MultiOptionEditor
Ø Number cell editor –
com.elegantj.jfc.common.editors.NumberEditor
Ø RadioButton cell editor –
com.elegantj.jfc.common.editors.RadioButtonEditor
Ø Slider cell editor - com.elegantj.jfc.common.editors.SliderEditor
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
dataGrid.setRowCellEditor(checkboxEditor); // sets checkbox as a cell editor for row at 0th index
dataGrid.setColumnCellEditor(checkboxEditor); // sets checkbox as a cell editor for column at 0th index
Ø To set row/column wise editibality
dataGrid.setRowEditable(new Boolean(false), 0); // makes row as not editable for row at 0th index
dataGrid.setColumnEditable(new Boolean(false), 0); // makes column as not editable for column at 0th index
Note: All above row/column
wise attributes prefers row wise attributes over column wise attributes. That is, if one has set above attributes for
the 1st row and also for 1st column, then 1st cell of the table (occupied by
1st row and 1st column) will be rendered with 1st rows attributes.
6.1.2.5 Setting up column header
With DataGrid, you can set following properties for header -
Ø SortColumnOnClick
Ø AdjustColumnOnClick
Ø ColumnReorderingAllowed
Ø ColumnResizingAllowed
Ø ColumnHeaderBackground
Ø ColumnHeaderForeground
Ø ColumnHeaderFont
Ø ColumnHeaderHeight
Ø ColumnHeaderVisible
Ø To set sort column on click.
dataGrid.setSortColumnOnClick(true); // enables sorting of column on column click
Ø To set adjust column on click,
dataGrid.setAdjustColumnOnClick(true); // enables adjusting of column on column click
Ø To set column reordering property,
dataGrid.setColumnReorderingAllowed(false); // disables reordering of columns
Ø To enable / disable column resizing,
dataGrid.setColumnResizingAllowed(false); // disables column resizing
Ø To set column header background,
dataGrid.setColumnHeaderBackground(java.awt.Color.blue); // sets column header background color as blue
Ø To set column header foreground,
dataGrid.setColumnHeaderForeground(java.awt.Color.black); // sets column header foreground color as black
Ø To set column header font,
dataGrid.setColumnHeaderFont(new java.awt.Font("Dialog", Font.BOLD, 12)); // sets column header font as dialog, bold, 12 size.
Ø To set column header height,
dataGrid.setColumnHeaderHeight(30); // sets column header height as 30 pixels
Ø To set visibility of column header,
dataGrid.setColumnHeaderVisible(false); // sets the column header as invisible
With DataGrid, you can set following properties for header -
Ø AdjustRowOnClick
Ø RowResizingAllowed
Ø RowHeaderBackground
Ø RowHeaderForeground
Ø RowHeaderFont
Ø RowHeaderWidth
Ø RowHeaderVisible
Ø To set adjust row on click feature,
dataGrid.setAdjustRowOnClick(true); // enables adjusting of row on row-click
Ø To enable/disable row resizing,
dataGrid.setRowResizingAllowed(false); // disables row resizing
Ø To set row header background,
dataGrid.setRowHeaderBackground(java.awt.Color.blue); // sets row header background color as blue
Ø To set row header foreground,
dataGrid.setRowHeaderForeground(java.awt.Color.black); // sets row header foreground color as black
Ø To set row header font,
dataGrid.setRowHeaderFont(new java.awt.Font("Dialog", Font.BOLD, 12)); // sets row header font to dialog, bold, 12 size
Ø To set row header height,
dataGrid.setRowHeaderHeight(30); // sets row header height as 30 pixels
To set visibility of row header,
dataGrid.setRowHeaderVisible(false); // makes row header invisible
6.1.2.7 Setting up cell editors and cell renderers
With DataGrid, you can apply any cell renderer / cell editor to whole table as well as to selected rows (s) / column(s).
The basic renderers supplied with this package are listed below,
Ø BooleanRenderer
Ø CheckboxRenderer
Ø ChoiceRenderer
Ø ColorRenderer
Ø DateRenderer
Ø DefaultRenderer
Ø IconRenderer
Ø MultiLineRenderer
Ø MultiOptionRenderer
Ø NumberRenderer
Ø ProgressRenderer
Ø RadioButtonRenderer
Ø TextRenderer
Here is a list of basic editors shipped with Bean -
Ø BooleanEditor
Ø CheckboxEditor
Ø ChoiceEditor
Ø ColorEditor
Ø DateEditor
Ø DefaultEditor
Ø IconEditor
Ø MultiLineEditor
Ø MultiOptionEditor
Ø NumberEditor
Ø RadioButtonEditor
Ø SliderEditor
Ø TextEditor
Ø To set cell renderer for whole table,
com.elegantj.jfc.common.renderers.CheckboxRenderer checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();
dataGrid.setDefaultCellRenderer(checkboxRenderer);
// This sets cell renderer as checkbox for whole table
Ø To set cell renderer at row level,
com.elegantj.jfc.common.renderers.CheckboxRenderer checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();
dataGrid.setRowCellRenderer(checkboxRenderer, 0);
// This sets cell renderer as checkbox for row at 0th index
Ø To set cell renderer at column level,
com.elegantj.jfc.common.renderers.CheckboxRenderer checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();
dataGrid.setColumnCellRenderer(checkboxRenderer, 0);
// This sets cell renderer as checkbox for column at 0th index
Ø To set cell editor for whole table,
com.elegantj.jfc.common.editors.CheckboxEditor checkboxEditor = new com.elegantj.jfc.common.editors.CheckboxEditor();
dataGrid.setDefaultCellEditor(checkboxEditor, 0);
// This sets cell editor as checkbox for whole table
Ø To set cell editor at row level,
com.elegantj.jfc.common.editors.CheckboxEditor checkboxEditor = new com.elegantj.jfc.common.editors.CheckboxEditor();
dataGrid.setRowCellEditor(checkboxEditor, 0);
// This sets cell editor as checkbox for row at 0th index
Ø To set cell editor at column level,
com.elegantj.jfc.common.editors.CheckboxEditor checkboxEditor = new com.elegantj.jfc.common.editors.CheckboxEditor();
dataGrid.setColumnCellEditor(checkboxEditor, 0);
// This sets cell editor as checkbox for column at 0th index
6.1.2.8 Setting up grid attributes
ElegantJ DataGrid offers following grid attributes -
Ø Grid color
Ø Show Grid
Ø Show horizontal lines
Ø Show vertical lines
Ø To set grid color,
java.awt.Color gridColor = java.awt.Color.black;
dataGrid.setGridColor(gridColor); // This sets grid color as black.
Ø To set visibility of grid,
dataGrid.setShowGrid(false); // makes the grid invisible
Ø To set the visibility of horizontal grid lines,
dataGrid.setShowHorizontalLines(false); // makes the horizontal grid invisible
Ø To set the visibility of the vertical grid lines,
dataGrid.setShowVerticalLines(false); // makes vertical grid lines invisible
6.1.2.9 Setting up row heights and row margins
DataGrid provides the following methods to set the row heights,
Ø To set the row height for all the rows,
dataGrid.setRowHeight(20);
which sets the row height to 20.
Ø To set the row height for the specified row,
dataGrid.setRowHeight(0, 20);
which sets the row height for the 0th row to 20.
DataGrid provides the following method to set row margin.
Ø To set the row margin,
dataGrid.setRowMargin(5);
which sets the row margin to 5.
6.1.2.10 Setting up column widths and column margins
DataGrid provides following methods to set column widths
Ø To set column width for specified column,
dataGrid.setColumnWidth(0, 80); // sets column width for column 0 as 80 pixels
Ø To set column margin,
dataGrid.setColumnMargin(5); // sets the column margin as 5 pixels
6.1.2.11 Working with selection and selection style
You can have three type of selection
Ø javax.swing.ListSelectionModel.SINGLE_SELECTION - only one path can be selected at a time.
Ø javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION - only contiguous paths can be selected.
Ø javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION - any path can be selected.
Ø To set selection mode,
dataGrid.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); // sets selection to single selection
Ø To select a row,
dataGrid.setSelectedRow(0); // selects row at 0th index
Ø To select more than one rows,
dataGrid.setSelectedRows(new int[]{0, 1, 2}); // sets row at 0th, 1st and 2nd index
Ø To select column,
dataGrid.setSelectedColumn(0); // sets column at 0th index
Ø To select columns,
dataGrid.setSelectedColumns(new int[]{0, 1, 2}); // selects columns at 0th, 1st and 2nd index
Ø To remove row selection interval,
dataGrid.removeRowSelectionInterval(0, 2); // removes selection on rows at 0th, 1st and 2nd index
Ø To remove column selection interval,
dataGrid.removeColumnSelectionInterval(0, 2); // removes selection on columns at 0th, 1st and 2nd index
Ø To clear selection of the whole table,
dataGrid.clearSelection(); // clears the selection of whole table.
6.1.2.12 Configuring editing features
Ø To set default editability,
dataGrid.setDefaultEditable(true); // allows to edit whole DataGrid
Ø To set row wise editability,
dataGrid.setRowEditable(new Boolean(false), 0); // sets row 0 as not editable
Ø To set column editability,
dataGrid.setColumnEditable(new Boolean(false), 0); // sets coumn 0 as not editable
Ø To start editing at the specified table cell,
com.elegantj.jfc.table.TableCell
tableCell =
new
com.elegantj.jfc.table.TableCell(2, 2);
dataGrid.editTableCell(tableCell);
This starts editing at the cell represented by 2nd row and 2nd column.
6.1.2.13 Configuring data with DataGrid
DataGrid provides the following methods to configure data to the DataGrid,
Ø To set data,
java.util.Vector data = new java.util.Vector();
java.util.Vector row1Data = new java.util.Vector();
row1Data.addElement("cell11");
row1Data.addElement("cell12");
row1Data.addElement("cell13");
data.addElement(row1Data);
java.util.Vector row2Data = new java.util.Vector();
row2Data.addElement("cell21");
row2Data.addElement("cell22");
row2Data.addElement("cell23");
data.addElement(row2Data);
java.util.Vector row3Data = new java.util.Vector();
row3Data.addElement("cell31");
row3Data.addElement("cell32");
row3Data.addElement("cell33");
data.addElement(row3Data);
dataGrid.setData(data);
which sets the 2-dimensional vector as a data.
Ø To set value at the specified row and column,
dataGrid.setValueAt("Cell 1, 1", 1, 1); // sets value at cell specified by row 1 and column 1.
6.1.2.14 Setting up auto resizing feature
ElegantJ DataGrid provides following auto- resizing modes,
DataGrid considers the following modes when a column of table is being resized:
Ø com.elegantj.jfc.table.dataGrid.AUTO_RESIZE_ALL_COLUMNS - Spared the delta amongst all the columns in the DataGrid, including the one that is being adjusted.
Ø com.elegantj.jfc.table.dataGrid.AUTO_RESIZE_LAST_COLUMN – Automatically adjust the size of last column only, If the last column to the appropriate limit and make no further adjustments.
Ø com.elegantj.jfc.table.dataGrid.AUTO_RESIZE_NEXT_COLUMN - Use just the column after the resizing column, This results in the "boundary" or divider between adjacent cells being independently adjustable.
Ø com.elegantj.jfc.table.dataGrid.AUTO_RESIZE_SQBSEQUENT_COLUMN - Use all columns after the one being adjusted to absorb the changes. This is the default behavior
Ø com.elegantj.jfc.table.dataGrid.AUTO_RESIZE_OFF - Don't automatically adjust the column's widths at all.
Ø To set auto resize mode,
dataGrid.setAutoResizeMode(com.elegantj.jfc.table.dataGrid.AUTO_RESIZE_ALL_COLUMNS);
This sets the auto resize mode to auto resize all columns.
6.1.2.15 Setting up key strokes insert, delete and enter key
Here is a list of keystrokes available (for carrying out operations) for use on a cell of DataGrid -
Ø INSERT - for inserting row on insert key.
Ø DELETE - for deleting row on delete key.
Ø ENTER - for adding row on enter key at the last row position.
Ø To enable inserting of row using Insert key,
dataGrid.setInsertRowOnInsertKey(true);
Ø To enable deleting of row using Delete key,
dataGrid.setDeleteRowOnDeleteKey(true);
Ø To enable adding a row at the end of table using Enter key,
dataGrid.setAddRowOnEnterKey(true);
This enables adding row on enter key, it works on last row only.
6.1.2.16 Setting visibility of popup menu
DataGrid provides a ready to use popup menu, having following functionalities -
Ø Add row / column
Ø Insert row / column
Ø Remove row / column
Ø Edit cell
Ø Sort (ascending / descending) column
All the above popup menu operations take place on selected row/column/cell.
Ø To set visibility of the popup menu,
dataGrid.setPopupVisible(true);
This allows to open the popup menu on right-click.
6.1.2.17 Configuring search panel
Ø To set search panel's visibility,
dataGrid.setSearchPanelVisible(false); // makes search panel invisible
Ø To set the search panel background,
dataGrid.setSearchPanelBackground(java.awt.Color.gray); // sets search panel background as gray
Ø To set the search panel foreground,
dataGrid.setSearchPanelForeground(java.awt.Color.black); // sets search panel foreground as black
Ø To set search panel font,
dataGrid.setSearchPanelFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12)); // sets search panel font as dialog, style as bold and size as 12
Ø To set search panel placement,
Possible values for the search panel placement are,
-
javax.swing.SwingConstants.TOP
-
javax.swing.SwingConstants.LEFT
-
javax.swing.SwingConstants.BOTTOM
-
javax.swing.SwingConstants.RIGHT
To set search panel placement,
dataGrid.setSearchPanelPlacement(com.elegantj.jfc.table.javax.swing.SwingConstants.TOP);
This places search panel at top.
6.1.2.18 Searching for information
Search Progress Options
|
Search Progress from |
Options for search Progress |
|
First cell |
com.elegantj.jfc.table.dataGrid. SEARCH_FROM_FIRST_CELL |
|
Last cell |
com.elegantj.jfc.table.dataGrid. SEARCH_FROM_LAST_CELL |
|
Selected cell, upwards |
com.elegantj.jfc.table.dataGrid. SEARCH_FROM_SELECTED_CELL_TO_UP |
|
Selected cell, downwards |
com.elegantj.jfc.table.dataGrid. SEARCH_FROM_SELECTED_CELL_TO_DOWN |
Comparison Options
|
Comparison requirement |
Option for comparison |
|
Search cell for value that starts with given search string |
com.elegantj.jfc.table.dataGrid.COMPARE_STARTS_WITH |
|
Search cell for value that ends with given search string |
com.elegantj.jfc.table.dataGrid.COMPARE_ENDS_WITH |
|
Search cell for value or its part equals given search string |
com.elegantj.jfc.table.dataGrid.COMPARE_CONTAINS |
|
Search cell for value for given string for exact match |
com.elegantj.jfc.table.dataGrid.COMPARE_EQUALS |
Ø To carry out a case insensitive search on table cell with specified cell string, column index and comparison mode,
String searchString = "search string";
int searchOnColumn = 1;
int compareMode = com.elegantj.jfc.table.dataGrid.COMPARE_STARTS_WITH;
boolean isCaseSensitive = false;
com.elegantj.jfc.table.TableCell searchedTableCell = dataGrid.searchTableCell(searchString, searchOnColumn, compareMode, isCaseSensitive);
This carries out a case insensitive search on column at index 1 with starts with compare mode, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To carry out a case insensitive search on table cell with the specified cell string, column index and search mode and comparison mode,
String searchString = "search string";
int searchOnColumn = 1;
int searchMode = com.elegantj.jfc.table.dataGrid.SEARCH_FROM_FIRST_CELL;
int compareMode = com.elegantj.jfc.table.dataGrid.COMPARE_STARTS_WITH;
boolean isCaseSensitive = false;
com.elegantj.jfc.table.TableCell searchedTableCell = dataGrid.searchTableCell(searchString, searchOnColumn, searchMode, compareMode, isCaseSensitive);
This carries out a case insensitive search on column at index 1 from first cell with starts with compare mode, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To search table cell with the specified cell string, on multiple columns, comparison mode and case sensitivity,
String searchString = "search string";
int searchOnColumns = new int[]{1, 2, 3};
int compareMode = com.elegantj.jfc.table.dataGrid.COMPARE_STARTS_WITH;
boolean isCaseSensitive = true;
com.elegantj.jfc.table.TableCell searchedTableCell = dataGrid.searchTableCell(searchString, searchOnColumns, compareMode, isCaseSensitive);
This carries out a case sensitive search on columns at indexes 1st, 2nd and 3rd with starts with compare mode, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To search table cell with the specified cell string on multiple columns, search mode, comparison mode and case sensitivity,
String searchString = "search string";
int searchOnColumns = new int[]{1, 2, 3};
int searchMode = com.elegantj.jfc.table.dataGrid.SEARCH_FROM_FIRST_CELL;
int compareMode = com.elegantj.jfc.table.dataGrid.COMPARE_STARTS_WITH;
boolean isCaseSensitive = false;
com.elegantj.jfc.table.TableCell searchedTableCell = dataGrid.searchTableCell(searchString, searchOnColumns, searchMode, compareMode, isCaseSensitive);
This carries out case sensitive search on columns at index 1, 2 and 3 from first cell with starts with compare mode, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To search table cell with the specified value,
Object searchValue = "search object";
com.elegantj.jfc.table.TableCell searchedTableCell = dataGrid.searchTableCell(searchValue);
This searches entire table with search value, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To search table cell with the specified value and column index,
Object searchValue = "search object";
int columnIndex = 1;
com.elegantj.jfc.table.TableCell searchedTableCell = dataGrid.searchTableCell(searchValue, columnIndex);
This searches column at index 1 with search value, If search string found then it returns TableCell which contains row and column index where search string found.
Ø To search table cell with the specified value and column indexes,
Object serachValue = "search object";
int columnIndexes[] = new int[]{1, 2, 3};
com.elegantj.jfc.table.TableCell searchedTableCell = dataGrid.searchTableCell(searchValue, columnIndexes);
This searches for search value on columns at indexes 1st, 2nd and 3rd, If search string found then it returns TableCell which contains row and column indexes where search string found.
Ø To sort specified column,
int columnIndex = 1;
dataGrid.sortColumn(columnIndex);
This sorts column at index 1 in ascending-descending-ascending-descending manner. That is, on 1st call, it sorts in ascending order on 2nd time in descending order and as on in this order.
Ø To sort specified column in ascending or descending order,
int columnIndex = 1;
boolean sortingOrder = true; // i.e. ascending
dataGrid.sortColumn(columnIndex, sortingOrder);
This sorts column at index 1 in ascending order.
Ø To sort multiple columns,
int columnIndexes[] = new int[]{1, 2, 3};
dataGrid.sortColumns(columnIndexes);
This sorts column at index 1, 2 and 3 in ascending-descending-ascending-descending order. That is, on 1st call, it sorts in ascending order. On 2nd call, in descending order and likewise.
Ø To sort multiple columns with specified sorting order,
int columnIndexes[] = new int[]{1, 2, 3};
boolean sortingOrders[] = new boolean[]{true, false, true};
dataGrid.sortColumns(columnIndexes, sortingOrders);
This sorts column 1 in ascending order, column 2 in descending and column 3 in ascending order.
6.1.2.20 Configuring data access component with ElegantJ DataGrid
You can use ElegantJ DataGrid bean for data exchange from SQL data source, Text, HTTP, FTP or an XML data source. Use method setDataProvider to set a data access component. It also allows to bind data access component to other data viewer or any other data viewing components through method getDataProvider. Data access component provides data which is manipulated by data viewer through data navigator. For more information on ElegantJ data access components refer Data Access Component Usage Matrix and Data Access Component Objects for more information.
You will get following five data access components with this package -
Ø SqlDataProvider - can fetch data from database
Ø TextDataProvider - can fetch data from text (local or remote) file
Ø HTTPTextDataProvider - can fetch data from text file using HTTP protocol
Ø FTPTextDataProvider - can fetch data from text file using FTP protocol
Ø XMLDataProvider - can fetch data from XML files
Any of the above data access components can be easily bound with DataGrid to fetch data from data source.
Ø To bind SqlDataProvider with DataGrid,
String databaseURL = "jdbc:odbc:data";
String databaseDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "";
String password = "";
String sqlString = "select * from data_table";
com.elegantj.data.dataprovider.sql.SqlDataProvider sqlDataProvider =
new com.elegantj.data.dataprovider.sql.SqlDataProvider(); // instantiate the SqlDataProvider
sqlDataProvider.setConnectionProperties(new com.elegantj.data.editors.ConnectionProperties(databaseURL, databaseDriver, userName, password)); // sets the connection properties
sqlDataProvider.setSqlString(sqlString); // sets the sql string to data access component
dataGrid.setDataProvider(sqlDataProvider); // binds the SqlDataProvider to DataGrid
dataGrid.retrieveData(); // retrieves the data from data access component
Ø To bind TextDataProvider with DataGrid,
String
sourceFilePath = "c:\\data\\data.txt";
com.elegantj.data.dataprovider.text.TextDataProvider textDataProvider = new com.elegantj.data.dataprovider.text.TextDataProvider(); // instantiate the TextDataProvider
textDataProvider.setFile(sourceFilePath); // sets the source file path to the TextDataProvider
textDataProvider.setRowSeparator("\n"); // sets the row separator
textDataProvider.setColumnSeparator(","); // sets the column separator
textDataProvider.setTextQualifier("\""); // sets the text qualifier
textDataProvider.setFirstRowAsColumnNames(true); // set the first row as column names
dataGrid.setDataProvider(textDataProvider); // binds the TextDataProvider to DataGrid
dataGrid.retrieveData(); // retrieves the data from data access component
Ø To bind HTTPTextDataProvider to DataGrid,
java.net.URL
httpURL = new
java.net.URL("http://localhost/myfolder/myfile.txt");
String
httpMethod = "Get";
com.elegantj.data.dataprovider.http.HTTPTextDataProvider
httpTextDataProvider = new
com.elegantj.data.dataprovider.http.HTTPTextDataProvider(); // instantiate the HTTPTextDataProvider
httpTextDataProvider.setURL(httpURL); // sets the URL
httpTextDataProvider.setMethod(httpMethod); // sets the HTTP-Method
httpTextDataProvider.setRowSeparator("\n"); // sets the row separator
httpTextDataProvider.setColumnSeparator(","); // sets the column separator
httpTextDataProvider.setTextQualifier("\""); // sets the text qualifier
httpTextDataProvider.setFirstRowAsColumnNames(true); // sets the first row as column names
dataGrid.setDataProvider(httpTextDataProvider); // binds the HTTPTextDataProvider to DataGrid
dataGrid.retrieveData(); // retrieves the data from data access component
Ø To bind FTPTextDataProvider to DataGrid,
String
hostName = "localhost";
int
portNo = 21;
String
userName = "user_name";
String
password = "password";
String
sourceFilePath = "data.txt";
com.elegantj.data.dataprovider.ftp.FTPTextDataProvider
ftpTextDataProvider = new
com.elegantj.data.dataprovider.ftp.FTPTextDataProvider(); // instantiate the FTPTextDataProvider
ftpTextDataProvider.setHostName(hostName); // sets the host name where FTP service is running
ftpTextDataProvider.setPort(portNo); // sets the portNo on which FTP service is running
ftpTextDataProvider.setUserName(userName); // sets the user name, required for the FTP login
ftpTextDataProvider.setPassword(password); // sets the password, required for the FTP login
ftpTextDataProvider.setFile(sourceFilePath); // sets the source file path
ftpTextDataProvider.setRowSeparator("\n"); // sets the row separator
ftpTextDataProvider.setColumnSeparator(","); // sets the column separator
ftpTextDataProvider.setTextQualifier("\""); // sets the text qualifier
ftpTextDataProvider.setFirstRowAsColumnNames(true); // sets the first row as column names
dataGrid.setDataProvider(ftpTextDataProvider); // binds the FTPTextDataProvider to DataGrid
dataGrid.retrieveData(); // retrieves the data from data access component
Ø To bind XMLDataProvider with DataGrid,
String
sourceFilePath = "c:\\data\\data.xml";
com.elegantj.data.dataprovider.xml.XMLDataProvider
xmlDataProvider =
new com.elegantj.data.dataprovider.xml.XMLDataProvider(); // instantiate the XMLDataProvider
xmlDataProvider.setFile(sourceFilePath); // sets the source file path to XMLDataProvider
xmlDataProvider.setRootTag("Report"); // sets the root tag
xmlDataProvider.setRowTag("Row"); // sets the row tag
xmlDataProvider.setColumnTag("Column"); // sets the column tag
xmlDataProvider.setFirstRowAsColumnNames(true) // set the first row as column names
dataGrid.setDataProvider(xmlDataProvider); // binds the XMLDataProvider to DataGrid
dataGrid.retrieveData(); // retrieves the data from data access component
Note: For more information
on data access components, go through the programmers guide on data access
components section, of this documentation.
6.1.2.21 Handling data navigation
JFCDataTable DataGrid has functionality for data navigation. Functionalities include -
|
Where to move |
Function to use |
|
To first record |
FirstRecord |
|
To last record |
LastRecord |
|
To Next record |
NextRecord |
|
To previous record |
PreviousRecord |
|
To specified record |
ScrollToRow |
Ø To move cursor to the first record,
dataGrid.firstRecord(); // moves cursor to first record
Ø To move cursor to the last record,
dataGrid.lastRecord(); // moves cursor to last record
Ø To move cursor to next record,
dataGrid.nextRecord(); // moves cursor to next record
Ø To move to a specific row,
dataGrid.scrollToRow(5); // moves the cursor 5th record.
6.1.2.22 Handling data modification
The following methods are used to modify data through data access component.
|
For what |
Function to use |
|
Refresh the table |
Refresh |
|
To add a default row to the end of the data |
AddRow |
|
To remove selected row |
DeleteRow |
Ø To refresh table,
dataGrid.refresh(); // refreshes data table
Ø To add a new row at end of data,
dataGrid.addRow(); // adds row at end of data
Ø To delete selected row,
dataGrid.deleteRow(); // removes selected row.
6.2 ElegantJ Data Access Component
6.2.1ElegantJ Database Access Component
6.2.1.1 Creating an instance of Database Access Component
You can use following code to create an instance of Database Access component.
com.elegantj.data.dataprovider.sql.SqlDataProvider sqlDataProvider = new com.elegantj.data.dataprovider.sql.SqlDataProvider(); // this creates an instance of Database Access component with default constructor.
6.2.1.2 Configuring database connection
Using ElegantJ Database Access component you can create connection to various database through a Connection object or a ConnectionProperties object. ConnectionProperties object includes various properties such as url, database driver class name, user name and password.
Ø To Set the Connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection
connection =
DriverManager.getConnection("jdbc:odbc:dsn",
"username", "password");
sqlDataProvider.setConnection(connection);
Ø To Set the ConnectionProperties
com.elegantj.data.editors.ConnectionProperties
connectionProperties =
new
com.elegantj.data.editors.ConnectionProperties("jdbc:odbc:dsn",
"sun.jdbc.odbc.JdbcOdbcDriver",
"username", "password");
sqlDataProvider.setConnectionProperties(connectionProperties);
6.2.1.3 Configuring database query
ElegantJ Database Access component executes database query. A query can include the retrieval arguments. Arguments are in the form of - name.type
Ø To set the query
sqlDataProvider.setSqlString("select * from employee");
6.2.1.4 Configuring data retrieval
ElegantJ Database Access component allows to skip the first n rows, to restrict the total number of fetched records at a time (fetch size) and allows to append or to replace the existing data by the next retrieved data.
Ø To Skip 'n' rows
sqlDataProvider.setSkippedRows(10); // skips 10 rows
Ø To Set the Fetch Size
sqlDataProvider.setFetchSize(100); // sets fetch size to 100
Ø To Append the next retrieved data to the existing data buffer
sqlDataProvider.setAppendDataOnFetchNext(true); // appends next retrieved data to existing data buffer
Ø To Retrieve data
sqlDataProvider.retrieve(); // Opens a connection and executes the query to retrieve the data
Ø To retrieve data with predefined retrieval arguments
String[]
arguments = new String[] { "argument1", "argument2" };
sqlDataProvider.retrieve(arguments); // Opens a connection and executes the query to retrieve the data
Ø To retrieve data without retrieve method call
if(!sqlDataProvider.open()) // Opens the connection explicitly
System.out.println"Error while
opening connection");
else if(!sqlDataProvider.executeQuery("select * from employee")) // Executes the query explicitly
System.out.println"Error while executing query");
Ø To retrieve the next batch of data, if the fetch size is specified and if it has more data
if(!sqlDataProvider.nextData())
System.out.println"Error while
retrieving more data");
6.2.1.6 Getting retrieved data information
Ø To get data from data provider
java.util.Vector data = sqlDataProvider.getData();
Note: The number of records
that can be fetched at a time depends on fetch size. If fetch size is 100 and
total records are 1000, this method will return 100 records only. So, to Get
next 100 records, nextData method should be called before calling this method.
Ø To get next 100 records, sqlDataProvider.nextData();
java.util.Vector data = sqlDataProvider.getData();
Ø To get data at specified record index.
java.util.Vector record = sqlDataProvider.getDataAt(0);
Ø To get data at specified record index and specified column index.
Object value = sqlDataProvider.getDataAt(0, 0);
Ø To get total number of records
int totalRecords = sqlDataProvider.getDataCount();
Ø To get current record index
int currentIndex = sqlDataProvider.getCurrentIndex();
Ø To get current record
java.util.Vector record = sqlDataProvider.getCurrentRecord();
Ø To get total number of tables for executed query
int totalTables = sqlDataProvider.getTableCount();
Ø To get the table names for the executed query
java.util.Vector tableNames = sqlDataProvider.getTableNames();
Ø To get the updateable table name
String updateableTable = sqlDataProvider.getUpdateableTable();
Ø To get total number of columns
int totalColumns = sqlDataProvider.getColumnCount();
Ø To get column names
java.util.Vector columnNames = sqlDataProvider.getColumnNames();
Ø To get column names as elements of an array
String[] columnNames = sqlDataProvider.getColumnsArray();
Ø To get column index of specified column name
int columnIndex = sqlDataProvider.getColumnIndex("employee_name");
Ø To get column data type for given column index, data type can be char, varchar, int, boolean, blob, etc. (refer java.sql.Types for more details)
int columnType = sqlDataProvider.getColumnType(0);
Ø To get column attributes for each column. Column attributes include - column catalog name, column class name, column display size, column label, column name, column type, column type name, column precision, column scale, column schema name, column's table name, column is auto increment or not, case sensitivity of column, currency of column, definitely writable column or not, column is nullable or not, column is read only or not, column is searchable or not, column is signed or not and column is writable or not.
java.util.Vector columnAttributes = sqlDataProvider.getColumnAttribs();
6.2.1.7 Navigating retrieved data
Ø Get the first record by positioning the cursor at the first record
java.util.Vector record = sqlDataProvider.firstRecord();
Ø To get the last record by positioning the cursor at the last record
java.util.Vector record = sqlDataProvider.lastRecord();
Ø To get the next record by positioning the cursor at next record
java.util.Vector record = sqlDataProvider.nextRecord();
Ø To get the last record by positioning the cursor at last record
java.util.Vector record = sqlDataProvider.previousRecord();
Ø To get record by positioning the cursor at specified index
java.util.Vector record = sqlDataProvider.scrollToRow(10);
6.2.1.8 Manipulating retrieved data
ElegantJ Database Access component saves the data into database. It saves the data according to options specified in WhereClause.
Options for whereClause are -
Ø Unique
Ø Unique and updateable
Ø Unique and modified.
For updated records, it considers key modification option. A key modification options includes the before inserting new record delete old record and update record directly.
Ø To set WhereClause option which tells the data provider that what data should be considered for saving. It can be one of the following options:
UNIQUE - unique column's data.
UNIQUE_AND_UPDATEABLE - unique and updateable column's data
UNIQUE_AND_MODIFIED - unique column's modified data
sqlDataProvider.setWhereClause
(com.elegantj.data.dataprovider.sql.SqlDataProvider.
UNIQUE_AND_MODIFIED);
Ø To set the key modification option which tells the data provider that what to do when updating the data. It is one of the following options :
USE_DELETE_THEN_INSERT - delete the older data, followed by insert new(updated) data
USE_UPDATE - update the data directly
sqlDataProvider.setKeyModification
(com.elegantj.data.dataprovider.sql.SqlDataProvider.
USE_DELETE_THEN_INSERT);
Ø To allow data to be updated
sqlDataProvider.setAllowUpdate(true);
Ø To explicitly set each column's updateable state
java.util.Vector updateableColumns = java.util.Vector();
updateableColumns.addElement(new Boolean(true)); // for the first column
updateableColumns.addElement(new Boolean(false)); // for second column
sqlDataProvider.setUpdateable(updateableColumns); // size of the updateableColumns should be same as total number of columns
Ø To explicitly set each column's unique key status
String
uniqueColumnIndexes = "0,2,7";
sqlDataProvider.setUniqueKeys(uniqueColumnIndexes);
Ø To set data (all the records)
java.util.Vector
data = java.util.Vector();
java.util.Vector vect = java.util.Vector(); // for the first row
vect.addElement("ID1"); // for first column
vect.addElement("NAME1"); // for second column
vect.addElement("ADDRESS1"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for second row
vect.addElement("ID2"); // for the first column
vect.addElement("NAME2"); // for second column
vect.addElement("ADDRESS2"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for third row
vect.addElement("ID3"); // for the first column
vect.addElement("NAME3"); // for second column
vect.addElement("ADDRESS3"); // for third column
data.addElement(vect);
sqlDataProvider.setData(data);
Ø To store data (all the records) as elements of an array
java.util.Vector[]
data = new java.util.Vector[3];
data[0] = java.util.Vector(); // for the first row
data[0].addElement("ID1"); // for first column
data[0].addElement("NAME1"); // for second column
data[0].addElement("ADDRESS1"); // for third column
data[1] = java.util.Vector(); // for second row
data[1].addElement("ID2"); // for the first column
data[1].addElement("NAME2"); // for second column
data[1].addElement("ADDRESS2"); // for third column
data[2] = java.util.Vector(); // for third row
data[2].addElement("ID3"); // for the first column
data[2].addElement("NAME3"); // for second column
data[2].addElement("ADDRESS3"); // for third column
sqlDataProvider.setDataArray(data);
Ø To ignore any changes made after last save and refresh data.
sqlDataProvider.refreshData();
Ø To append given record at the end.
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = sqlDataProvider.appendData(vect);
Ø To add given record at the end.
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
sqlDataProvider.addRow(vect);
Ø To remove current record
sqlDataProvider.deleteRow();
Ø To remove the record at specified index
sqlDataProvider.removeAt(10);
Ø To remove all the records
sqlDataProvider.removeAll();
Ø To remove all the records within specified range
sqlDataProvider.removeRange(2,
10);
Ø To insert specified record at specified index
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = sqlDataProvider.insertDataAt(vect, 3);
Ø To update record's data which resides at specified index of data provider
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
sqlDataProvider.modifyDataAt(vect,
3);
Ø To save only filtered data
sqlDataProvider.setSaveOnlyFilteredData(true);
Ø To save all the changes made (such as add, delete, insert, update procedure) on the database
sqlDataProvider.save();
ElegantJ Database Access component also provide methods to get data about changes made to data and filtering.
Ø To get total number of modified records
int
modifiedRecords = sqlDataProvider.getModifiedCount();
Ø To get total number of deleted records
int
deletedRecords = sqlDataProvider.getDeletedCount();
Ø To get total number of filtered records
int
filteredRecords = sqlDataProvider.getFilteredCount();
ElegantJ Database Access component provides facility of data filtering. A filter can be any expression. It can be arithmetical or data related expression.
Ø To enable filtering
sqlDataProvider.setFilterState(true);
Ø To set filter criteria (it can be any arithmetic or data related expression.)
sqlDataProvider.setFilterCriteria("employee_id
= 10");
Ø To filter data with given filter condition (expression)
sqlDataProvider.filterData("employee_id
= 10");
ElegantJ Database Access component allows to sort data by column(s) and sorting order for each column. String representation of sorting is in the form of col1:true,col2:false. The following methods are used for data sorting:
Ø To Set sorting criteria (it is string representation of the sorted column names and their sorting order)
sqlDataProvider.setSortingCriteria("employee_id:true,employee_name:false");
Ø To Sort the data with given different arguments as
Ø By vector containing column names with respective orders
java.util.Vector
sortColumns = new java.util.Vector();
java.util.Vector
sortColumn = new java.util.Vector();
sortColumn.addElement("employee_id");
sortColumn.addElement(new
Boolean(true));
sortColumns.addElement(sortColumn);
sortColumn
= new java.util.Vector();
sortColumn.addElement("employee_name");
sortColumn.addElement(new
Boolean(false));
sortColumns.addElement(sortColumn);
sqlDataProvider.sortData(sortColumns);
Ø By column names
sqlDataProvider.sortData(new
String[]{ "employee_id", "employee_name"});
Ø By column indexes
sqlDataProvider.sortData(new
int[]{ 0, 1});
Ø By column names and their sorting order
sqlDataProvider.sortData(new
String[]{ "employee_id", "employee_name"}, new boolean[]{
true, false});
Ø By column indexes and their sorting order
sqlDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false});
Ø By column names and range of the records to be sorted
sqlDataProvider.sortData(new
String[]{ "employee_id", "employee_name"}, 2 ,10);
Ø By column indexes and range of the records to be sorted
sqlDataProvider.sortData(new
int[]{ 0, 1}, 2 ,10);
Ø By column names, their sorting order and range of the records to be sorted
sqlDataProvider.sortData(new
String[]{ "employee_id", "employee_name" }, new boolean[]{
true, false },2 , 10);
Ø By column indexes, their sorting order and range of the records to be sorted
sqlDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false}, 2 ,10);
ElegantJ Database Access component has feature of data search. Any expression can be used as search criteria. ElegantJ Database Access component bean also provides find next functionality. The following methods are used for data search:
Ø To search data on given expression or any condition within given range of the records (optional).
int
index = sqlDataProvider.find("employee_id == 10", 2, 10);
Ø To search the next record with the given search criteria.
int
index = sqlDataProvider.findNext();
6.2.1.12 Exporting data as text
ElegantJ Database Access component allows to export data as column separated text or fixed width column text. It also allows to set default attributes to export the data as text.
Ø To set default exporting attributes
sqlDataProvider.SetColumnsDelimited(true); // Sets data being exported as column separated text
sqlDataProvider.SetColumnsDelimited(false); // Sets data being exported as fixed width column text
sqlDataProvider.SetFirstRowAsColumnNames(true); // Sets the first row being exported as column names
sqlDataProvider.SetRowSeparator("\n"); // Sets the row separator
sqlDataProvider.SetColumnSeparator(","); // Sets the column separator
sqlDataProvider.SetTextQualifier("\""); // Sets the text identifier
sqlDataProvider.SetColumnsWidth("10,5,4,21"); // Sets the fixed width of each column
Ø To export data as Text to specified OutputStream using default attributes
try
{
java.io.FileOutputStream out =
new
java.io.FileOutputStream("myfile.text");
sqlDataProvider.exportToText(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as text");
}
Ø To export data as column separated Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnSeparator = ",";
String textQualifier = "\"";
java.io.FileOutputStream out =
new
java.io.FileOutputStream("myfile.text");
sqlDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnSeparator, textQualifiers);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as text");
}
Ø To export data as fixed width column Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnsWidth = "10, 4, 14,
5";
java.io.FileOutputStream out =
new
java.io.FileOutputStream("myfile.text");
sqlDataProvider.exportToText(out,
rowSeparator,
firstRowAsColumnNames, columnsWidth);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as text");
}
Ø To export data as Text to specified OutputStream by specified attributes, specify null argument which is not required
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
boolean columnsDelimited = true;
String columnSeparator = ",";
String textQualifier = "\"";
String columnsWidth = null;
java.io.FileOutputStream out =
new
java.io.FileOutputStream("myfile.text");
sqlDataProvider.exportToText(out, rowSeparator, firstRowAsColumnNames, columnsDelimited, columnSeparator, textQualifier, columnsWidth); // Exports data as the column separated text
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as text");
}
6.2.1.13 Exporting data as XML
ElegantJ Database Access component allows to export data as XML. You can also set default attributes to export the data as XML.
Ø To set default exporting attributes
sqlDataProvider.SetRootTag("Report"); // Sets root tag identifier
sqlDataProvider.SetRowTag("Row"); // Sets row tag identifier
sqlDataProvider.SetColumnTag("Column"); // Sets column tag identifier
sqlDataProvider.SetFirstRowAsColumnNames(true); // Sets first exporting row as column names
Ø To export data as XML to specified OutputStream by default attributes
try
{
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.xml");
sqlDataProvider.exportToXML(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as XML");
}
Ø To export data as XML to specified OutputStream by specified attributes
try
{
String rootTag = "Root";
String rowTag = "Row";
String columnTag = "Column";
boolean firstRowAsColumnNames = true;
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.xml");
sqlDataProvider.exportToXML(out, rootTag,
rowTag, columnTag, firstRowAsColumnNames);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as XML");
}
6.2.1.14 Exporting data as SQL
ElegantJ Database Access component allows to export the data to any RDBMS.
Ø To export data as SQL to a database by specifying connection and name of the table in which data is to be inserted
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
sqlDataProvider.setConnection(connection);
String tableName = "employee";
sqlDataProvider.exportToSQL(connection,
tableName);
}
catch(ClassNotFoundException e) {
System.out.println"Error while loading
the driver class);
}
catch(java.sql.SQLException e) {
System.out.println"Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection, name of the table and column names in which data is to be inserted. Specify table column as Null to skip that column for data export activity.
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
sqlDataProvider.setConnection(connection);
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
sqlDataProvider.exportToSQL(connection,
tableName, tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println"Error while loading
the driver class);
}
catch(java.sql.SQLException e) {
System.out.println"Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes and name of the table in which data is to be inserted.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
sqlDataProvider.exportToSQL(databaseURL,
driver, username, password, tableName);
}
catch(ClassNotFoundException e) {
System.out.println"Error while loading
the driver class);
}
catch(java.sql.SQLException e) {
System.out.println"Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes, name of table and column names in which data is to be inserted. Specify table column as null to skip data export for that column.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
sqlDataProvider.exportToSQL(databaseURL,
driver, userName, password, tableName, tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println"Error while loading
the driver class);
}
catch(java.sql.SQLException e) {
System.out.println"Error while
exporting the data as SQL");
}
6.2.2ElegantJ Text Data Access Component
6.2.2.1 ElegantJ Text via File
6.2.2.1.1 Creating an instance of Text Data Access Component
You can use following code to create an instance of Text Data Access component.
com.elegantj.data.dataprovider.text.TextDataProvider textDataProvider = new com.elegantj.data.dataprovider.text.TextDataProvider();
6.2.2.1.2 Configuring data source
Using ElegantJ Text Data Access component you can connect to a Text file through File Name or URL.
Ø To Set the File Name
textDataProvider.setURLConnectionEnabled(false); // Disable URL connection
textDataProvider.setFile("c://myfolder/myfile.txt");
Ø To Set the URL
textDataProvider.setURLConnectionEnabled(true); // Enable URL connection
textDataProvider.setURL("http://localhost/myfolder/myfile.txt");
6.2.2.1.3 Configuring data retrieval
ElegantJ Text Data Access component allows to set the row separator, column separator, text qualifier, columns fixed width, to skip the first n rows, to skip specified columns, to restrict total number of fetched records at a time and allows to append or to replace the existing data with next retrieved data.
Ø To set the first row to contain column names
textDataProvider.setFirstRowAsColumnNames(true);
Ø To set columns delimited text or fixed width text
textDataProvider.setColumnsDelimited(true); // columns separated text
textDataProvider.setColumnsDelimited(false); // fixed width columns text
Ø To set row separator
textDataProvider.setRowSeparator("\n");
Ø To set column separator
textDataProvider.setColumnSeparator(",");
Ø To set identifier of the text included in the column
textDataProvider.setTextQualifier("\"");
Ø To set the columns with fixed width
textDataProvider.setColumnsWidth("10,5,4,21");
Ø To skip a set of rows
textDataProvider.setSkippedRows(10);
Ø To skip a set of columns
textDataProvider.setSkippedColumns("0,3,5");
Ø To set Fetch Size
textDataProvider.setFetchSize(100);
Ø To append the next retrieved data to existing one
textDataProvider.setAppendDataOnFetchNext(true);
6.2.2.1.4 Retrieving data
Ø To retrieve data
textDataProvider.retrieve(); // Opens a connection and retrieves the data
Ø To retrieve data explicitly with specified InputStream
try {
java.io.FileInputStream in = new java.io.FileInputStream("c://myfolder/myfile.txt");
if(!textDataProvider.retrieveData(in))
System.out.println"Error while retrieving data");
in.close();
} catch(java.io.IOException e) {
System.out.println"Error while opening the file");
}
Ø To retrieve the next batch of data, if the fetch size is specified and if has more data
if(!textDataProvider.nextData())
System.out.println"Error while retrieving more data");
6.2.2.1.5 Getting retrieved data information
Ø To get data from data provider
java.util.Vector data = textDataProvider.getData();
Note: The number of records
that can be fetched at a time depends on fetch size. If fetch size is 100 and
total records are 1000, this method will return 100 records only. So, to get
next 100 records, nextData method should be called before calling this method.
Ø To get next 100 records, textDataProvider.nextData();
java.util.Vector data = textDataProvider.getData();
Ø To get data at specified record index.
java.util.Vector record = textDataProvider.getDataAt(0);
Ø To get data at specified record index and specified column index.
Object value = textDataProvider.getDataAt(0, 0);
Ø To get total number of records
int totalRecords = textDataProvider.getDataCount();
Ø To get current record index
int currentIndex = textDataProvider.getCurrentIndex();
Ø To get current record
java.util.Vector record = textDataProvider.getCurrentRecord();
Ø To get total number of columns
int totalColumns = textDataProvider.getColumnCount();
Ø To get column names
java.util.Vector columnNames = textDataProvider.getColumnNames();
Ø To get column names in the array representation
String[] columnNames = textDataProvider.getColumnsArray();
Ø To get the column index of the specified column name
int columnIndex = textDataProvider.getColumnIndex("employee_name");
6.2.2.1.6 Navigating retrieved data
Ø To get the first record by positioning the cursor at the first record
java.util.Vector record = textDataProvider.firstRecord();
Ø To get the last record by positioning the cursor at the last record
java.util.Vector record = textDataProvider.lastRecord();
Ø To get the next record by positioning the cursor at the next record
java.util.Vector record = textDataProvider.nextRecord();
Ø To get the last record by positioning the cursor at last record
java.util.Vector record = textDataProvider.previousRecord();
Ø To get a record by positioning the cursor at specified index
java.util.Vector record = textDataProvider.scrollToRow(10);
6.2.2.1.7 Manipulating retrieved data
ElegantJ Text Data Access Component saves the data to the Text file.
Ø To set data (all the records)
java.util.Vector data = java.util.Vector();
java.util.Vector vect = java.util.Vector(); // for the first row
vect.addElement("ID1"); // for the first column
vect.addElement("NAME1"); // for second column
vect.addElement("ADDRESS1"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for second row
vect.addElement("ID2"); // for the first column
vect.addElement("NAME2"); // for second column
vect.addElement("ADDRESS2"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for third row
vect.addElement("ID3"); // for the first column
vect.addElement("NAME3"); // for second column
vect.addElement("ADDRESS3"); // for third column
data.addElement(vect);
textDataProvider.setData(data);
Ø To set data (all the records) as elements of an array
java.util.Vector[]
data = new java.util.Vector[3];
data[0] = java.util.Vector(); // for the first row
data[0].addElement("ID1"); // for the first column
data[0].addElement("NAME1"); // for second column
data[0].addElement("ADDRESS1"); // for third column
data[1] = java.util.Vector(); // for second row
data[1].addElement("ID2"); // for the first column
data[1].addElement("NAME2"); // for second column
data[1].addElement("ADDRESS2"); // for third column
data[2] = java.util.Vector(); // for third row
data[2].addElement("ID3"); // for the first column
data[2].addElement("NAME3"); // for second column
data[2].addElement("ADDRESS3"); // for third column
textDataProvider.setDataArray(data);
Ø To ignore any changes made after last save and refresh data.
textDataProvider.refreshData();
Ø To append given record at the end
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = textDataProvider.appendData(vect);
Ø To add given record to the end
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
textDataProvider.addRow(vect);
To remove current record
textDataProvider.deleteRow();
Ø To remove record at a specified index
textDataProvider.removeAt(10);
Ø To remove all the records
textDataProvider.removeAll();
Ø To remove the records in specified range
textDataProvider.removeRange(2,
10);
Ø To insert specified record at specified index
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = textDataProvider.insertDataAt(vect, 3);
Ø To update record's data which resides at specified index of data provider
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
textDataProvider.modifyDataAt(vect,
3);
Ø To save only filtered data
textDataProvider.setSaveOnlyFilteredData(true);
Ø To save all the changes (such as add, delete, insert, update procedure) made to the text
textDataProvider.save();
Ø To save all the changes to specified OutputStream
try
{
java.io.FileOutputStream out =
new
java.io.FileOutputStream("d://myfolder/myfile.txt");
if(!textDataProvider.saveData(out))
System.out.println"Error while
saving data");
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while opening
the file");
}
ElegantJ Text Data Access Component also provides methods to get data about changes made to data and filtering.
Ø To get total number of modified records
int
modifiedRecords = textDataProvider.getModifiedCount();
Ø To get total number of deleted records
int
deletedRecords = textDataProvider.getDeletedCount();
Ø To get total number of filtered records
int
filteredRecords = textDataProvider.getFilteredCount();
6.2.2.1.8 Filtering data
ElegantJ Text Data Access component provides facility of data filtering. A filter can be any expression. It can be arithmetical or data related expression.
Ø To enable filtering
textDataProvider.setFilterState(true);
Ø To set filter criteria (it can be any arithmetic or data related expression.)
textDataProvider.setFilterCriteria("employee_id
= 10");
Ø To filter data with the given filter condition (expression)
textDataProvider.filterData("employee_id
= 10");
6.2.2.1.9 Sorting data
ElegantJ Text Data Access component allows to sort data by column(s) and sorting order for each column. The string representation of sorting is in the form of col1:true,col2:false. Following methods are used for data sorting:
Ø To set sorting criteria (it is string representation of the sorted column names and their sorting order)
textDataProvider.setSortingCriteria("employee_id:true,employee_name:false");
Ø To sort the data with given different arguments as -
Ø By vector containing column names and its orders
java.util.Vector
sortColumns = new java.util.Vector();
java.util.Vector
sortColumn = new java.util.Vector();
sortColumn.addElement("employee_id");
sortColumn.addElement(new
Boolean(true));
sortColumns.addElement(sortColumn);
sortColumn
= new java.util.Vector();
sortColumn.addElement("employee_name");
sortColumn.addElement(new
Boolean(false));
sortColumns.addElement(sortColumn);
textDataProvider.sortData(sortColumns);
Ø By column names
textDataProvider.sortData(new
String[]{ "employee_id", "employee_name"});
Ø By column indexes
textDataProvider.sortData(new
int[]{ 0, 1});
Ø By column names and their sorting order
textDataProvider.sortData(new
String[]{ "employee_id", "employee_name"}, new boolean[]{
true, false});
Ø By column indexes and their sorting order
textDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false});
Ø By column names and range of the records to be sorted
textDataProvider.sortData(new
String[]{ "employee_id", "employee_name"}, 2 ,10);
Ø By column indexes and range of the records to be sorted
textDataProvider.sortData(new
int[]{ 0, 1}, 2 ,10);
Ø By column names, their sorting order and range of the records to be sorted
textDataProvider.sortData(new
String[]{ "employee_id", "employee_name" },
new
boolean[]{ true, false },2 , 10);
Ø By column indexes, their sorting order and range of the records to be sorted
textDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false}, 2 ,10);
6.2.2.1.10 Searching data
ElegantJ Text Data Access component has feature of data search. Any expression can be used as search criteria. ElegantJ Text Data Access component also provides find Next functionality. Following methods are used for data search:
Ø To search data on given expression or any condition within given range of the records (optional)
int
index = textDataProvider.find("employee_id == 10", 2, 10);
Ø To Search the next record with the given search criteria.
int
index = textDataProvider.findNext();
6.2.2.1.11 Exporting data as text
ElegantJ Text Data Access component allows to export data as column separated text or fixed width column text. It also allows to set default attributes to export the data as text.
Ø To set default exporting attributes
textDataProvider.SetColumnsDelimited(true); // Sets data being exported as column separated text
textDataProvider.SetColumnsDelimited(false); // Sets data being exported as fixed width column text
textDataProvider.SetFirstRowAsColumnNames(true); // Sets the first row being exported as column names
textDataProvider.SetRowSeparator("\n"); // Sets the row separator
textDataProvider.SetColumnSeparator(","); // Sets the column separator
textDataProvider.SetTextQualifier("\""); // Sets the text identifier
textDataProvider.SetColumnsWidth("10,5,4,21"); // Sets the fixed width of each column
Ø To export data as Text to specified OutputStream using default attributes
try
{
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
textDataProvider.exportToText(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as text");
}
Ø To export data as column separated Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnSeparator = ",";
String textQualifier = "\"";
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
textDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnSeparator, textQualifiers);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as text");
}
Ø To export data as fixed width column Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnsWidth = "10, 4, 14,
5";
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
textDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnsWidth);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as text");
}
Ø To export data as Text to specified OutputStream by specified attributes, specify null argument which is not required
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
boolean columnsDelimited = true;
String columnSeparator = ",";
String textQualifier = "\"";
String columnsWidth = null;
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
textDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnsDelimited, columnSeparator,
textQualifier, columnsWidth); // Exports data as the column separated text
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as text");
6.2.2.1.12 Exporting data as XML
ElegantJ Text Data Access component allows to export data as XML. You can also set default attributes to export the data as XML.
Ø To set default exporting attributes
textDataProvider.SetRootTag("Report"); // Sets root tag identifier
textDataProvider.SetRowTag("Row"); // Sets row tag identifier
textDataProvider.SetColumnTag("Column"); // Sets column tag identifier
textDataProvider.SetFirstRowAsColumnNames(true); // Sets first exporting row as column names
Ø To export data as XML to specified OutputStream by default attributes
try
{
java.io.FileOutputStream out =
new
java.io.FileOutputStream("myfile.xml");
textDataProvider.exportToXML(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while exporting the data as
XML");
}
Ø To export data as XML to specified OutputStream by specified attributes
try
{
String rootTag = "Root";
String rowTag = "Row";
String columnTag = "Column";
boolean firstRowAsColumnNames = true;
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.xml");
textDataProvider.exportToXML(out, rootTag,
rowTag, columnTag, firstRowAsColumnNames);
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while
exporting the data as XML");
}
6.2.2.1.13 Exporting data as SQL
ElegantJ Text Data Access component allows to export the data to any RDBMS.
Ø To export data as SQL to a database by specifying connection and name of the table in which data is to be inserted
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
textDataProvider.setConnection(connection);
String tableName = "employee";
textDataProvider.exportToSQL(connection,
tableName);
}
catch(ClassNotFoundException e) {
System.out.println"Error while loading
the driver class);
}
catch(java.sql.SQLException e) {
System.out.println"Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection, name of the table and column names in which data is to be inserted. Specify table column as Null to skip that column for data export activity.
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
textDataProvider.setConnection(connection);
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
textDataProvider.exportToSQL(connection,
tableName, tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println"Error while loading
the driver class);
}
catch(java.sql.SQLException e) {
System.out.println"Error while exporting
the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes and name of the table in which data is to be inserted.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
textDataProvider.exportToSQL(databaseURL,
driver, username, password, tableName);
}
catch(ClassNotFoundException e) {
System.out.println"Error while loading
the driver class);
}
catch(java.sql.SQLException e) {
System.out.println"Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes, name of table and column names in which data is to be inserted. Specify table column as null to skip data export for that column.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
textDataProvider.exportToSQL(databaseURL,
driver, userName, password, tableName, tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println"Error while loading
the driver class);
}
catch(java.sql.SQLException e) {
System.out.println"Error while
exporting the data as SQL");
}
6.2.2.2 ElegantJ Text via HTTP
6.2.2.2.1 Creating an instance of HTTP Text Data Access Component
You can use following code to create an instance of ElegantJ Text via HTTP JavaBean.
com.elegantj.data.dataprovider.http.HTTPTextDataProvider
httpTextDataProvider
= new
com.elegantj.data.dataprovider.http.HTTPTextDataProvider();
6.2.2.2.2 Configuring data source
Using ElegantJ Text via HTTP JavaBean you can connect to a Text Data through HTTP URL. It also allows to configure the HTTP request.
Ø To set the URL
httpTextDataProvider.setURL("http://localhost:8080/myapp/data.jsp?id=22");
Ø To set HTTP Request Method
httpTextDataProvider.setMethod(com.elegantj.net.http.HTTPClient.HTTP_GET_METHOD);
Ø To clear HTTP Request headers
httpTextDataProvider.clearHTTPRequestHeaders();
Ø To set General Header property for the HTTP Request header
httpTextDataProvider.setHTTPRequestGeneralHeaderProperty("Date",
"12/12/2002");
Ø To set Request Header property for the HTTP Request header
httpTextDataProvider.setHTTPRequestHeaderProperty("From",
"xyz@elegantjbeans.com");
Ø To set Entity Header property for the HTTP entity header
httpTextDataProvider.setHTTPRequestEntityHeaderProperty("Content-Type",
"text/plain");
Ø To set specified string buffer as the entity body for the HTTP POST Request
httpTextDataProvider.setStringBufferAsEntityBody("This
is the Sample Data to be Posted");
Ø To set content of the specified file as entity body for the HTTP POST Request
httpTextDataProvider.setFileAsEntityBody(new
java.io.File("c://myfolder/myrequestdata.txt"));
6.2.2.2.3 Configuring data retrieval
ElegantJ Text via HTTP JavaBean allows to set the row separator, column separator, text qualifier, columns fixed width, skip the first n rows, to skip the specified columns, to restrict total number of fetched records at a time and allows to append or to replace the existing data with the next retrieved data.
Ø To set the first row to contain column names
httpTextDataProvider.setFirstRowAsColumnNames(true);
Ø To set columns delimited text or fixed width text
httpTextDataProvider.setColumnsDelimited(true); // columns separated text
httpTextDataProvider.setColumnsDelimited(false); // fixed width columns text
Ø To set row separator
httpTextDataProvider.setRowSeparator("\n");
Ø To set column separator
httpTextDataProvider.setColumnSeparator(",");
Ø To set identifier of the text included in the column
httpTextDataProvider.setTextQualifier("\"");
Ø To set columns fixed width
httpTextDataProvider.setColumnsWidth("10,5,4,21");
Ø To set skipped rows
httpTextDataProvider.setSkippedRows(10);
Ø To set skipped columns
httpTextDataProvider.setSkippedColumns("0,3,5");
Ø To set Fetch Size
httpTextDataProvider.setFetchSize(100);
Ø To append the next retrieved data to existing data
httpTextDataProvider.setAppendDataOnFetchNext(true);
6.2.2.2.4 Retrieving data
Ø To retrieve data
httpTextDataProvider.retrieve(); // Opens the connection and retrieve the data
Ø To retrieve data explicitly with specified InputStream
try
{
httpTextDataProvider.openConnection();
httpTextDataProvider.sendRequestToServer();
httpTextDataProvider.getResponseHeaderFromServer();
java.io.InputStream in = httpTextDataProvider.getInputStream();
if(!httpTextDataProvider.retrieveData(in))
System.out.println"Error while
retrieving data");
in.close();
}
catch(java.io.IOException e) {
System.out.println"Error while opening
the connection");
}
Ø To retrieve the next data, if the fetch size is specified and if has more data
if(!httpTextDataProvider.nextData())
System.out.println"Error while
retrieving more data");
6.2.2.2.5 Getting retrieved data information
Ø To get data from data provider
java.util.Vector
data = httpTextDataProvider.getData();
Note: The number of records
that can be fetched at a time depends on fetch size. If fetch size is 100 and
total records are 1000, this method will return 100 records only. So, to get
next 100 records, nextData method should be called before calling this method.
Ø To get next 100 records, httpDataProvider.nextData();
java.util.Vector
data = httpTextDataProvider.getData();
Ø To get data at specified record index.
java.util.Vector
record = httpTextDataProvider.getDataAt(0);
Ø To get data at specified record index and specified column index.
Object
value = httpTextDataProvider.getDataAt(0, 0);
Ø To get total number of records
int
totalRecords = httpTextDataProvider.getDataCount();
Ø To get current record index
int
currentIndex = httpTextDataProvider.getCurrentIndex();
Ø To get current record
java.util.Vector
record = httpTextDataProvider.getCurrentRecord();
Ø To get total number of columns
int
totalColumns = httpTextDataProvider.getColumnCount();
Ø To get column names
java.util.Vector
columnNames =
httpTextDataProvider.getColumnNames();
Ø To get column names in the array representation
String[]
columnNames = httpTextDataProvider.getColumnsArray();
Ø To get column index of the specified column name
int
columnIndex =
httpTextDataProvider.getColumnIndex("employee_name");
6.2.2.2.6 Navigating retrieved data
Ø To get the first record by positioning the cursor at first record
java.util.Vector
record = httpTextDataProvider.firstRecord();
Ø To get the last record by positioning the cursor at last record
java.util.Vector
record = httpTextDataProvider.lastRecord();
Ø To get the next record by positioning the cursor at next record
java.util.Vector
record = httpTextDataProvider.nextRecord();
Ø To get the last record by positioning the cursor at last record
java.util.Vector
record = httpTextDataProvider.previousRecord();
Ø To get the record by positioning the cursor at specified index
java.util.Vector
record = httpTextDataProvider.scrollToRow(10);
6.2.2.2.7 Manipulating retrieved data
ElegantJ Text via HTTP JavaBean saves the data as the Text to the specified URL.
Ø To set the data (all the records)
java.util.Vector
data = java.util.Vector();
java.util.Vector vect = java.util.Vector(); // for the first row
vect.addElement("ID1"); // for the first column
vect.addElement("NAME1"); // for second column
vect.addElement("ADDRESS1"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for second row
vect.addElement("ID2"); // for the first column
vect.addElement("NAME2"); // for second column
vect.addElement("ADDRESS2"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for third row
vect.addElement("ID3"); // for the first column
vect.addElement("NAME3"); // for second column
vect.addElement("ADDRESS3"); // for third column
data.addElement(vect);
httpTextDataProvider.setData(data);
Ø To set data (all the records) as elements of an array
java.util.Vector[]
data = new java.util.Vector[3];
data[0] = java.util.Vector(); // for first row
data[0].addElement("ID1"); // for the first column
data[0].addElement("NAME1"); // for second column
data[0].addElement("ADDRESS1"); // for third column
data[1] = java.util.Vector(); // for second row
data[1].addElement("ID2"); // for the first column
data[1].addElement("NAME2"); // for second column
data[1].addElement("ADDRESS2"); // for third column
data[2] = java.util.Vector(); // for third row
data[2].addElement("ID3"); // for the first column
data[2].addElement("NAME3"); // for second column
data[2].addElement("ADDRESS3"); // for third column
httpTextDataProvider.setDataArray(data);
Ø To ignore any changes made after last save and refresh data.
httpTextDataProvider.refreshData();
Ø To append given record at the end
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = httpTextDataProvider.appendData(vect);
Ø To add given record at the end
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
httpTextDataProvider.addRow(vect);
Ø To remove current record
httpTextDataProvider.deleteRow();
Ø To remove record at specified index
httpTextDataProvider.removeAt(10);
Ø To remove all the records
httpTextDataProvider.removeAll();
Ø To remove records in the specified range
httpTextDataProvider.removeRange(2,
10);
Ø To Insert specified record at specified index
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = httpTextDataProvider.insertDataAt(vect, 3);
Ø To update record's data which resides at specified index of data provider
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
httpTextDataProvider.modifyDataAt(vect,
3);
Ø To save only filtered data
httpTextDataProvider.setSaveOnlyFilteredData(true);
Ø To save all the changes (such as add, delete, insert, update procedure) made to the text
httpTextDataProvider.save();
Ø To save all the changes to the specified OutputStream
try
{
httpTextDataProvider.openConnection();
httpTextDataProvider.sendRequestToServer();
httpTextDataProvider.getResponseHeaderFromServer();
java.io.OutputStream out = httpTextDataProvider.getOutputStream();
if(!httpTextDataProvider.saveData(out))
System.out.println"Error while
saving data");
out.close();
}
catch(java.io.IOException e) {
System.out.println"Error while opening
connection");
}
ElegantJ Text via HTTP JavaBean also provides methods to get data about changes made to data and filtering.
Ø To get total number of modified records
int
modifiedRecords = httpTextDataProvider.getModifiedCount();
Ø To get total number of deleted records
int
deletedRecords = httpTextDataProvider.getDeletedCount();
Ø To get total number of filtered records
int
filteredRecords = httpTextDataProvider.getFilteredCount();
6.2.2.2.8 Filtering data
ElegantJ Text via HTTP JavaBean provides the filtering data.
A filter can be any expression. It can be arithmetical or data related expression.
Ø To enable filtering
httpTextDataProvider.setFilterState(true);
Ø To set filter criteria (it can be any arithmetic or data related expression).
httpTextDataProvider.setFilterCriteria("employee_id
= 10");
Ø To filter the data with given filter condition (expression)
httpTextDataProvider.filterData("employee_id
= 10");
6.2.2.2.9 Sorting data
ElegantJ Text via HTTP JavaBean allows to sort the data by column(s) and sorting order for each column. The string representation of the sorting is in the form of col1:true,col2:false. The following methods are used for data sorting:
Ø To set sorting criteria (it is string representation of the sorted column names and their sorting order).
httpTextDataProvider.setSortingCriteria("employee_id:true,employee_name:false");
Ø To Sort the data with given different arguments as
Ø By vector containing column names and its orders
java.util.Vector
sortColumns = new java.util.Vector();
java.util.Vector
sortColumn = new java.util.Vector();
sortColumn.addElement("employee_id");
sortColumn.addElement(new
Boolean(true));
sortColumns.addElement(sortColumn);
sortColumn
= new java.util.Vector();
sortColumn.addElement("employee_name");
sortColumn.addElement(new
Boolean(false));
sortColumns.addElement(sortColumn);
httpTextDataProvider.sortData(sortColumns);
Ø By column names
httpTextDataProvider.sortData(new
String[]{ "employee_id",
"employee_name"});
Ø By column indexes
httpTextDataProvider.sortData(new
int[]{ 0, 1});
Ø By column names and their sorting order
httpTextDataProvider.sortData(new
String[]{ "employee_id",
"employee_name"}, new boolean[]{
true, false});
Ø By column indexes and their sorting order
httpTextDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false});
Ø By column names and range of the records to be sorted
httpTextDataProvider.sortData(new
String[]{ "employee_id", "employee_name"}, 2 ,10);
Ø By column indexes and range of the records to be sorted
httpTextDataProvider.sortData(new
int[]{ 0, 1}, 2 ,10);
Ø By column names, their sorting order and range of the records to be sorted
httpTextDataProvider.sortData(new
String[]{ "employee_id", "employee_name" }, new boolean[]{
true, false },2 , 10);
Ø By column indexes, their sorting order and range of the records to be sorted
httpTextDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false}, 2 ,10);
6.2.2.2.10 Searching data
ElegantJ Text via HTTP JavaBean has feature of data search. Any expression can be used as search criteria. ElegantJ Text via HTTP JavaBean bean also provides Find Next functionality. Following methods are used for data search:
Ø To search data on given expression or any condition within the given range of the records (optional)
int
index = httpTextDataProvider.find("employee_id == 10", 2, 10);
Ø To search the next record with the given search criteria.
int
index = httpTextDataProvider.findNext();
6.2.2.2.11 Exporting data as text
ElegantJ Text via HTTP JavaBean allows to export data as column separated text or fixed width column text. It also allows to set default attributes to export the data as text.
Ø To set default exporting attributes
httpTextDataProvider.SetColumnsDelimited(true); // Sets data being exported as column separated text
httpTextDataProvider.SetColumnsDelimited(false); // Sets data being exported as fixed width column text
httpTextDataProvider.SetFirstRowAsColumnNames(true); // Sets the first row being exported as column names
httpTextDataProvider.SetRowSeparator("\n"); // Sets the row separator
httpTextDataProvider.SetColumnSeparator(","); // Sets the column separator
httpTextDataProvider.SetTextQualifier("\""); // Sets the text identifier
httpTextDataProvider.SetColumnsWidth("10,5,4,21"); // Sets the fixed width of each column
Ø To export data as Text to specified OutputStream using default attributes
try
{
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
httpTextDataProvider.exportToText(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while exporting
the data as text");
}
Ø To export data as column separated Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnSeparator = ",";
String textQualifier = "\"";
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
httpTextDataProvider.exportToText(out,
rowSeparator,
firstRowAsColumnNames, columnSeparator,
textQualifiers);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while exporting the data as text");
}
Ø To export data as fixed width column Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnsWidth = "10, 4, 14,
5";
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
httpTextDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnsWidth);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
Ø To export data as Text to specified OutputStream by specified attributes, specify null argument which is not required
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
boolean columnsDelimited = true;
String columnSeparator = ",";
String textQualifier = "\"";
String columnsWidth = null;
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
httpTextDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnsDelimited, columnSeparator,
textQualifier, columnsWidth); // Exports data as the column separated text
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
6.2.2.2.12 Exporting data as XML
ElegantJ Text via HTTP JavaBean allows to export data as XML. You can also set default attributes to export the data as XML.
Ø To set default exporting attributes
httpTextDataProvider.SetRootTag("Report"); // Sets root tag identifier
httpTextDataProvider.SetRowTag("Row"); // Sets row tag identifier
httpTextDataProvider.SetColumnTag("Column"); // Sets column tag identifier
httpTextDataProvider.SetFirstRowAsColumnNames(true); // Sets first exporting row as column names
Ø To export data as XML to specified OutputStream by default attributes
try
{
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.xml");
httpTextDataProvider.exportToXML(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as XML");
}
Ø To export data as XML to specified OutputStream by specified attributes
try
{
String rootTag = "Root";
String rowTag = "Row";
String columnTag = "Column";
boolean firstRowAsColumnNames = true;
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.xml");
httpTextDataProvider.exportToXML(out,
rootTag, rowTag, columnTag, firstRowAsColumnNames);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as XML");
}
6.2.2.2.13 Exporting data as SQL
ElegantJ Text via HTTP JavaBean allows to export data to any RDBMS.
Ø To export data as SQL to a database by specifying connection and name of the table in which data is to be inserted
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
httpTextDataProvider.setConnection(connection);
String tableName = "employee";
httpTextDataProvider.exportToSQL(connection,
tableName);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection, name of the table and column names in which data is to be inserted. Specify table column as Null to skip that column for data export activity.
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
httpTextDataProvider.setConnection(connection);
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
httpTextDataProvider.exportToSQL(connection, tableName,
tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes and name of the table in which data is to be inserted.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
httpTextDataProvider.exportToSQL(databaseURL, driver, username,
password, tableName);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes, name of table and column names in which data is to be inserted. Specify table column as null to skip data export for that column.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
httpTextDataProvider.exportToSQL(databaseURL, driver, userName,
password, tableName, tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
6.2.2.3.1 Creating an instance of FTP Text Data Access Component
You can use following code to create an instance of FTP Text Data Access component.
com.elegantj.data.dataprovider.ftp.FTPTextDataProvider
ftpTextDataProvider
= new
com.elegantj.data.dataprovider.ftp.FTPTextDataProvider();
6.2.2.3.2 Configuring data source
Using ElegantJ FTP Text Data Access component you can connect to a Text file through File Name. It also allows to configure the FTP attributes.
Ø To set File Name
ftpTextDataProvider.setFile("/myfolder/myfile.txt");
Ø To set Host Name
ftpTextDataProvider.setHostName("elegantj");
Ø To set Port Number
ftpTextDataProvider.setPort(21);
Ø To set User Name
ftpTextDataProvider.setUserName("username");
Ø To set Password
ftpTextDataProvider.setPassword("password");
6.2.2.3.3 Configuring data retrieval
ElegantJ FTP Text Data Access component allows to set the row separator, column separator, text qualifier, columns fixed width, skip the first n rows, to skip specified columns, to restrict total number of fetched records at a time and allows to append or to replace existing data with the next retrieved data.
Ø To set the first row to contain column names
ftpTextDataProvider.setFirstRowAsColumnNames(true);
Ø To set columns delimited text or fixed width text
ftpTextDataProvider.setColumnsDelimited(true); // columns separated text
ftpTextDataProvider.setColumnsDelimited(false); // fixed width columns text
Ø To set row separator
ftpTextDataProvider.setRowSeparator("\n");
Ø To Set column separator
ftpTextDataProvider.setColumnSeparator(",");
Ø To set identifier of the text included in the column
ftpTextDataProvider.setTextQualifier("\"");
Ø To set columns fixed width
ftpTextDataProvider.setColumnsWidth("10,5,4,21");
Ø To set skipped rows
ftpTextDataProvider.setSkippedRows(10);
Ø To set skipped columns
ftpTextDataProvider.setSkippedColumns("0,3,5");
Ø To set Fetch Size
ftpTextDataProvider.setFetchSize(100);
Ø To append the next retrieved data to existing one
ftpTextDataProvider.setAppendDataOnFetchNext(true);
6.2.2.3.4 Retrieving data
Ø To retrieve data
ftpTextDataProvider.retrieve(); // Opens the connection and retrieve the data
Ø To retrieve data explicitly with specified remote path
ftpTextDataProvider.retrieveDataFromServer("/myfolder/myfile.txt");
Ø To retrieve next data, if the fetch size is specified and if it has more data
if(!ftpTextDataProvider.nextData())
System.out.println("Error
while retrieving more data");
6.2.2.3.5 Getting retrieved data information
Ø To get data from data provider
java.util.Vector
data = ftpTextDataProvider.getData();
Note: The number of records
that can be fetched at a time depends on fetch size. If fetch size is 100 and
total records are 1000, this method will return 100 records only. So, to get
next 100 records, nextData method should be called before calling this method.
Ø To get next 100 records, ftpDataProvider.nextData();
java.util.Vector data = ftpDataProvider.getData();
Ø To get data at specified record index.
java.util.Vector
record = ftpTextDataProvider.getDataAt(0);
Ø To get data at specified record index and specified column index.
Object
value = ftpTextDataProvider.getDataAt(0, 0);
Ø To get total number of records
int
totalRecords = ftpTextDataProvider.getDataCount();
Ø To get current record index
int
currentIndex = ftpTextDataProvider.getCurrentIndex();
Ø To get current record
java.util.Vector
record = ftpTextDataProvider.getCurrentRecord();
Ø To get total number of columns
int
totalColumns = ftpTextDataProvider.getColumnCount();
Ø To get column names
java.util.Vector
columnNames = ftpTextDataProvider.getColumnNames();
Ø To get column names as elements of an array
String[]
columnNames = ftpTextDataProvider.getColumnsArray();
Ø To get column index of specified column name
int
columnIndex =
ftpTextDataProvider.getColumnIndex("employee_name");
6.2.2.3.6 Navigating retrieved data
Ø To get the first record by positioning the cursor at first record
java.util.Vector
record = ftpTextDataProvider.firstRecord();
Ø To get the last record by positioning the cursor at last record
java.util.Vector
record = ftpTextDataProvider.lastRecord();
Ø To get the next record by positioning the cursor at next record
java.util.Vector
record = ftpTextDataProvider.nextRecord();
Ø To get the last record by positioning the cursor at last record
java.util.Vector
record = ftpTextDataProvider.previousRecord();
Ø To get the record by positioning the cursor at specified index
java.util.Vector
record = ftpTextDataProvider.scrollToRow(10);
6.2.2.3.7 Manipulating retrieved data
ElegantJ FTP Text Data Access component saves the data to the Text file.
Ø To set data (all the records)
java.util.Vector
data = java.util.Vector();
java.util.Vector vect = java.util.Vector(); // for the first row
vect.addElement("ID1"); // for the first column
vect.addElement("NAME1"); // for second column
vect.addElement("ADDRESS1"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for second row
vect.addElement("ID2"); // for the first column
vect.addElement("NAME2"); // for second column
vect.addElement("ADDRESS2"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for third row
vect.addElement("ID3"); // for the first column
vect.addElement("NAME3"); // for second column
vect.addElement("ADDRESS3"); // for third column
data.addElement(vect);
ftpTextDataProvider.setData(data);
Ø To set data (all the records) as elements of an array
java.util.Vector[]
data = new java.util.Vector[3];
data[0] = java.util.Vector(); // for the first row
data[0].addElement("ID1"); // for the first column
data[0].addElement("NAME1"); // for second column
data[0].addElement("ADDRESS1"); // for third column
data[1] = java.util.Vector(); // for second row
data[1].addElement("ID2"); // for the first column
data[1].addElement("NAME2"); // for second column
data[1].addElement("ADDRESS2"); // for third column
data[2] = java.util.Vector(); // for third row
data[2].addElement("ID3"); // for the first column
data[2].addElement("NAME3"); // for second column
data[2].addElement("ADDRESS3"); // for third column
ftpTextDataProvider.setDataArray(data);
Ø To ignore any changes made after last save and refresh data.
ftpTextDataProvider.refreshData();
Ø To append the given record at the end
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = ftpTextDataProvider.appendData(vect);
Ø To add the given record at the end
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
ftpTextDataProvider.addRow(vect);
Ø To remove current record
ftpTextDataProvider.deleteRow();
Ø To remove record at specified index
ftpTextDataProvider.removeAt(10);
Ø To remove all the records
ftpTextDataProvider.removeAll();
Ø To remove records in specified range
ftpTextDataProvider.removeRange(2,
10);
Ø To Insert specified record at specified index
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = ftpTextDataProvider.insertDataAt(vect, 3);
Ø To update record's data which resides at specified index of data provider
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
ftpTextDataProvider.modifyDataAt(vect,
3);
Ø To save only filtered data
ftpTextDataProvider.setSaveOnlyFilteredData(true);
Ø To save all the changes (such as add, delete, insert, update procedure) made to the text
ftpTextDataProvider.save();
Ø To save all the changes to the specified remote path
ftpTextDataProvider.saveDataToServer("/myfolder/myfile.txt");
ElegantJ FTP Text Data Access components also provides methods to get data about changes made to data and filtering.
Ø To get total number of modified records
int
modifiedRecords = ftpTextDataProvider.getModifiedCount();
Ø To get total number of deleted records
int
deletedRecords = ftpTextDataProvider.getDeletedCount();
Ø To get total number of filtered records
int
filteredRecords = ftpTextDataProvider.getFilteredCount();
6.2.2.3.8 Filtering data
ElegantJ FTP Text Data Access components provides data filtering.
A filter can be any expression. It can be arithmetical or data related expression.
Ø To enable the filtering
ftpTextDataProvider.setFilterState(true);
Ø To set filter criteria (it can be any arithmetic or data related expression).
ftpTextDataProvider.setFilterCriteria("employee_id
= 10");
Ø To filter the data with given filter condition (expression)
ftpTextDataProvider.filterData("employee_id
= 10");
6.2.2.3.9 Sorting data
ElegantJ FTP Text Data Access component allows to sort the data by column(s) and sorting order of columns. The string representation of the sorting is in the form of col1:true,col2:false. The following methods are used for data sorting.
Ø To set sorting criteria (it is string representation of the sorted column names and their sorting order).
ftpTextDataProvider.setSortingCriteria("employee_id:true,employee_name:false");
Ø To sort the data with given different arguments as
Ø By vector containing column names and its orders
java.util.Vector
sortColumns = new java.util.Vector();
java.util.Vector
sortColumn = new java.util.Vector();
sortColumn.addElement("employee_id");
sortColumn.addElement(new
Boolean(true));
sortColumns.addElement(sortColumn);
sortColumn
= new java.util.Vector();
sortColumn.addElement("employee_name");
sortColumn.addElement(new
Boolean(false));
sortColumns.addElement(sortColumn);
ftpTextDataProvider.sortData(sortColumns);
Ø By column names
ftpTextDataProvider.sortData(new
String[]{ "employee_id",
"employee_name"});
Ø By column indexes
ftpTextDataProvider.sortData(new
int[]{ 0, 1});
Ø By column names and their sorting order
ftpTextDataProvider.sortData(new
String[]{ "employee_id",
"employee_name"}, new boolean[]{
true, false});
Ø By column indexes and their sorting order
ftpTextDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false});
Ø By column names and range of the records to be sorted
ftpTextDataProvider.sortData(new
String[]{ "employee_id", "employee_name"}, 2 ,10);
Ø By column indexes and range of the records to be sorted
ftpTextDataProvider.sortData(new
int[]{ 0, 1}, 2 ,10);
Ø By column names, their sorting order and range of the records to be sorted
ftpTextDataProvider.sortData(new
String[]{ "employee_id", "employee_name" }, new boolean[]{
true, false },2 , 10);
Ø By column indexes, their sorting order and range of the records to be sorted
ftpTextDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false}, 2 ,10);
6.2.2.3.10 Searching data
ElegantJ FTP Text Data Access component has feature of data search. Any expression can be used as search criteria. ElegantJ FTP Text Data Access component also provides Find Next functionality. Following methods are used for data search:
Ø To search data on given expression or any condition within the given range of the records (optional)
int
index = ftpTextDataProvider.find("employee_id == 10", 2, 10);
Ø To search the next record with given search criteria.
int
index = ftpTextDataProvider.findNext();
6.2.2.3.11 Exporting data as text
ElegantJ FTP Text Data Access component allows to export data as column separated text or fixed width column text. It also allows to set default attributes to export the data as text.
Ø To set default exporting attributes
ftpTextDataProvider.SetColumnsDelimited(true); // Sets data being exported as column separated text
ftpTextDataProvider.SetColumnsDelimited(false); // Sets data being exported as fixed width column text
ftpTextDataProvider.SetFirstRowAsColumnNames(true); // Sets the first row being exported as column names
ftpTextDataProvider.SetRowSeparator("\n"); // Sets the row separator
ftpTextDataProvider.SetColumnSeparator(","); // Sets the column separator
ftpTextDataProvider.SetTextQualifier("\""); // Sets the text identifier
ftpTextDataProvider.SetColumnsWidth("10,5,4,21"); // Sets the fixed width of each column
Ø To export data as Text to specified OutputStream using default attributes
try
{
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
ftpTextDataProvider.exportToText(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
Ø To export data as column separated Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnSeparator = ",";
String textQualifier = "\"";
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
ftpTextDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnSeparator, textQualifiers);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
Ø To export data as fixed width column Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnsWidth = "10, 4, 14,
5";
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
ftpTextDataProvider.exportToText(out,
rowSeparator,
firstRowAsColumnNames, columnsWidth);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
Ø To export data as Text to specified OutputStream by specified attributes, specify null argument which is not required
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
boolean columnsDelimited = true;
String columnSeparator = ",";
String textQualifier = "\"";
String columnsWidth = null;
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
ftpTextDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnsDelimited, columnSeparator,
textQualifier, columnsWidth); // Exports data as the column separated text
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
6.2.2.3.12 Exporting data as XML
ElegantJ FTP Text Data Access component allows to export data as XML. You can also set default attributes to export the data as XML.
Ø To set default exporting attributes
ftpTextDataProvider.SetRootTag("Report"); // Sets root tag identifier
ftpTextDataProvider.SetRowTag("Row"); // Sets row tag identifier
ftpTextDataProvider.SetColumnTag("Column"); // Sets column tag identifier
ftpTextDataProvider.SetFirstRowAsColumnNames(true); // Sets first exporting row as column names
Ø To export data as XML to specified OutputStream by default attributes
try
{
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.xml");
ftpTextDataProvider.exportToXML(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while exporting the data as XML");
}
Ø To export data as XML to specified OutputStream by specified attributes
try
{
String rootTag = "Root";
String rowTag = "Row";
String columnTag = "Column";
boolean firstRowAsColumnNames = true;
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.xml");
ftpTextDataProvider.exportToXML(out,
rootTag, rowTag, columnTag, firstRowAsColumnNames);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as XML");
}
6.2.2.3.13 Exporting data as SQL
ElegantJ FTP Text Data Access component allows to export the data to any RDBMS.
Ø To export data as SQL to a database by specifying connection and name of the table in which data is to be inserted
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
ftpTextDataProvider.setConnection(connection);
String tableName = "employee";
ftpTextDataProvider.exportToSQL(connection,
tableName);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection, name of the table and column names in which data is to be inserted. Specify table column as Null to skip that column for data export activity.
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
ftpTextDataProvider.setConnection(connection);
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
ftpTextDataProvider.exportToSQL(connection,
tableName,
tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes and name of the table in which data is to be inserted.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
ftpTextDataProvider.exportToSQL(databaseURL, driver, username, password,
tableName);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes, name of table and column names in which data is to be inserted. Specify table column as null to skip data export for that column.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
ftpTextDataProvider.exportToSQL(databaseURL, driver, userName, password,
tableName, tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
6.2.3ElegantJ XML Data Access Component
6.2.3.1 Creating an instance of XML Data Access Component
You can use following code to create an instance of XML Data Access component.
com.elegantj.data.dataprovider.xml.XMLDataProvider
xmlDataProvider = new com.elegantj.data.dataprovider.xml.XMLDataProvider();
6.2.3.2 Configuring data source
Using ElegantJ XML Data Access component you can connect to a Text file through File Name or URL.
Ø To Set the File Name
xmlDataProvider.setURLConnectionEnabled(false); // Disable URL connection
xmlDataProvider.setFile("c://myfolder/myfile.xml");
Ø To Set the URL
xmlDataProvider.setURLConnectionEnabled(true); // Enable the URL connection
xmlDataProvider.setURL("http://localhost/myfolder/myfile.xml");
6.2.3.3 Configuring data retrieval
ElegantJ XML Data Access component allows to set the root tag identifier, the row tag identifier, the column tag identifier, to skip the first n rows.
Ø To Set the first row to contain column names
xmlDataProvider.setFirstRowAsColumnNames(true);
Ø To set root tag identifier
xmlDataProvider.setRootTag("Report");
Ø To set row tag identifier
xmlDataProvider.setRowTag("Row");
Ø To set column tag identifier
xmlDataProvider.setColumnTag("Column");
Ø To skip a set of rows
xmlDataProvider.setSkippedRows(10);
Ø To retrieve data
xmlDataProvider.retrieve();
// Opens a connection and retrieves data
Ø To retrieve data explicitly with specified InputStream
try
{
java.io.FileInputStream in = new
java.io.FileInputStream("c://myfolder/myfile.xml");
if(!xmlDataProvider.retrieveData(in))
System.out.println("Error while
retrieving data");
in.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
opening the file");
}
6.2.3.5 Getting retrieved data information
Ø To get retrieved data.
java.util.Vector
data = xmlDataProvider.getData();
Ø To get data at specified record index.
java.util.Vector
record = xmlDataProvider.getDataAt(0);
Ø To get data at specified record index and specified column index.
Object
value = xmlDataProvider.getDataAt(0, 0);
Ø To get total number of records
int
totalRecords = xmlDataProvider.getDataCount();
Ø To get current record index
int
currentIndex = xmlDataProvider.getCurrentIndex();
Ø To get current record
java.util.Vector
record = xmlDataProvider.getCurrentRecord();
Ø To get total number of columns
int
totalColumns = xmlDataProvider.getColumnCount();
Ø To get column names
java.util.Vector
columnNames = xmlDataProvider.getColumnNames();
Ø To get column names in the array representation
String[]
columnNames = xmlDataProvider.getColumnsArray();
Ø To get the column index of the specified column name
int
columnIndex = xmlDataProvider.getColumnIndex("employee_name");
6.2.3.6 Navigating retrieved data
Ø To get the first record by positioning the cursor at first record
java.util.Vector
record = xmlDataProvider.firstRecord();
Ø To get the last record by positioning the cursor at last record
java.util.Vector
record = xmlDataProvider.lastRecord();
Ø To get the next record by positioning the cursor at next record
java.util.Vector
record = xmlDataProvider.nextRecord();
Ø To get the last record by positioning the cursor at last record
java.util.Vector
record = xmlDataProvider.previousRecord();
Ø To get the record by positioning the cursor at specified index
java.util.Vector
record = xmlDataProvider.scrollToRow(10);
6.2.3.7 Manipulating retrieved data
ElegantJ XML Data Access component saves the data to the Text file.
Ø To set data (all the records)
java.util.Vector
data = java.util.Vector();
java.util.Vector vect = java.util.Vector(); // for the first row
vect.addElement("ID1"); // for the first column
vect.addElement("NAME1"); // for second column
vect.addElement("ADDRESS1"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for second row
vect.addElement("ID2"); // for the first column
vect.addElement("NAME2"); // for second column
vect.addElement("ADDRESS2"); // for third column
data.addElement(vect);
vect = java.util.Vector(); // for third row
vect.addElement("ID3"); // for the first column
vect.addElement("NAME3"); // for second column
vect.addElement("ADDRESS3"); // for third column
data.addElement(vect);
xmlDataProvider.setData(data);
Ø To set the data (all the records) as elements of an array
java.util.Vector[]
data = new java.util.Vector[3];
data[0] = java.util.Vector(); // for the first row
data[0].addElement("ID1"); // for the first column
data[0].addElement("NAME1"); // for second column
data[0].addElement("ADDRESS1"); // for third column
data[1] = java.util.Vector(); // for second row
data[1].addElement("ID2"); // for the first column
data[1].addElement("NAME2"); // for second column
data[1].addElement("ADDRESS2"); // for third column
data[2] = java.util.Vector(); // for third row
data[2].addElement("ID3"); // for the first column
data[2].addElement("NAME3"); // for second column
data[2].addElement("ADDRESS3"); // for third column
xmlDataProvider.setDataArray(data);
Ø To ignore any changes made after last save and refresh data.
xmlDataProvider.refreshData();
Ø To append given record to the end
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = xmlDataProvider.appendData(vect);
Ø To add given record to the end
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
xmlDataProvider.addRow(vect);
Ø To remove current record
xmlDataProvider.deleteRow();
Ø To remove record at a specified index
xmlDataProvider.removeAt(10);
Ø To remove all the records
xmlDataProvider.removeAll();
Ø To remove the records in a specified range
xmlDataProvider.removeRange(2,
10);
Ø To insert specified record at specified index
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
int
recordIndex = xmlDataProvider.insertDataAt(vect, 3);
Ø To update the record's data which resides at specified index to data provider
java.util.Vector
vect = java.util.Vector();
vect.addElement("ID"); // for the first column
vect.addElement("NAME"); // for second column
vect.addElement("ADDRESS"); // for third column
xmlDataProvider.modifyDataAt(vect,
3);
Ø To save only filtered data
xmlDataProvider.setSaveOnlyFilteredData(true);
Ø To save all the changes (such as add, delete, insert, update procedure) made to the XML
xmlDataProvider.save();
Ø To Save all the changes to specified OutputStream
try
{
java.io.FileOutputStream out = new
java.io.FileOutputStream("d://myfolder/myfile.xml");
if(!xmlDataProvider.saveData(out))
System.out.println("Error while
saving data");
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
opening the file");
}
ElegantJ XML Data Access component also provides methods to get data about changes made to the data and filtering.
Ø To get total number of modified records
int
modifiedRecords = xmlDataProvider.getModifiedCount();
Ø To get total number of deleted records
int
deletedRecords = xmlDataProvider.getDeletedCount();
Ø To get total number of filtered records
int
filteredRecords = xmlDataProvider.getFilteredCount();
ElegantJ XML Data Access component provides the filtering data.
A filter can be any expression. It can be arithmetical or data related expression.
Ø To enable filtering
xmlDataProvider.setFilterState(true);
Ø To set filter criteria (it can be any arithmetic or data related expression.)
xmlDataProvider.setFilterCriteria("employee_id
= 10");
Ø To filter data with given filter condition (expression)
xmlDataProvider.filterData("employee_id
= 10");
ElegantJ XML Data Access component allows to sort the data by column(s) and sorting order for each column. The string representation of sorting is in the form of col1:true,col2:false. Following methods are used for data sorting:
Ø To set sorting criteria (it is string representation of the sorted column names and their sorting order)
xmlDataProvider.setSortingCriteria("employee_id:true,employee_name:false");
Ø To Sort the data with given different arguments as
Ø By vector containing column names and its orders
java.util.Vector
sortColumns = new java.util.Vector();
java.util.Vector
sortColumn = new java.util.Vector();
sortColumn.addElement("employee_id");
sortColumn.addElement(new
Boolean(true));
sortColumns.addElement(sortColumn);
sortColumn
= new java.util.Vector();
sortColumn.addElement("employee_name");
sortColumn.addElement(new
Boolean(false));
sortColumns.addElement(sortColumn);
xmlDataProvider.sortData(sortColumns);
Ø By column names
xmlDataProvider.sortData(new
String[]{ "employee_id", "employee_name"});
Ø By column indexes
xmlDataProvider.sortData(new
int[]{ 0, 1});
Ø By column names and their sorting order
xmlDataProvider.sortData(new
String[]{ "employee_id", "employee_name"}, new boolean[]{
true, false});
Ø By column indexes and their sorting order
xmlDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false});
Ø By column names and range of the records to be sorted
xmlDataProvider.sortData(new
String[]{ "employee_id", "employee_name"}, 2 ,10);
Ø By column indexes and range of the records to be sorted
xmlDataProvider.sortData(new
int[]{ 0, 1}, 2 ,10);
Ø By column names, their sorting order and range of the records to be sorted
xmlDataProvider.sortData(new
String[]{ "employee_id", "employee_name" }, new boolean[]{
true, false },2 , 10);
Ø By column indexes, their sorting order and range of the records to be sorted
xmlDataProvider.sortData(new
int[]{ 0, 1}, new boolean[]{ true, false}, 2 ,10);
ElegantJ XML Data Access component has feature of data search. Any expression can be used as search criteria. ElegantJ XML Data Access component also provides find Next functionality. Following methods are used for data search -
Ø To Search the data on given expression or any condition within given range of the records (optional)
int
index = xmlDataProvider.find("employee_id == 10", 2, 10);
Ø To Search the next record with the given search criteria.
int
index = xmlDataProvider.findNext();
6.2.3.11 Exporting data as Text
ElegantJ XML Data Access component allows to export data as column separated text or fixed width column text. It also allows to set default attributes to export the data as text.
Ø To set default exporting attributes
xmlDataProvider.SetColumnsDelimited(true); // Sets data being exported as column separated text
xmlDataProvider.SetColumnsDelimited(false); // Sets data being exported as fixed width column text
xmlDataProvider.SetFirstRowAsColumnNames(true); // Sets the first row being exported as column names
xmlDataProvider.SetRowSeparator("\n"); // Sets the row separator
xmlDataProvider.SetColumnSeparator(","); // Sets the column separator
xmlDataProvider.SetTextQualifier("\""); // Sets the text identifier
xmlDataProvider.SetColumnsWidth("10,5,4,21"); // Sets the fixed width of each column
Ø To export data as Text to specified OutputStream using default attributes
try
{
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
xmlDataProvider.exportToText(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
Ø To export data as column separated Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnSeparator = ",";
String textQualifier = "\"";
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
xmlDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnSeparator, textQualifiers);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
Ø To export data as fixed width column Text to specified OutputStream by specified attributes
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
String columnsWidth = "10, 4, 14,
5";
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
xmlDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnsWidth);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
Ø To export data as Text to specified OutputStream by specified attributes, specify null argument which is not required
try
{
String rowSeparator = "\n";
boolean firstRowAsColumnNames = true;
boolean columnsDelimited = true;
String columnSeparator = ",";
String textQualifier = "\"";
String columnsWidth = null;
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.text");
xmlDataProvider.exportToText(out,
rowSeparator, firstRowAsColumnNames, columnsDelimited, columnSeparator,
textQualifier, columnsWidth); // Exports data as the column separated text
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as text");
}
6.2.3.12 Exporting data as XML
ElegantJ XML Data Access component allows to export data as XML. You can also set default attributes to export the data as XML.
Ø To set default exporting attributes
xmlDataProvider.SetRootTag("Report"); // Sets root tag identifier
xmlDataProvider.SetRowTag("Row"); // Sets row tag identifier
xmlDataProvider.SetColumnTag("Column"); // Sets column tag identifier
xmlDataProvider.SetFirstRowAsColumnNames(true); // Sets first exporting row as column names
Ø To export data as XML to specified OutputStream by default attributes
try
{
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.xml");
xmlDataProvider.exportToXML(out);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as XML");
}
Ø To export data as XML to specified OutputStream by specified attributes
try
{
String rootTag = "Root";
String rowTag = "Row";
String columnTag = "Column";
boolean firstRowAsColumnNames = true;
java.io.FileOutputStream out = new
java.io.FileOutputStream("myfile.xml");
xmlDataProvider.exportToXML(out, rootTag,
rowTag, columnTag, firstRowAsColumnNames);
out.close();
}
catch(java.io.IOException e) {
System.out.println("Error while
exporting the data as XML");
}
6.2.3.13 Exporting data as SQL
ElegantJ XML Data Access component allows to export the data to any RDBMS.
Ø To export data as SQL to a database by specifying connection and name of the table in which data is to be inserted
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
xmlDataProvider.setConnection(connection);
String tableName = "employee";
xmlDataProvider.exportToSQL(connection,
tableName);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection, name of the table and column names in which data is to be inserted. Specify table column as Null to skip that column for data export activity.
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
DriverManager.getConnection("jdbc:odbc:dsn", "username",
"password");
xmlDataProvider.setConnection(connection);
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
xmlDataProvider.exportToSQL(connection,
tableName, tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes and name of the table in which data is to be inserted.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
xmlDataProvider.exportToSQL(databaseURL,
driver, username, password, tableName);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Ø To export data as SQL to a database by specifying connection attributes, name of table and column names in which data is to be inserted. Specify table column as null to skip data export for that column.
try
{
String databaseURL =
"jdbc:odbc:dsn";
String driver =
"sun.jdbc.odbc.JdbcOdbcDriver";
String userName = "username";
String password = "password";
String tableName = "employee";
String[] tableColumns = new String[]
{"employee_name", null, "employee_address"};
xmlDataProvider.exportToSQL(databaseURL,
driver, userName, password, tableName, tableColumns);
}
catch(ClassNotFoundException e) {
System.out.println("Error while
loading the driver class);
}
catch(java.sql.SQLException e) {
System.out.println("Error while
exporting the data as SQL");
}
Product and Support Information:
Ø You can find more information about ElegantJ Data Tables and its features on www.ElegantJBeans.com.
Ø Forward your support related mails to support@ElegantJBeans.com.
Ø Forward your sales related mails to sales@ElegantJBeans.com.
Feedback and Suggestions:
Ø We will be pleased to get your feedback as well as suggestions about our product.
Ø Forward any feedback or suggestions related mails to support@ElegantJBeans.com.