ElegantJBeans – Data Trees
Programmers’ Guide
ElegantJBeans – Data Tree Programmers Guide
Table of Content
3.1.1 ElegantJ AWT Data Tree JavaBean
3.1.1.1 Appearance and Visual Appeal
3.1.1.3 Data Exchange, Handling and
Management
3.1.2 ElegantJ JFC Data Tree JavaBean
3.1.2.1 Appearance and Visual Appeal
3.1.2.3 Data Exchange, Handling and
Management
3.2 ElegantJ
Data Access Component
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 ElegantJ AWT Data Tree JavaBean
6.1.1.1 Creating an instance of
AWTDataTreeViewer
6.1.1.2 Applying general appearance and
formatting
6.1.1.3 Configuring node attributes for whole
tree
6.1.1.4 Configuring level wise node
attributes
6.1.1.6 Setting row height attributes
6.1.1.7 Configuring selection functionality
6.1.1.9 Using insert key and delete key
6.1.1.10 Configuring drag and drop
6.1.1.11 Configuring search panel
6.1.1.13 Configuring popup menu
6.1.1.14 Configuring checkbox tree
and features under checkbox tree
6.1.1.15 Configuring child-parent
relationship in checkbox tree
6.1.1.16 Restricting duplicate
nodes
6.1.1.17 Making use of Advanced
Implementation for creating custom cell renderers
6.1.1.18 AWT Data Tree Listeners
and Events
6.1.1.19 Configuring data access
component with AWTDataTreeViewer
6.1.1.20 Making Master-Detail
relationship
6.1.1.21 Handlign data navigation
functionality
6.1.1.22 Handling data
modification
6.1.2 ElegantJ JFC Data Tree JavaBean
6.1.2.1 Creating an instance of
DataTreeViewer
6.1.2.2 Configuring general appearance
6.1.2.3 Configuring level wise node
attributes
6.1.2.4 Configuring root of tree
6.1.2.5 Configuring row attributes
6.1.2.8 Use of insert key and delete key
6.1.2.9 Configuring drag and drop
6.1.2.10 Configuring search panel
6.1.2.11 Searching for information
6.1.2.13 Setting visibility and
popup menu
6.1.2.14 Configuring checkbox tree
and features under checkbox tree
6.1.2.15 Configuring child-parent
relationship in checkbox tree
6.1.2.16 Restricting duplicate
nodes
6.1.2.17 Configuring data access
component with DataTreeViewer
6.1.2.18 Handling data navigation
6.1.2.19 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.1.1 Creating an instance of
text data access component
6.2.2.1.2 Configuring data source
6.2.2.1.3 Configuring data
retrieval
6.2.2.1.5 Getting retrieved data
information
6.2.2.1.6 Navigating retrieved data
6.2.2.1.7 Manipulating retrieved
data
6.2.2.1.11 Exporting data as Text
6.2.2.1.12 Exporting data as XML
6.2.2.1.13 Exporting 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
6.2.2.2.2 Configuring data source
6.2.2.2.3 Configuring data retrieval
6.2.2.2.5 Getting retrieved data
information
6.2.2.2.6 Navigating retrieved data
6.2.2.2.7 Manipulating retrieved
data
6.2.2.2.11 Exporting data as text
6.2.2.2.12 Exporting data as XML
6.2.2.2.13 Exporting data as SQL
6.2.2.3.1 Creating an instance of
FTP text data access component
6.2.2.3.2 Configuring data source
6.2.2.3.3 Configuring data
retrieval
6.2.2.3.5 Getting retrieved data
information
6.2.2.3.6 Navigating retrieved data
6.2.2.3.7 Manipulating retrieved
data
6.2.2.3.11 Exporting data as text
6.2.2.3.12 Exporting data as XML
6.2.2.3.13 Exporting data as SQL
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 |
6 |
|
Assumptions |
6 |
|
Document Organization |
6 |
|
Conventions Used |
7 |
The purpose of this document is to provide the fundamental skills necessary to productively install, program, integrate, and use the ElegantJ Data Trees. 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
Trees |
Ø What’s New Ø Toolkit |
|
Features |
Ø Ø ElegantJ Data Trees Beans Ø ElegantJ 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 trees Ø 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. |
2 About ElegantJ Data Trees
ElegantJ Data Trees Bean has all the features that you need to create a dynamically created data driven tree. It provides the best performance to suit your need of large number of nodes and levels in a tree. This Java Bean can handle large volume of data at unmatched speeds - let the data be in local computer or on server.
Ø Completely configurable
Ø Use any component as node
Ø Format controls for whole tree, for selected level as well as a node
Ø Use ready to use functionalities of Search Panel and Sort
Ø Also, functionality of insert, delete and add node.
Using ElegantJ Data Trees Beans, you can manage more information in the minimum space.
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.
This collection is derived from our Tree collection. ElegantJ Data Trees is a whole new Java Beans collection designed to cater when you wish to work with data in tree form. Use this bean specially when you need Data Aware Trees.
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 Trees is shipped with two set of Beans -
ElegantJ Data Trees Beans
ElegantJ Data Trees Beans includes AWT and JFC Data Tree Beans -
Ø AWT Data Tree Bean
o ElegantJ AWT Data Tree (awtdatatreeviewer.jar)
Ø JFC Data Tree Bean
o ElegantJ JFC Data Tree (datatreeviewer.jar)
ElegantJ Data Providers Beans
ElegantJ Data Trees Beans use following data access components to exchange data from source. All of these data access components can be bound with AWT Data Tree as well as JFC Data Tree.
Ø 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 Trees Beans
3.1.1.1 Appearance and Visual Appeal
Ø General appearance control features like background, borders, fonts, cursor type, etc.
o Background of tree can be set.
o Background color for node that is selected and not selected can be set.
o Text color for node that is s elected and not selected can be set.
o In this JavaBean, you can set Font properties.
o Border color for node that is selected and not selected.
o Locale can be set in ElegantJ AWT Data Tree Java Bean.
o Cursor styles can be customized.
Ø Appearance control - Level wise or for whole tree. With ElegantJ AWT Data Tree Bean, you can control visual properties based on levels as well as for whole tree.
o You can set visual properties for entire tree or for a level of node.
o The properties that you can set are -
§ Background color for Selected / Not selected node
§ Text color for Selected / Not selected node
§ Image for opened (expanded) node / closed (collapsed) node and Leaf node.
§ Border color for selected node.
o Cell Renderers and Cell Editors can be applied to whole tree as well as to selected level using ElegantJ AWT Data Tree JavaBean.
o You can choose from following cell renderers that come with this Java Bean,
§ Check box cell renderer
§ Choice (combo box) cell renderer
§ Label cell renderer
§ Text area cell renderer.
o You can choose from following cell editors that come with this Java Bean,
§ Check box cell editor
§ Choice (combo box) cell editor
§ Text editor and
§ Text area cell editor.
Ø Appearance for line that connects nodes.
o A line connects nodes. You can set appearance for this line using ElegantJ AWT Tree Java Beans.
o You may have a line that is straight or dotted. You can set color of line too.
Ø With this JavaBean, you can set gap between each line of information.
o You have option to set gap between two row of information. Gap can be reduced to have more information in available area. In ElegantJ JavaBeans, gap can be increased to make information easier to read. It is set in terms of pixels.
Ø Root / root handle - Make it Visible / Invisible.
o If there is a need of hiding root, you can do it using ElegantJ AWT Data Tree JavaBeans.
o ElegantJ AWT Data Tree Java Beans also gives facility to hide root handle.
Ø Option to select single node or multiple nodes.
o Your application can provide ability for selection of single node as well as multiple nodes.
Ø Insert and Delete a node using Insert and Delete key respectively on the keyboard. If used with Data Tree, this will insert / delete a record respectively in the database.
Ø In ElegantJ AWT Data Tree Java Bean, F2 key stroke can be used to start editing of a node. You can get the same functionality on mouse-clicks. Also setup number of mouse-clicks required to start editing.
Ø Drag-and-drop functionality for tree nodes. Child branches, moved with respective parent.
Ø Ready to use Right-click menu with frequently used options. Customization is possible.
o ElegantJ AWT Data Tree Java Bean is shipped with feature to implement Right click menu having four options (Add Child, Insert Node, Delete Node and Edit Node).
o If needed, APIs are available as part of ElegantJ AWT Data Tree JavaBean can be used to create menu as per requirement.
Ø Record Navigation (first, last, previous, next) feature for Data Trees.
3.1.1.3 Data Exchange, Handling and Management
Ø Seamless connectivity with databases through SQL, XML, FTP, HTTP and Text.
Ø ElegantJ AWT Data Tree Java Bean is shipped with Data Access Components. Data exchange is possible between tree and data source through Data Access Components.
ElegantJ data aware beans can be used for different data sources including databases, text files and XML. It's unique data access interface which can work across protocols like JDBC, HTTP and FTP, makes it possible for ElegantJ data aware beans to be deployed in almost any deployment architecture and environment. With it's capability to access various type of data sources through different protocols.
It works around three main interfaces.
o Data Access Component: It is possible to access any database, Text or XML data through JDBC (All four types of JDBC Drivers supported), HTTP or FTP. It acts as a data buffer between data source and data viewer.
o Data Viewer: Data viewer gets attached to Data Access Component and works seamlessly to view or manipulate the data in the data source of the data provider.
o Data Navigator: This is set of controls who control the behavior of data in data viewer/manipulator. It can have operations like First, Last, Next, Previous, Add, Save, Delete, etc.
It’s Features are:
o Access any data source (Database, XML or Text files) through different protocols (JDBC - All four types, FTP & HTTP).
o Makes it possible to access almost any data in any deployment architecture.
o Accessing and manipulating any database supporting any of the four types of JDBC drivers.
o Accessing and manipulating text / XML through HTTP protocol. This can help you even push your text or XML data through your ASP, JSP, Servlet, PHP or CGI pages also.
o Ready navigation panel for Add, update . . . . . or use these methods in data viewer, through your program.
Ø Ready to use, feature packed Search Panel. Search at selected level or entire tree. Availability of ready-to-use search panel. You can locate it on the top or bottom of the screen.
o Search is the first step for to view and manage information. Using ElegantJ AWT Tree Java Bean, your application can have feature to search for a text in a tree. Search can be performed on entire tree or at selected level.
o Search can be performed downwards from first node / selected node, upwards from last node / selected node.
o In ElegantJ AWT Data Tree JavaBean, search can be performed for total equality, availability of search string as part of value in tree nodes, for value in tree nodes starting with search string as well as for value in tree nodes ending with search string.
o Search is conducted with or without case sensitivity.
o Delete Record / Insert record function can be implemented.
Ø Using ElegantJ AWT Data Tree Java Bean, you can use different cell editors and cell renderers. To make things faster, you can have same cell editor or cell renderer for entire tree or different cell editor or renderer at different levels.
Node Cell Renderer
In ElegantJ AWT Data Tree Java Bean, you can set cell renderer to whole tree or level wise. That is, different cell renderer for nodes for different level.
Bean is shipped with following renderers -
o Checkbox cell renderer
o Choice (combo box) cell renderer
o Label cell renderer
o Text area cell renderer
Node Cell Editor
In ElegantJ AWT Data Tree JavaBean, you can set cell editor to whole tree or level wise. That is, different cell editor for nodes for different level.
Bean is shipped with following editors -
o Checkbox cell editor
o Choice (combo box) cell editor
o Text editor
o Text area cell editor
Ø Facility to setup Check box tree with child parent relationship. Developer can give user, a functionality to have entire tree as a check box tree. This feature of ElegantJ AWT Data Tree Bean has other functionalities too. You can have entire tree with check boxes.
o ElegantJ AWT Data Tree maintains Child Parent relationship. This means, if a user checks any node then all its children (recursive) becomes checked. If user unchecks any node then all the parents (recursive) become unchecked, so every checked node has all the children (recursive) as checked and every unchecked node has all the parents (recursive) as unchecked.
o ElegantJ AWT Data Tree Java Bean facilitates user to get the checked or unchecked nodes for the whole tree or at specific level.
o You have option to set a tree as editable (where user can make changes into existing tree), or not editable.
Ø If required, validations can be implemented for not accepting two nodes with same value (name) for any parent node.
3.1.2.1 Appearance and Visual Appeal
Ø General appearance like background, borders, fonts, cursor type, etc.
o In this Java Bean, you can set basic look and feel properties - Background, Foreground, Font, Locale, Cursor style, enable / disable, Visible / Invisible.
o Swing Look and feel properties that this JavaBean support are - Lightweight, Opaque, Tool-tip text, Double buffering, Ability to receive and manage Focus, Border, Auto-scrolling.
Ø In this Java Bean, you can set appearance control based on level.
o You can set visual properties for a level of node.
o Level wise node attributes available in ElegantJ JFC Data Tree Java Bean are,
§ Background non selection color
§ Background selection color
§ Text non selection color
§ Text selection color
§ Border selection color
§ Opened image icon
§ Closed image icon
§ Leaf image icon
§ Cell renderer
§ Cell editor
o You can apply same cell renderers and cell editors to whole tree as well as different cell renderers and cell editors at different levels.
o You can choose from following cell renderers that come with ElegantJ JFC Data Tree JavaBean,
§ Boolean cell renderer
§ Checkbox cell renderer
§ Choice cell renderer
§ Color cell renderer
§ Date cell renderer
§ Default cell renderer
§ Icon cell renderer
§ MultiLine cell renderer
§ MultiOption cell renderer
§ Number cell renderer
§ Progress cell renderer
§ RadioButton cell renderer
§ Text cell renderer
o You can choose from following cell editors that come with ElegantJ JFC Data Tree Java Bean,
§ Boolean cell editor
§ Checkbox cell editor
§ Choice cell editor
§ Color cell editor
§ Date cell editor
§ Default cell editor
§ Icon cell editor
§ MultiLine cell editor
§ MultiOption cell editor
§ Number cell editor
§ RadioButton cell editor
§ Slider cell editor
Ø Gap between each line of information.
o In ElegantJ JFC Data Tree Java Bean, you have option to set gap between two row of information. Gap can be reduced to have more information in available area. Gap can be increased to make information easier to read.
o This JavaBean allows you to set number of rows to be displayed without scrollbars.
Ø Appearance of root / root handle. Make it invisible to give a feel of independent trees.
o If there is a need of hiding root, you can do it using ElegantJ JFC Data Tree JavaBeans.
o ElegantJ JFC Data Tree Java Beans also gives facility to hide root handle.
Ø Option to select single node or multiple nodes.
o Your application can have feature to be able to select one cell as well as multiple cells. This JavaBean supports selection that is single, multiple or set of selections.
Ø Insert and Delete a node using Insert and Delete key. For Data Tree, this will insert / delete a record respectively.
Ø In ElegantJ JFC Data Tree Java Bean, F2 keystroke can be used to start editing of a node. Same functionality can be implemented on mouse-clicks.
Ø ElegantJ JFC Data Tree JavaBean provides Drag-and-drop functionality for tree nodes. For node with child branches, it moves all the branches along with respective parent.
Ø Ready to use Fully featured Search Panel. Search for a text on node or entire tree. Ready to use Search Panel.
o Search is the first step for to view and manage information. Using ElegantJ JFC Data Tree Java Bean, your application can have feature to search for a text in a tree. You can perform search on selected level or entire tree.
o Search can be performed downwards from first node or selected node, upwards from last node or selected node.
o Search can be performed for -
§ Exact match with search string
§ For nodes having search string
§ For nodes starting with search string, as well as
§ For nodes ending with search string.
o In this JavaBean, you have an option to conduct a search with or without case sensitivity.
Ø Ready to use and customizable Right-click menu with frequently used options.
o ElegantJ JFC Data Tree JavaBean is shipped with feature of Right click menu having options - Add Child, Insert Node, Delete Node, Edit Node as well as Sort. ElegantJ JFC Data Tree Java Bean can be used to create menu as per requirement.
Ø For Data trees, Record Navigation (first, last, previous, next, etc.) feature can be implemented.
Ø AutoSave with Accidental Interruption. If a node is being edited, and control is transferred out of the node, the changed work will be automatically saved.
Ø Auto-scroll node's descendents when a node is expanded. Available as Customizable property.
3.1.2.3 Data Exchange, Handling and Management
Ø Configurable Data Model. ElegantJ JFC Data Tree bean offers option to configure data model. Option is available to use large data model.
Ø ElegantJ JFC Data Tree JavaBean is shipped with Data Access Components. A tree can exchange data from data source through Data Access Components.
ElegantJ data aware beans can be used for different data sources including databases, text files and XML. It's unique data access interface which can work across protocols like JDBC, HTTP and FTP, makes it possible for ElegantJ data aware beans to be deployed in almost any deployment architecture and environment. With it's capability to access various type of data sources through different protocols.
It works around three main interfaces.
o Data Access Component: It is possible to access any database, Text or XML data through JDBC (All four types of JDBC Drivers supported), HTTP or FTP. It acts as a data buffer between data source and data viewer.
o Data Viewer: Data viewer gets attached to Data Access Component and works seamlessly to view or manipulate the data in the data source of the data provider.
o Data Navigator: This is set of controls who control the behavior of data in data viewer/manipulator. It can have operations like First, Last, Next, Previous, Add, Save, Delete, etc.
Its features are:
o Access any data source (Database, XML or Text files) through different protocols (JDBC - All four types, FTP & HTTP).
o Makes it possible to access almost any data in any deployment architecture.
o Accessing and manipulating any database supporting any of the four types of JDBC drivers.
o Accessing and manipulating text / XML through HTTP protocol. This can help you even push your text or XML data through your ASP, JSP, Servlet, PHP or CGI pages also.
o Ready navigation panel for Add, update . . . . . or use these methods in data viewer, through your program.
Ø Search for a text on node or entire tree. Ready to use Search Panel.
o Search is the first step for to view and manage information. Using ElegantJ JFC Data Tree Java Bean, your application can have feature to search for a text in a tree. You can perform search on selected level or entire tree.
o Search can be performed downwards from first node or selected node, upwards from last node or selected node.
o Search can be performed for -
§ Exact match with search string
§ For nodes having search string
§ For nodes starting with search string, as well as
§ For nodes ending with search string.
o In this JavaBean, you have an option to conduct a search with or without case sensitivity.
Ø ElegantJ JFC Data Tree Java Bean has feature to sort children of any node or whole tree in ascending or descending order.
Ø Delete Record/Insert record function can be implemented.
Ø Node Cell Renderers and Renderers. Using ElegantJ JFC Data Tree Java Bean, you can use different editors and renderers. To make things faster, you can have same cell editor and cell renderer for entire tree as well as different ones for different levels.
Node Cell Renderer
In ElegantJ JFC Data Tree Java Bean, you can set cell renderer to whole tree or level wise. That is, different cell renderer for nodes for different level.
Bean is shipped with following renderers -
o Boolean cell renderer
o Checkbox cell renderer
o Choice cell renderer
o Color cell renderer
o Date cell renderer
o Default cell renderer
o Icon cell renderer
o MultiLine cell renderer
o MultiOption cell renderer
o Number cell renderer
o Progress cell renderer
o RadioButton cell renderer
o Text cell renderer
Node Cell Editor
In ElegantJ JFC Data Tree JavaBean, you can set cell editor to whole tree or level wise. That is, different cell editor for nodes for different level.
Bean is shipped with following editors -
o Boolean cell editor
o Checkbox cell editor
o Choice cell editor
o Color cell editor
o Date cell editor
o Default cell editor
o Icon cell editor
o MultiLine cell editor
o MultiOption cell editor
o Number cell editor
o RadioButton cell editor
o Slider cell editor
Ø Facility to setup Check box tree with child parent relationship. Set entire tree as a check box tree. This feature of ElegantJ JFC Data Tree Beans has other functionalities too.
o You can have entire tree with check boxes.
o ElegantJ JFC Data Tree JavaBean maintains Child Parent relationship. This means, if a user checks any node then all its children (recursive) becomes checked. If user unchecks (clears) any node then all the parents (recursive) become unchecked, so every checked node has all the children (recursive) as checked and every unchecked node has all the parents (recursive) as unchecked.
o ElegantJ JFC Data Tree Java Bean facilitates user to get the checked or unchecked nodes for the whole tree or at a specific level.
Ø You have option to make a tree View Only. It can also be set for Edit (where user can make changes into existing tree).
Ø Node can be opened for edit by pressing F2 key. Same functionality can be implemented through mouse-clicks. You can setup number of mouse clicks for Editing.
Ø If required, validations can be implemented for not accepting two nodes with same value (name) for any parent node.
3.2 ElegantJ Data Access Component
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 Comonent 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 Java Bean 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 beginning 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 Java Bean.
Ø 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 JavaBean.
Ø 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 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 Java Bean 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 Java Bean 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 beginning 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 Java Bean 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 Java Bean. Features of ElegantJ FTP Text Data Access component are -
Ø This Java Bean connects to any FTP server.
Ø Reads from remote file.
Ø Can parse data with fixed column size or with delimiter.
Ø Option to skip lines from begining 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 Java Bean can parse an XML file by user-defined tags (identifiers of root, row and column).
Ø Option to skip lines from begining 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 Java Bean 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 Tree
applet
Description: This applet demonstrates use of ElegantJ AWT Data Tree bean. It populates tree data, directly from text file using ElegantJ TextDataProvider.
To run this demo application,
Go to ElegantJDataTrees\demos\applets\awt directory, then open treesawtapplet.html in any Java compliant web browser.
AWT Data Tree
application
Description: This application demonstrates use of ElegantJ AWT Data Tree bean. It populates tree data, directly from text file using ElegantJ TextDataProvider.
To run this demo application,
Go to ElegantJDataTrees\demos\applications\awt directory, then execute java -jar treesawtapp.jar command.
JFC Data Tree
application
Description: This application demonstrates use of ElegantJ JFC Data Tree bean. It populates tree data, directly from text file using ElegantJ TextDataProvider.
To run this demo application,
Go to ElegantJDataTrees\demos\applications\jfc directory,then execute java -jar treesjfcapp.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 ejdatatrees_v1.zip, following directories will be created inside ElegantJDataTrees 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 Java Bean 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 Programmers’ Guide
6.1.1.1 Creating an instance of AWTDataTreeViewer
ElegantJ AWTDataTreeViewer can be created in following ways,
First way:
com.elegantj.data.dataviewer.awt.tree.AWTDataTreeViewer awtDataTreeViewer = new
com.elegantj.data.dataviewer.awt.tree.AWTDataTreeViewer();
Creates AWTDataTreeViewer using default constructor.
Second way:
com.elegantj.awt.tree.AWTTreeNode root =
new com.elegantj.awt.tree.AWTTreeNode("Root");
com.elegantj.data.dataviewer.awt.tree.AWTDataTreeViewer awtDataTreeViewer =
new com.elegantj.data.dataviewer.awt.tree.AWTDataTreeViewer(root);
Creates AWTDataTreeViewer with specified root node.
Third way:
Object rootUserObject = "Root";
com.elegantj.awt.tree.AWTTreeNode nodes[] = {
new com.elegantj.awt.tree.AWTTreeNode("node1"),
new com.elegantj.awt.tree.AWTTreeNode("node2"),
new com.elegantj.awt.tree.AWTTreeNode("node3")};
com.elegantj.data.dataviewer.awt.tree.AWTDataTreeViewer awtDataTreeViewer =
new com.elegantj.data.dataviewer.awt.tree.AWTDataTreeViewer(rootUserObject, nodes);
Creates AWTDataTreeViewer with specified root's user object and nodes array.
Fourth way:
Object rootUserObject = "Root";
Vector nodes = new Vector();
nodes.addElement(new com.elegantj.awt.tree.AWTTreeNode("node1"));
nodes.addElement(new com.elegantj.awt.tree.AWTTreeNode("node2"));
nodes.addElement(new com.elegantj.awt.tree.AWTTreeNode("node3"));
com.elegantj.data.dataviewer.awt.tree.AWTDataTreeViewer awtDataTreeViwer =
new com.elegantj.data.dataviewer.awt.tree.AWTDataTreeViewer(rootUserObject, nodes);
Creates AWTDataTreeViewer with specified root's user object and nodes vector.
6.1.1.2 Applying general appearance and formatting
Ø To set value for background color for tree
awtDataTreeViewer.setTreeBackground(java.awt.Color.cyan); // sets the background color as cyan
Ø To set visibility property for tree
awtDataTreeViewer.setVisible(true); // makes the tree visible
Ø To set enability property
awtDataTreeViewer.setEnabled(true); // sets enability property as true
Ø To set Locale
awtDataTreeViewer.setLocale(java.util.Locale.ENGLISH); // sets locale as English
Ø To set cursor type
awtDataTreeViewer.setCursor (new
java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); // sets cursor as hand cursor
Ø To set Tree dimension (bounds)
int x = 5;
int y = 5;
int width = 300;
int height = 200;
awtDataTreeViewer.setBounds(x, y, width,
height);
Ø To set Border properties
awtDataTreeViewer.setBorder(new
com.elegnatj.editors.AWTBorder
(com.elegnatj.editors.AWTBorder.SIMPLE, 2, java.awt.Color.black)); // sets SIMPLE, 2 pixel wide and black colored border
6.1.1.3 Configuring node attributes for whole tree
ElegantJ AWTDataTreeViewer provides whole tree node's attributes like -
Ø Background non selection color
Ø Background selection color
Ø Text non selection color
Ø Text selection color
Ø Border selection color
Ø Expanded image icon
Ø Collapsed image icon
Ø Leaf image icon
Ø Cell renderer
Ø Cell editor
Ø To set background non selection color for whole tree nodes
awtDataTreeViewer.setBackgroundNonSelectionColor(java.awt.Color.cyan); // sets background non selection color for whole tree nodes as cyan
Ø To set background selection color for whole tree nodes
awtDataTreeViewer.setBackgroundSelectionColor(java.awt.Color.blue); //
sets background selection color for whole tree nodes as blue
Ø To set text non selection color for whole tree nodes
awtDataTreeViewer.setTextNonSelectionColor(java.awt.Color.black); //
sets text non selection color for whole tree nodes as black
Ø To set text selection color for whole tree nodes
awtDataTreeViewer.setTextSelectionColor(java.awt.Color.white); // sets text selection color for whole tree nodes as white
Ø To set border selection color for whole tree nodes
awtDataTreeViewer.setBorderSelectionColor(java.awt.Color.black); // sets border selection color for whole tree nodes as black
Ø To set expanded image for expanded nodes by specifying image path
String expandedImagePath =
"c:/images/expanded.gif";
awtDataTreeViewer.setExpandedImageIcon(expandedImagePath);
Ø To set expanded image for expanded nodes by specifying java.awt.Image object
java.awt.Image expandedImage =
java.awt.Toolkit.getDefaultToolkit().
createImage(getClass().getResrouce("expanded.gif"));
awtDataTreeViewer.setExpandedImageIcon(expandedImage);
Ø To set collapsed image for collapsed nodes by specifying image path
String collapsedImagePath =
"c:/images/collapsed.gif";
awtDataTreeViewer.setCollapsedImageIcon(collapsedImagePath);
Ø To set collapsed image for collapsed nodes by specifying java.awt.Image object
java.awt.Image collapsedImage =
java.awt.Toolkit.getDefaultToolkit().
createImage(getClass().getResrouce("collapsed.gif"));
awtDataTreeViewer.setCollapsedImageIcon(collapsedImage);
Ø To set leaf image for leaf nodes by specifying image path
String leafImagePath =
"c:/images/leaf.gif";
awtDataTreeViewer.setLeafImageIcon(leafImagePath);
Ø To set leaf image for leaf nodes by specifying java.awt.Image object
java.awt.Image leafImage =
java.awt.Toolkit.getDefaultToolkit().
createImage(getClass().getResrouce("leaf.gif"));
awtDataTreeViewer.setLeafImageIcon(leafImage);
Ø To set cell renderer for whole tree,
You will receive following cell renderers for ready to use with this package,
o Checkbox cell renderer –
com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer
o Choice (combo box) cell renderer –
com.elegantj.awt.tree.ChoiceAWTTreeCellRenderer
o Text cell renderer –
com.elegantj.awt.tree.DefaultAWTTreeCellRenderer
o Text area cell renderer –
com.elegantj.awt.tree.TextAreaAWTTreeCellRenderer
com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer
renderer = new
com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer();
awtDataTreeViewer.setCellRenderer(renderer);
which sets checkbox as a cell renderer for whole tree.
Ø To set the cell editor for whole tree,
You will receive following cell editors for ready to use with this package,
o Checkbox cell editor –
com.elegantj.awt.tree.CheckboxAWTTreeCellEditor
o Choice (combo box) cell editor –
com.elegantj.awt.tree.ChoiceAWTTreeCellEditor
o Text editor - com.elegantj.awt.tree.DefaultAWTTreeCellEditor
o Text area cell editor –
com.elegantj.awt.tree.TextAreaAWTTreeCellEditor
com.elegantj.awt.tree.CheckboxAWTTreeCellEditor
editor = new
com.elegantj.awt.tree.CheckboxAWTTreeCellEditor();
awtDataTreeViewer.setCellEditor(editor);
which sets checkbox as a cell editor for whole tree.
6.1.1.4 Configuring level wise node attributes
ElegantJ AWTDataTreeViewer provides level wise tree node's attributes like -
Ø Background non selection color
Ø Background selection color
Ø Text non selection color
Ø Text selection color
Ø Border selection color
Ø Expanded image icon
Ø Collapsed image icon
Ø Leaf image icon
Ø Cell renderer
Ø Cell editor
Ø To set background non selection color for nodes at specific level
int level = 1;
Color backgroundNonSelectionColor =
java.awt.Color.cyan;
awtDataTreeViewer.setBackgroundNonSelectionColorAt
(level, backgroundNonSelectionColor); // sets background non selection color as cyan for nodes at level 1
Ø To set background selection color for nodes at specific level
int level = 1;
Color backgroundSelectionColor =
java.awt.Color.blue;
awtDataTreeViewer.setBackgroundSelectionColorAt
(level, backgroundSelectionColor); // sets background selection color as blue for nodes at level 1
Ø To set text non selection color for nodes at specific level
int level = 1;
Color textNonSelectionColor =
java.awt.Color.black;
awtDataTreeViewer.setTextNonSelectionColorAt
(level, textNonSelectionColor); // sets text non selection as black for nodes at level 1
Ø To set text selection color for nodes at specific level
int level = 1;
Color textSelectionColor =
java.awt.Color.white;
awtDataTreeViewer.setTextSelectionColorAt
(level, textSelectionColor); // sets text selection as white for nodes at level 1
Ø To set expanded image for expanded nodes at specific level using image path
int level = 1;
String expandedImagePath =
"c:/images/expanded.gif";
awtDataTreeViewer.setExpandedImageIconAt
(level, expandedImagePath); // sets expanded image for expanded nodes at level 1 using image path
Ø To set expanded image for expanded nodes at specific level using java.awt.Image
int level = 1;
java.awt.Image expandedImage =
java.awt.Toolkit.getDefaultToolkit().
createImage(getClass().getResrouce("expanded.gif"));
awtDataTreeViewer.setExpandedImageIconAt
(level, expandedImage); // sets expanded image using java.awt.Image for expanded nodes at level 1
Ø To set collapsed image for collapsed nodes at specific level using image path
int level = 1;
String collapsedImagePath =
"c:/images/collapsed.gif";
awtDataTreeViewer.setCollapsedImageIconAt
(level, collapsedImagePath); // sets collapsed image for collapsed nodes at level 1 using image path
Ø To set collapsed image for collapsed nodes at specific level using java.awt.Image
int level = 1;
java.awt.Image collapsedImage =
java.awt.Toolkit.getDefaultToolkit().
createImage(getClass().getResrouce("collapsed.gif"));
awtDataTreeViewer.setCollapsedImageIconAt
(level, collapsedImage); // sets collapsed image for expanded nodes at level 1 using java.awt.Image
Ø To set leaf image for leaf nodes at specific level using image path
int level = 1;
String leafImagePath =
"c:/images/leaf.gif";
awtDataTreeViewer.setLeafImageIconAt
(level, leafImagePath); // sets leaf image for leaf nodes at level 1 using image path
Ø To set leaf image for leaf nodes at specific level using java.awt.Image
int level = 1;
java.awt.Image leafImage =
java.awt.Toolkit.getDefaultToolkit().
createImage(getClass().getResrouce("leaf.gif"));
awtDataTreeViewer.setLeafImageIconAt
(level, leafImage); // sets leaf image for leaf nodes at level 1 using java.awt.Image
Ø To set cell renderer for specific level
You will receive following cell renderers for ready to use with this package,
o Checkbox cell renderer -
com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer
o Choice (combo box) cell renderer -
com.elegantj.awt.tree.ChoiceAWTTreeCellRenderer
o Text cell renderer -
com.elegantj.awt.tree.DefaultAWTTreeCellRenderer
o Text area cell renderer -
com.elegantj.awt.tree.TextAreaAWTTreeCellRenderer
int level = 1;
com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer
renderer = new
com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer();
awtDataTreeViewer.setCellRendererAt(level,
renderer);
which sets checkbox as a cell renderer for nodes at level 1.
Ø To set cell editor for specific level,
You will receive following cell editors for ready to use with this package,
o Checkbox cell editor -
com.elegantj.awt.tree.CheckboxAWTTreeCellEditor
o Choice (combo box) cell editor -
com.elegantj.awt.tree.ChoiceAWTTreeCellEditor
o Text editor -
com.elegantj.awt.tree.DefaultAWTTreeCellEditor
o Text area cell editor -
com.elegantj.awt.tree.TextAreaTreeCellEditor
int level = 1;
com.elegantj.awt.tree.CheckboxAWTTreeCellEditor
editor = new
com.elegantj.awt.tree.CheckboxAWTTreeCellEditor();
awtDataTreeViewer.setCellEditor(editor);
which sets checkbox as a cell editor for nodes at level 1.
Ø To set root of AWTDataTreeViewer
com.elegantj.awt.tree.AWTTreeNode root =
new
com.elegantj.awt.tree.AWTTreeNode("Root");
awtDataTreeViewer.setRoot(root); // sets the root of the tree with "Root" as user object
Ø To set visibility of root node
awtDataTreeViewer.setRootVisible(false); // which makes search panel invisible
Ø To set visibility of root handles
awtDataTreeViewer.setShowRootHandles(true); // which makes root handles visible
6.1.1.6 Setting row height attributes
Ø To set row height
awtDataTreeViewer.setRowHeight(20); // sets row height as 20 pixels
6.1.1.7 Configuring selection functionality
Ø AWTDataTreeViewer supports two types of selection
o Single selection -
com.elegantj.awt.tree.awtDataTreeViewer.SINGLE_SELECTION
o Multiple selection -
com.elegantj.awt.tree.awtDataTreeViewer.MULTIPLE_SELECTION
Ø To set selection style as SINGLE_SELECTION
awtDataTreeViewer.setSelectionStyle(com.elegantj.awt.tree.awtDataTreeViewer.SINGLE_SELECTION); // sets selection style as single selection
Ø To set selection style as MULTIPLE_SELECTION
awtDataTreeViewer.setSelectionStyle(com.elegantj.awt.tree.awtDataTreeViewer.MULTIPLE_SELECTION); // sets selection style as multiple selection
Ø To provide / remove selection functionality on tree
awtDataTreeViewer.setSelectionAllowed(true); // allows selection on tree
Ø Do not allow selection functionality on tree
awtDataTreeViewer.setSelectionAllowed(false); // disallows selection functionality on tree
Ø To select a specific node
awtDataTreeViewer.setSelectionNode(awtTreeNode); // selects specified node
Ø To select a specific Row
awtDataTreeViewer.setSelectionRow(rowIndex); // selects node exist at specified rowIndex
Ø To select a range of nodes
awtDataTreeViewer.setSelectionInterval(startRowIndex,
endRowIndex);
Ø To set editability of AWTDataTreeViewer
awtDataTreeViewer.setEditable(false); // makes AWTDataTreeViewer uneditable
Ø To start editing of a specific node
awtDataTreeViewer.startEditing(node); // starts editing of specified node
Ø To stop editing
awtDataTreeViewer.stopEditing(); // stops editing
Ø To cancel editing
awtDataTreeViewer.cancelEditing(); // cancels editing
Ø To check if tree is being edited or not
awtDataTreeViewer.isEditing(); // which returns boolean value, returns true if currently it is being edited
6.1.1.9 Using insert key and delete key
Ø To allow inserting of node on INSERT key of keyboard
awtDataTreeViewer.setInsertNodeOnInsertKey(true); // which allows to insert node on INSERT key of keyboard
Ø To allow deleting of node on DELETE key of keyboard
awtDataTreeViewer.setDeleteNodeOnDeleteKey(true); // which allows to delete node on DELETE key of keyboard
6.1.1.10 Configuring drag and drop
ElegantJ AWTDataTreeViewer provides feature of drag and drop. Also provides property to activate or deactivate drag and drop functionality for a tree.
The drag and drop functionality works in following way,
Ø A node can only be dropped to the node. It can not be dropped outside the tree or any position in tree except the hierarchical node's region.
Ø A parent node can not be dropped to the it's any of the child node.
Ø If allowSameNodeAtSameLevel's value is false then same child node as the dragged node should not be exist in the node on which it is being dropped.
Ø To allow Drag and Drop functionality on tree,
awtDataTreeViewer.setDragAndDrop(true); // which allows drag and drop on tree
6.1.1.11 Configuring search panel
ElegantJ AWTDataTreeViewer beans has collection of methods that can be used to set up search panel to implement Search functionality in your application. User can search down from first node or selected node and up from last node or selected node. You can perform case sensitive / case insensitive search if required.
You can perform search for total equality, availability of search string as part of value in tree nodes, for value in tree nodes starting with search string as well as for value in tree nodes ending with search string
ElegantJ AWTDataTreeViewer provides the following properties to configure the search panel
Ø Search Panel Visibility
Ø Search Panel Background
Ø Search Panel Foreground
Ø Search Panel Font
Ø Search Panel Placement
Ø Search Level Identifiers
Ø To set search panel visibility
awtDataTreeViewer.setSearchPanelVisible(true); // sets search panel visibility to true
Ø To set search panel background
Color searchPanelBackground =
java.awt.Color.cyan;
awtDataTreeViewer.setSearchPanelBackground(searchPanelBackground); // sets search panel background color as cyan
Ø To set search panel foreground
Color searchPanelForeground =
java.awt.Color.black;
awtDataTreeViewer.setSearchPanelForeground(searchPanelForeground); // sets search panel foreground color as black
Ø To set search panel font
Font searchPanelFont = new java.awt.Font("Dialog", java.awt.Font.BOLD, 12); awtDataTreeViewer.setSearchPanelFont(searchPanelFont); // sets search panel font as dialog, bold and of size 12
Ø To set the search panel's placement (top or bottom)
awtDataTreeViewer.setSearchPanelLocation(com.elegantj.awt.tree.awtDataTreeViewer.TOP); // sets search panel location to top
Ø To set search level-wise identifiers
java.util.Vector levelWiseSearchIDs = new
java.util.Vector();
levelWiseSearchIDs.addElement("Country");
levelWiseSearchIDs.addElement("State");
levelWiseSearchIDs.addElement("City");
awtDataTreeViewer.setLevelWiseIDs(levelWiseSearchIDs); // which sets search panel wise identifiers to fill combo box of search panel
ElegantJ AWT Data Tree bean provides facility for searching node values. To make things easier for developer, ElegantJ also provides ready-to-use Search panel. You can search tree in four different ways (up as well as down). You have option of a case sensitive / case insensitive search, if required.
Options for search progress and Comparison
|
Search Progress from |
Options for search Progress |
|
First node |
com.elegantj.awt.tree.awtDataTreeViewer. SEARCH_FROM_FIRST_NODE |
|
Last Node |
com.elegantj.awt.tree.awtDataTreeViewer. SEARCH_FROM_LAST_NODE |
|
upwards from selected node |
com.elegantj.awt.tree.awtDataTreeViewer. SEARCH_FROM_SELECTED_NODE_TO_UP |
|
downwards from selected node |
com.elegantj.awt.tree.awtDataTreeViewer. SEARCH_FROM_SELECTED_NODE_TO_DOWN |
Comparison Options
|
Comparison requirement |
Option for comparison |
|
Search node for value that starts with given search string |
com.elegantj.awt.tree.awtDataTreeViewer. STARTS_WITH |
|
Search node for value that ends with given search string |
com.elegantj.awt.tree.awtDataTreeViewer. ENDS_WITH |
|
Search node for value or its part equals given search string |
com.elegantj.awt.tree.awtDataTreeViewer. CONTAINS |
|
Search node for value for given string for exact match |
com.elegantj.awt.tree.awtDataTreeViewer. EQUALS |
To search for text "Employees" at node level 2,
String searchText = "Employees";
int searchFrom =
com.elegantj.awt.tree.awtDataTreeViewer.SEARCH_FROM_FIRST_NODE;
int serachWith =
com.elegantj.awt.tree.awtDataTreeViewer.STARTS_WITH;
int serachOnLevel = 2;
boolean isCaseSensitive = false;
com.elegantj.awt.tree.AWTTreeNode node = searchTreeNode(searchText, searchFrom, searchWith, searchOnLevel, isCaseSensitive); // This returns the selected node if found. Search level must be greater than or equal to zero. To search whole tree, specify searchOnLevel as 0.
6.1.1.13 Configuring popup menu
ElegantJ AWTDataTreeViewer is shipped with ready-to-use popup with following functionalities:
Ø Insert the node
Ø Delete the node
Ø Edit the node
Ø Add the child node
To make right-click functionality available or not available.
Ø Make Right-click functionality available
awtDataTreeViewer.setShowPopupMenu(true);
Note: For Remove operations, If more than one nodes are selected then all nodes will be removed while For Add, Edit as well as Insert operations, action is performed on the node where mouse pointer is located while right-clicking.
6.1.1.14 Configuring checkbox tree and features under checkbox tree
Using ElegantJ AWTDataTreeViewer Beans, you can make entire tree as a CheckBox tree. In a Checkbox tree, all the nodes will be checkboxes. The process to create a check box tree is -
Ø Create a tree object
Ø Set it as a CheckBox Tree.
Ø Set tree as a check box tree
awtDataTreeViewer.setCheckboxTree(true);
In a check box tree, all the nodes are rendered by checkboxes.
Ø ElegntJ AWTDataTreeViewer provides following methods to get checked / unchecked nodes in case of Checkbox tree.
o To get a vector containing checked nodes from whole check box tree,
java.util.Vector
nodes = awtDataTreeViewer.getTreeNodes();
o To get a vector containing checked / unchecked nodes from whole check box tree,
boolean bChecked = false;
java.util.Vector nodes =
awtDataTreeViewer.getTreeNodes(bChecked);// returns vector containing unchecked nodes.
o To get a vector containing checked / unchecked nodes for specific level,
boolean bChecked = false;
int level = 2;
java.util.Vector nodes = awtDataTreeViewer.getTreeNodes(bChecked, level); // returns vector containing unchecked nodes at level 2.
o To get a vector containing checked / unchecked nodes from sub tree,
boolean bChecked = false;
com.elegantj.awt.tree.AWTTreeNode
parentNode =
awtDataTreeViewer.getRoot();
java.util.Vector nodes =
awtDataTreeViewer.getTreeNodes(bChecked, parentNode); // returns a vector containing unchecked nodes from sub tree whose root is parentNode.
o To get a vector containing checked / unchecked nodes at level 2 from sub tree
boolean bChecked = false;
int level = 2;
com.elegantj.awt.tree.AWTTreeNode
parentNode =
awtDataTreeViewer.getRoot();
Vector nodes = awtDataTreeViewer.getTreeNodes(bChecked, level, parentNode); // returns the vector containing the unchecked nodes at level 2 from subtree whose root is parentNode.
6.1.1.15 Configuring child-parent relationship in checkbox tree
A checkbox tree with Child-Parent relationship implemented improves speed of working with a tree. This feature of a tree, an action carried out on a parent is repeated on its children. For example,
Ø If parent node is checked, all children (directly or indirectly under that parent) will get checked.
Ø If parent node is unchecked, all children (directly or indirectly under that parent) also become unchecked.
Ø If any child is unchecked, it's direct-parent also become unchecked.
Ø To activate Child Parent relationship in check box tree
awtDataTreeViewer.setChildParentRelationship(true);
6.1.1.16 Restricting duplicate nodes
You can restrict creation of duplicate child nodes at same level (for any parent node). This means, user can be restricted from changing values in nodes, if values are getting duplicated at the same level (for any parent node). User will not be able to do this by carrying out operations like editing, inserting, drag and drop or even programmatically. This is specially useful when you want the data be unique.
Ø Do not allow nodes with same values at same level (for any parent node)
awtDataTreeViewer.setSameNodeAtSameLevel(false);
By default, it is set as true.
If SameNodeAtSameLevel is false,
Ø Duplicate child node cannot be positioned as parent node's child.
Ø If value entered makes same value, either the changes needs to be truncated or new value needs to be entered.
Ø Restricts the duplicate nodes at any depth of the inserted node.
SameNodeAtSameLevel works even in following cases also,
Ø On drag and drop
Ø While node is inserted by insert key
Ø While node is inserted programmatically
Ø While root is set programmatically
6.1.1.17 Making use of Advanced Implementation for creating custom cell renderers
ElegantJ AWTDataTreeViewer Beans is shipped with following cell renderers for ready to use -
Ø Checkbox cell renderer –
com.elegantj.awt.tree.CheckboxAWTTreeCellRenderer
Ø Choice (combo box) cell renderer –
com.elegantj.awt.tree.ChoiceAWTTreeCellRenderer
Ø Text cell renderer - com.elegantj.awt.tree.DefaultAWTTreeCellRenderer
Ø Text area cell renderer –
com.elegantj.awt.tree.TextAreaAWTTreeCellRenderer
If you wish to use the custom component as a 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.tree.AWTTreeCellRenderer and then,
Ø override paint(java.awt.Graphics g) method, which is called internally to paint the custom renderer.
6.1.1.18 AWT Data Tree Listeners and Events
|
Listener Name |
com.elegantj.awt.tree.AWTTreeListener |
|
Event that it receives |
com.elegantj.awt.tree.AWTTreeEvent |
|
When it fires |
Ø Tree node(s) is changed Ø Tree node(s) are inserted Ø Tree node(s) are removed or Ø Tree structure is changed |
|
Listener Name |
com.elegantj.awt.tree.AWTTreeExpansionListner |
|
Event that it receives |
com.elegantj.awt.tree.AWTTreeExpansionEvent |
|
When it fires |
Ø After a tree node is collapsed or Ø After a tree node is expanded |
|
Listener Name |
com.elegantj.awt.tree.AWTTreeWillExpandListener |
|
Event that it receives |
com.elegantj.awt.tree.AWTTreeExpansionEvent |
|
When it fires |
Ø Before a tree node is expanded or Ø Before a tree node is collapsed |
|
Listener Name |
com.elegantj.awt.tree.AWTTreeSelectionListener |
|
Event that it receives |
com.elegantj.awt.tree.AWTTreeSelectionEvent |
|
When it fires |
Ø After tree selection changes |
|
Listener Name |
com.elegantj.awt.tree.AWTTreeCellEditListener |
|
Event that it receives |
com.elegantj.awt.tree.AWTTreeCellEditEvent |
|
When it fires |
Ø Before cell editing Ø After cell editing |
For more information on Listeners / Events see JAVA API for this package
6.1.1.19 Configuring data access component with AWTDataTreeViewer
You can use ElegantJ AWTDataTreeViewer 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 Component refer Data Access Component Usage Matrix and Data Access Component Objects.
You will get following five Data Access Component 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 Component can be easily bound with AWTDataTreeViewer to fetch data from data source.
Ø To bind SqlDataProvider with AWTDataTreeViewer,
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
awtDataTreeViewer.setDataProvider(sqlDataProvider); // binds the SqlDataProvider to AWTDataTreeViewer
awtDataTreeViewer.retrieveData(); // retrieves the data from Data Access Component
Ø To bind TextDataProvider with AWTDataTreeViewer,
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
awtDataTreeViewer.setDataProvider(textDataProvider); // binds the TextDataProvider to AWTDataTreeViewer
awtDataTreeViewer.retrieveData(); // retrieves the data from Data Access Component
Ø To bind HTTPTextDataProvider to the AWTDataTreeViewer,
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
awtDataTreeViewer.setDataProvider(httpTextDataProvider); // binds the HTTPTextDataProvider to AWTDataTreeViewer
awtDataTreeViewer.retrieveData(); // retrieves the data from Data Access Component
Ø To bind FTPTextDataProvider to AWTDataTreeViewer,
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
awtDataTreeViewer.setDataProvider(ftpTextDataProvider); // binds the FTPTextDataProvider to AWTDataTreeViewer
awtDataTreeViewer.retrieveData(); // retrieves the data from Data Access Component
Ø To bind XMLDataProvider with AWTDataTreeViewer,
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
awtDataTreeViewer.setDataProvider(xmlDataProvider); // binds the XMLDataProvider to AWTDataTreeViewer
awtDataTreeViewer.retrieveData(); // retrieves the data from Data Access Component
Note: For more information on Data Access Component, go through the programmers guide on Data Access Component section, of this documentation.
6.1.1.20 Making Master-Detail relationship
AWTDataTreeViewer provides the master-detail relationship with other data viewer. By binding this data viewer as a master data viewer to other data viewer, both data viewers work as a master-detail data viewer. Master data viewer navigates the detail data viewer based on JOIN column between master data viewer and detail data viewer.
Ø To make master-detail relationship,
detailDataViewer.setMasterDataViewer(masterDataViewer.getDataViewer());
detailDataViewer.setJoin(new
com.elegantj.data.dataviewer.Join("MasterColumn","DetailColumn"));
6.1.1.21 Handlign data navigation functionality
AWTDataTreeViwer 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 record pointer to the first record.
awtDataTreeViewer.firstRecord();
Ø To move record pointer to the last record.
awtDataTreeViewer.nextRecord();
Ø To move record pointer to next record.
awtDataTreeViewer.nextRecord();
Ø To move record pointer to record 5.
awtDataTreeViewer.scrollToRow(5);
6.1.1.22 Handling data modification
The following methods are used to modify data through Data Access Component.
|
For what |
Function to use |
|
Refresh the data |
Refresh |
|
To add a default row to the end of the data |
AddRow |
|
To remove selected row |
DeleteRow |
Ø To refresh data,
awtDataTreeViewer.refresh();
Ø To add a row at end of data,
awtDataTreeViewer.addRow();
Ø To delete selected row,
awtDataTreeViewer.deleteRow();
6.1.2.1 Creating an instance of DataTreeViewer
Ø To create an instance of DataTreeViewer
com.elegantj.data.dataviewer.jfc.tree.DataTreeViewer
dataTreeViewer = new com.elegantj.data.dataviewer.jfc.tree.DataTreeViewer();
This creates an instance of DataTreeViewer.
6.1.2.2 Configuring general appearance
DataTreeViewer provides the following basic look & feel,
Ø Font
Ø Background
Ø Foreground
Ø Visibility
Ø Enabled
Ø Locale
Ø Cursor
Ø Bounds
Ø Lightweight
Ø Opaque
Ø Tool-Tip Text
Ø DoubleBuffered
Ø Autoscrolls
Ø RequestFocusEnabled
Ø Border
Ø ManagingFocus
Ø To set Background color,
dataTreeViewer.setBackground(java.awt.Color.cyan);
// sets the background color as cyan
Ø To set Foreground color,
dataTreeViewer.setForeground(java.awt.Color.black); // sets foreground color as black
Ø To set Font properties,
dataTreeViewer.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); // sets the dialog font of size 12
Ø To set Visibility property,
dataTreeViewer.setVisible(true); // sets visibility property as true
Ø To set Enable property,
dataTreeViewer.setEnabled(true); // sets enable property as true
Ø To set Locale property,
dataTreeViewer.setLocale(java.util.Locale.ENGLISH); // sets the locale property to English
Ø To set Cursor property,
dataTreeViewer.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); // sets the cursor property to hand cursor
Ø To set Bounds,
int x = 5;
int y = 5;
int width = 300;
int height = 200;
dataTreeViewer.setBounds(x, y, width, height); // sets bounds to x, y, width and height
Ø To set Lightweight
dataTreeViewer.setLightweight(true); // sets Lightweight to true
Ø To set Opaque,
dataTreeViewer.setOpaque(true); // sets opaque to true
Ø To set Tool-tip text,
dataTreeViewer.setTooltipText("DataTreeViewer"); // sets Tooltip text as "DataTreeViewer"
Ø To set Double Buffering property,
dataTreeViewer.setDoubleBuffered(true); // enables the double buffering
Ø To set Auto Scroll property,
dataTreeViewer.setAutoScrolls(true); // sets the auto scrolls to true
Ø To set RequestFocusEnabled,
dataTreeViewer.setRequestFocusEnabled(true);
Ø To set Border color,
javax.swing.Border border =
javax.swing.BorderFactory.createLineBorder(java.awt.Color.black); // sets the border as black
dataTreeViewer.setBorder(border);
Ø To set ManagingFocus property,
dataTreeViewer.setManagingFocus(true); // sets the ManagingFocus to true.
6.1.2.3 Configuring level wise node attributes
The level wise node attributes such as,
Ø Background non selection color
Ø Background selection color
Ø Text non selection color
Ø Text selection color
Ø Border selection color
Ø Opened image icon
Ø Closed image icon
Ø Leaf image icon
Ø Cell renderer
Ø Cell editor
Ø To set level wise BackgroundNonSelectionColor,
int level = 1;
jva.awt.Color backgroundNonSelectionColor =
java.awt.Color.cyan;
dataTreeViewer.setBackgroundNonSelectionColor(backgroundNonSelectionColor, level); // sets background non selection color for nodes at level 1 to cyan.
Ø To set level wise BackgroundSelectionColor
int level = 1;
java.awt.Color backgroundSelectionColor =
java.awt.Color.blue;
dataTreeViewer.setBackgroundSelectionColor(backgroundSelectionColor, level); // sets background selection color for nodes at level 1 to blue.
Ø To set level wise TextNonSelectionColor,
int level = 1;
java.awt.Color textNonSelectionColor =
java.awt.Color.black;
dataTreeViewer.setTextNonSelectionColor(textNonSelectionColor, level); // sets text non selection color for nodes at level 1 to black.
Ø To set level wise TextSelectionColor,
int level = 1;
java.awt.Color textSelectionColor =
java.awt.Color.white;
dataTreeViewer.setTextSelectionColor(textSelectionColor, level); // sets text selection color for nodes at level 1 to white.
Ø To set level wise BorderSelectionColor,
int level = 1;
java.awt.Color borderSelectionColor =
java.awt.Color.black;
dataTreeViewer.setBorderSelectionColor(borderSelectionColor, level); // sets border selection color for nodes at level 1 to black.
Ø To set level wise open image icon,
o To set open image icon with specified image path for nodes at specific level,
int level = 1;
String path =
"c:/images/opened.gif";
dataTreeViewer.setOpenIconPath(path ,level); // sets open image icon for nodes at level 1
o To set open image icon with specified image icon for nodes at specific level,
int level = 1;
javax.swing.ImageIcon imageIcon = new
javax.swing.ImageIcon("c:/my_folder/opened.gif");
dataTreeViewer.setOpenIcon(imageIcon, level); // sets open image icon for nodes at level 1
Ø To set level wise close image icon,
o To set close image icon with specified image path for nodes at specific level,
int level = 1;
String path =
"c:/images/closed.gif";
dataTreeViewer.setCloseIconPath(path ,level); // sets close image icon for nodes at level 1
o To set close image icon with specified image icon for nodes at specific level,
int level = 1;
javax.swing.ImageIcon imageIcon = new
javax.swing.ImageIcon("c:/my_folder/closed.gif");
dataTreeViewer.setCloseIcon(imageIcon, level); // sets close image icon for nodes at level 1
Ø To set level wise leaf image icon,
o To set leaf image icon with specified image path for nodes at specific level,
int level = 1;
String path =
"c:/images/leaf.gif";
dataTreeViewer.setLeafIconPath(path ,level); // sets leaf image icon for nodes at level 1
o To set leaf image icon with specified image icon for nodes at specific level,
int level = 1;
javax.swing.ImageIcon imageIcon = new
javax.swing.ImageIcon("c:/my_folder/leaf.gif");
dataTreeViewer.setLeafIcon(imageIcon, level); // sets leaf image icon for nodes at level 1
Ø To set cell renderer,
Following cell renderers comes with the ElegantJ DataTreeViewer beanary,
o Boolean cell renderer –
com.elegantj.jfc.common.renderers.BooleanRenderer
o Checkbox cell renderer –
com.elegantj.jfc.common.renderers.CheckboxRenderer
o Choice cell renderer –
com.elegantj.jfc.common.renderers.ChoiceRenderer
o Color cell renderer –
com.elegantj.jfc.common.renderers.ColorRenderer
o Date cell renderer –
com.elegantj.jfc.common.renderers.DateRenderer
o Default cell renderer –
com.elegantj.jfc.common.renderers.DefaultRenderer
o Icon cell renderer –
com.elegantj.jfc.common.renderers.IconRenderer
o MultiLine cell renderer –
com.elegantj.jfc.common.renderers.MultiLineRenderer
o MultiOption cell renderer –
com.elegantj.jfc.common.renderers.MultiOptionRenderer
o Number cell renderer –
com.elegantj.jfc.common.renderers.NumberRenderer
o Progress cell renderer –
com.elegantj.jfc.common.renderers.ProgressRenderer
o RadioButton cell renderer –
com.elegantj.jfc.common.renderers.RadioButtonRenderer
o Text cell renderer –
com.elegantj.jfc.common.renderers.TextRenderer
o To set level wise cell renderer for nodes at specific level
int level = 1;
com.elegantj.jfc.common.renderers.CheckboxRenderer
checkboxRenderer = new
com.elegantj.jfc.common.renderers.CheckboxRenderer();
dataTreeViewer.setCellRenderer(checkboxRenderer, level); // sets cell renderer as checkbox renderer for nodes at level 1
o To set default cell renderer (applicable when level wise renderer is not set, This default renderer renders all the nodes when level wise renderers are not set.)
com.elegantj.jfc.common.renderers.CheckboxRenderer
checkboxRenderer = new
com.elegantj.jfc.common.renderers.CheckboxRenderer();
dataTreeViewer.setDefaultCellRenderer(checkboxRenderer); // sets default cell renderer as checkbox renderer for whole tree,
Ø To set cell editor
Following cell editors come with the ElegantJ DataTreeViewer benary,
o Boolean cell editor –
com.elegantj.jfc.common.editors.BooleanEditor
o Checkbox cell editor –
com.elegantj.jfc.common.editors.CheckboxEditor
o Choice cell editor - com.elegantj.jfc.common.editors.ChoiceEditor
o Color cell editor - com.elegantj.jfc.common.editors.ColorEditor
o Date cell editor - com.elegantj.jfc.common.editors.DateEditor
o Default cell editor - com.elegantj.jfc.common.editors.DefaultEditor
o Icon cell editor - com.elegantj.jfc.common.editors.IconEditor
o MultiLine cell editor –
com.elegantj.jfc.common.editors.MultiLineEditor
o MultiOption cell editor –
com.elegantj.jfc.common.editors.MultiOptionEditor
o Number cell editor –
com.elegantj.jfc.common.editors.NumberEditor
o RadioButton cell editor –
com.elegantj.jfc.common.editors.RadioButtonEditor
o Slider cell editor - com.elegantj.jfc.common.editors.SliderEditor
o To set level wise cell editor for nodes at specific level
int level = 1;
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
dataTreeViewer.setCellEditor(checkboxEditor, level); // sets cell editor as checkbox editor for nodes at level 1
o To set default cell editor (applicable when level wise editor is not set, This default editor provides editor for all the nodes when level wise editors are not set.)
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
dataTreeViewer.setDefaultCellEditor(checkboxEditor); // sets default cell editor as checkbox editor for whole tree
6.1.2.4 Configuring root of tree
Ø To set the root for the DataTreeViewer,
javax.swing.tree.DefaultMutableTreeNode
root =
new javax.swing.tree.DefaultMutableTreeNode("Root");
dataTreeViewer.setRoot(root); // sets the root for the DataTreeViewer
Ø To set the visibility of the root node,
dataTreeViewer.setRootVisible(false); // makes root invisible.
Ø To set visibility of root handles
dataTreeViewer.setShowRootHandles(true);
// which makes root handles visible,
// root handles means (+) & (-) images to expand and collapse the node.
6.1.2.5 Configuring row attributes
Ø To set row height,
int rowHeight = 20;
dataTreeViewer.setRowHeight(rowHeight); // which sets the row height to 20.
Note: If the specified value is less than or equal to zero then current cell renderer is queried for each row's height.
Ø To set number of rows that should be visible,
dataTreeViewer.setVisibleRowCount(10); // which sets the visible row count to 10.
Ø To set fixed row height, If height of each display row is a fixed size or varied, that can be set through the method setFixedRowHeight.
dataTreeViewer.setFixedRowHeight(true); // which sets the fixed row height to true.
ElegantJ JFC Data Tree provides three type of selection style
Ø 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 the selection mode to SINGLE_SELECTION,
dataTreeViewer.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); // sets the selection to SINGLE_SELECTION.
Ø To add the selection interval,
int index0 = 2;
int index1 = 5;
dataTreeViewer.addSelectionInterval(index0, index1); // adds rows from index1 to index1 to selection
Ø To add tree path to selection,
javax.swing.tree.TreePath treePath =
dataTreeViewer.getPathForRow(1);
dataTreeViewer.addSelectionPath(treePath); // adds tree path to selection.
Ø To add selection paths,
javax.swing.tree.TreePath treePaths[] = new
javax.swing.tree.TreePath[]{dataTreeViewer.getPathForRow(1),
dataTreeViewer.getPathForRow(2), dataTreeViewer.getPathForRow(3)};
dataTreeViewer.addSelectionPaths(treePaths); // adds the 1st, 2nd and 3rd row's path to the selection
Ø To add row to selection,
int selectionRow = 2;
dataTreeViewer.addSelectionRow(selectionRow); // adds 2nd row to the selection
Ø To add more than one rows to selection,
int selectionRows[] = new int[]{1, 2, 3};
dataTreeViewer.addSelectionRow(selectionRows); // adds the 1st, 2nd and 3rd row to the selection.
Ø To set the Editable property DataTreeViewer,
dataTreeViewer.setEditable(false); // sets Editable property to false making it not editable
Ø InvokesStopCellEditing - When set to true, this determines what happens when editing is interrupted by selecting another node in the tree, a change in the tree's data, or by some other means.
dataTreeViewer.setInvokesStopCellEditing(true); // sets InvokesStopCellEditing to true
Ø To stop editing,
dataTreeViewer.stopEditing(); // stops the editing.
Ø To start editing at the specified path.
javax.swing.tree.TreePath treePath =
dataTreeViewer.getPathForRow(1);
dataTreeViewer.startEditingPath(treePath); // starts editing at the tree path for row at index 1
Ø To cancel editing,
dataTreeViewer.cancelEditing(); // cancels editing
Ø To check whether tree is being edited,
dataTreeViewer.isEditing(); // checks whether tree is being edited.
6.1.2.8 Use of insert key and delete key
ElegatnJ DataTreeViewer provides the action on following key strokes,
Ø INSERT key - which allows to insert node on insert key
Ø DELETE key - which allows to delete node on delete key
Note: These keystrokes works on selected node only.
Ø To enable the insertion of node on insert key,
dataTreeViewer.setInsertNodeOnInsertKey(true); // enables the insertion of node on insert key.
Ø To enable the deletion of node on delete key,
dataTreeViewer.setRemoveNodeOnDeleteKey(true); // enables the deletion of node on delete key.
6.1.2.9 Configuring drag and drop
ElegantJ DataTreeViewer allows to drag the tree node and drop it to the tree, by drag and drop functionality the tree node can be moved very easily. Drag and Drop functionality can be disabled or enabled through the method setDragAndDrop.
The drag and drop functionality works in following way,
Ø A node can only be dropped to the node. It can not be dropped outside the tree or any position in tree except the hierarchical node's region.
Ø A parent node can not be dropped to the it's any of the child node.
If allowSameNodeAtSameLevel's value is false then same child node as the dragged node should not be exist in the node on which it is being dropped.
Ø To enable the drag and drop functionality,
dataTreeViewer.setDragAndDrop(true); // enables the drag and drop functionality, the default value is true.
6.1.2.10 Configuring search panel
ElegantJ DataTreeViewer provides the following attributes for the search panel,
Ø Search panel visibility
Ø Search panel background
Ø Search panel foreground
Ø Search panel font
Ø Search panel placement
Ø Search panel identifiers
Ø To set search panel's visibility property,
dataTreeViewer.setSearchPanelVisible(false); // this hides the search panel
Ø To set background color of search panel,
dataTreeViewer.setSearchPanelBackground(java.awt.Color.gray); // which sets the search panel background to gray
Ø To set the search panel foreground,
dataTreeViewer.setSearchPanelForeground(java.awt.Color.black); // which sets the foreground color on search panel to black.
Ø To set search panel font,
dataTreeViewer.setSearchPanelFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12)); // sets the search panel font to 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
dataTreeViewer.setSearchPanelPlacement(com.elegantj.jfc.table.javax.swing.SwingConstants.TOP); // sets the search panel placement to top.
Ø To set search panel identifiers.
java.util.Vector identifiers = new
java.util.Vector();
identifiers.addElement("Region");
identifiers.addElement("Country");
identifiers.addElement("State");
dataTreeViewer.setSearchLevelIdentifiers(identifiers); // sets search level identifiers for the first three level.
6.1.2.11 Searching for information
Searching feature of ElegantJ JFC Data Tree bean provides facility for searching node values. To make things easier for developer, ElegantJ also provides ready-to-use Search panel. You can search tree in four different ways (up as well as down). You have an option of a case sensitive search, if required.
Options for search progress and Comparison
|
Search Progress from |
Options for search Progress |
|
First node |
com.elegantj.jfc.tree.dataTreeViewer. SEARCH_FROM_FIRST_NODE |
|
Last Node |
com.elegantj.jfc.tree.dataTreeViewer. SEARCH_FROM_LAST_NODE |
|
Selected node upwards |
com.elegantj.jfc.tree.dataTreeViewer. SEARCH_FROM_SELECTED_NODE_TO_UP |
|
Selected node downwards |
com.elegantj.jfc.tree.dataTreeViewer. SEARCH_FROM_SELECTED_NODE_TO_DOWN |
Comparison Options
|
Comparison requirement |
Option for comparison |
|
Search node for value that starts with given search string |
com.elegantj.jfc.tree.dataTreeViewer.STARTS_WITH |
|
Search node for value that ends with given search string |
com.elegantj.jfc.tree.dataTreeViewer.ENDS_WITH |
|
Search node for value or its part equals given search string |
com.elegantj.jfc.tree.dataTreeViewer.CONTAINS_WITH |
|
Search node for value for given string for exact match |
com.elegantj.jfc.tree.dataTreeViewer.EQUALS |
Ø To search tree node with specified node text, specified level, comparison mode and case sensitivity,
String sNode = "node";
int nSearchLevel = 1;
int nCompareMode =
com.elegantj.jfc.tree.dataTreeViewer.EQUALS;
boolean bCaseSensitive = false;
javax.swing.tree.DefaultMutableTreeNode
node =
dataTreeViewer.searchTreeNode(sNode,
nSearchLevel, nCompareMode, bCaseSensitive);
If search string is found, this returns default mutable tree node.
Ø To search tree node with specified node text, specified level, search mode, comparison mode and case sensitivity,
String sNode = "node";
int nSearchLevel = 1;
int nSearchMode =
com.elegantj.jfc.tree.dataTreeViewer.SEARCH_FROM_FIRST_NODE;
int nCompareMode =
com.elegantj.jfc.tree.dataTreeViewer.EQUALS;
boolean bCaseSensitive = false;
javax.swing.tree.DefaultMutableTreeNode
node =
dataTreeViewer.searchTreeNode(sNode,
nSearchLevel, nSearchMode,
nCompareMode, bCaseSensitive);
If search string is found, this returns default mutable tree node.
Ø To search tree node with specified user object,
Object userObject = "search
node";
javax.swing.tree.DefaultMutableTreeNode
node =
dataTreeViewer.searchTreeNode(userObject);
If user object is found, this returns default mutable tree node.
Ø To search tree node with specified user object and level,
Object userObject = "search
node";
int level = 1;
javax.swing.tree.DefaultMutableTreeNode
node =
dataTreeViewer.searchTreeNode(userObject,
1);
If user object is found, this returns default mutable tree node.
Ø To search tree node with the specified user object and parent user object,
Object userObject = "search
node";
Object userObjectOfParent = "parent
node";
javax.swing.tree.DefaultMutableTreenode
node =
dataTreeViewer.searchTreeNode(userObject,
userObjectOfParent);
If user object is found, this returns the default mutable tree node.
Sorting is possible with ElegantJ DataTreeViewer.
A tree may have any of the three state of arrangement -
|
Arrangement |
How to set it |
|
Not sorted |
com.elegantj.jfc.tree.dataTreeViewer.NON_SORT |
|
Sorted in Ascending order |
com.elegnatj.jfc.tree.dataTreeViewer.ASCENDING_SORT |
|
Sorted in Descending order |
com.elegantj.jfc.tree.dataTreeViewer.DESCENDING_SORT |
Ø To sort the tree in ascending order,
dataTreeViewer.setSortedTree(com.elegnatj.jfc.tree.dataTreeViewer.ASCENDING_SORT); // sorts the tree in ascending order.
Ø To sort the whole tree in ascending or descending order using boolean value,
dataTreeViewer.sortTree(true); // sorts the whole tree in ascending order.
Ø To sort particular node's child i.e. particular parent node,
dataTreeViewer.sortTree(parentNode, true); // sorts the parent node in ascending order.
6.1.2.13 Setting visibility and popup menu
ElegantJ DataTreeViewer provides the pop-up menu for the following functionalities,
Ø Insert node
Ø Delete node
Ø Edit node
Ø Add child node
Ø Sort node
All the pop-up menu operations are carried out on selected node.
Ø To set popup visibility to true,
dataTreeViewer.setPopupVisible(true); // which sets the value of ShowPopupVisible to true, so it will be opened on right click on DataTreeViewer.
6.1.2.14 Configuring checkbox tree and features under checkbox tree
ElegantJ DataTreeViewer allows you to make the whole tree as a Checkbox Tree. In a checkbox tree, all the nodes are renderered as checkboxes.
Ø To make checkbox tree, create instance of DataTreeViewer and then set checkbox tree to true in following way,
dataTreeViewer.setCheckboxTree(true); // which sets the tree as checkbox tree.
ElegantJ DataTreeViewer set the default checkbox renderer and editor on checkbox tree. If you want to set your own renderer or editor then you can do that using following methods,
Ø To set checkbox tree cell renderer, which is used in case of checkbox tree
com.elegantj.jfc.common.renderers.CheckboxRenderer
checkboxRenderer = new com.elegantj.jfc.common.renderers.CheckboxRenderer();
dataTreeViewer.setCheckboxTreeCellRenderer(checkboxRenderer); // sets the checkbox cell renderer.
Ø To set checkbox tree cell editor, which is used in case of checkbox tree
com.elegantj.jfc.common.editors.CheckboxEditor
checkboxEditor =
new
com.elegantj.jfc.common.editors.CheckboxEditor();
dataTreeViewer.setCheckboxTreeCellEditor(checkboxEditor); // sets the checkbox cell editor.
Ø ElegntJ DataTreeViewer provides following methods to get checked / unchecked nodes in case of Checkbox tree.
o To get a vector containing checked nodes from whole check box tree,
java.util.Vector nodes = dataTreeViewer.getTreeNodes();
o To get a vector containing checked / unchecked nodes from whole check box tree,
boolean bChecked
= false;
java.util.Vector nodes = dataTreeViewer.getTreeNodes(bChecked); // returns vector containing unchecked nodes.
o To get a vector containing checked / unchecked nodes for specific level,
boolean bChecked
= false;
int level = 2;
java.util.Vector nodes = dataTreeViewer.getTreeNodes(bChecked, level); // returns vector containing unchecked nodes at level 2.
o To get a vector containing checked / unchecked nodes from sub tree,
boolean bChecked
= false;
javax.swing.tree.DefaultMutableTreeNode
parentNode =
dataTreeViewer.getRoot(); java.util.Vector
nodes =
dataTreeViewer.getTreeNodes(bChecked, parentNode); // returns a vector containing unchecked nodes from sub tree whose root is parentNode.
o To get a vector containing checked / unchecked nodes at level 2 from sub tree
boolean bChecked
= false;
int level = 2;
javax.swing.tree.DefaultMutableTreeNode
parentNode =
dataTreeViewer.getRoot();
Vector nodes = dataTreeViewer.getTreeNodes(bChecked, level, parentNode); // returns the vector containing the unchecked nodes at level 2 from subtree whose root is parentNode.
6.1.2.15 Configuring child-parent relationship in checkbox tree
A checkbox tree with Child-Parent relationship implemented improves speed of working with a tree. This works in following way,
Ø If parent node is checked, all children (directly or indirectly under that parent) will get checked.
Ø If parent node is unchecked, all children (directly or indirectly under that parent) also become unchecked.
Ø If any child is unchecked, it's direct-parent also become unchecked.
Ø To activate Child Parent relationship in check box tree
dataTreeViewer.setChildParentRelationship(true);
6.1.2.16 Restricting duplicate nodes
You can restrict creation of duplicate child nodes at same level (for any parent node). This means, user can be restricted from changing values in nodes, if values are getting duplicated at the same level (for any parent node). User will not be able to do this by carrying out operations like editing, inserting, drag and drop or even programmatically. This is specially useful when you want the data be unique.
Ø Do not allow nodes with same values at same level (for any parent node)
dataTreeViewer.setSameNodeAtSameLevel(false);
By default, it is set as true.
If SameNodeAtSameLevel is false,
Ø Duplicate child node cannot be positioned as parent node's child.
Ø If value entered makes same value, either the changes needs to be truncated or new value needs to be entered.
Ø Restricts the duplicate nodes at any depth of the inserted node.
SameNodeAtSameLevel works even in following cases also,
Ø On drag and drop
Ø While node is inserted by insert key
Ø While node is inserted programmatically
Ø While root is set programmatically
6.1.2.17 Configuring data access component with DataTreeViewer
You can use ElegantJ DataTreeViewer 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 DataTreeViewer to fetch data from data source.
Ø To bind SqlDataProvider with DataTreeViewer
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
dataTreeViewer.setDataProvider(sqlDataProvider); // binds the SqlDataProvider to DataTreeViewer
dataTreeViewer.retrieveData(); // retrieves the data from Data Access Component
Ø To bind TextDataProvider with DataTreeViewer.
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
dataTreeViewer.setDataProvider(textDataProvider); // binds the TextDataProvider to DataTreeViewer
dataTreeViewer.retrieveData(); // retrieves the data from Data Access Component
Ø To bind HTTPTextDataProvider to DataTreeViewer.
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
dataTreeViewer.setDataProvider(httpTextDataProvider); // binds the HTTPTextDataProvider to DataTreeViewer
dataTreeViewer.retrieveData(); // retrieves the data from Data Access Component
Ø To bind FTPTextDataProvider to DataTreeViewer.
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
dataTreeViewer.setDataProvider(ftpTextDataProvider); // binds the FTPTextDataProvider to DataTreeViewer
dataTreeViewer.retrieveData(); // retrieves the data from Data Access Component
Ø To bind XMLDataProvider with DataTreeViewer
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
dataTreeViewer.setDataProvider(xmlDataProvider); // binds the XMLDataProvider to DataTreeViewer
dataTreeViewer.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.18 Handling data navigation
nDataTreeViwer 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,
dataTreeViewer.firstRecord(); // moves the cursor to the first record.
Ø To move the cursor to last record,
dataTreeViewer.lastRecord(); // moves the cursor to the last record.
Ø To move the cursor to next record,
dataTreeViewer.nextRecord(); // moves the cursor to the next record.
Ø To move the specific row,
dataTreeViewer.scrollToRow(5); // moves the cursor 5th record.
6.1.2.19 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,
dataTreeViewer.refresh(); // refreshes the data.
Ø To add the row at the end of the data,
dataTreeViewer.addRow(); // adds the row at the end of the data.
Ø To delete the selected row,
dataTreeViewer.deleteRow(); // removes the 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. An 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 Components 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 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);
Ø 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].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();
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");
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);
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 Java Bean.
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 Java Bean 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 Java Bean 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);
Ø 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 Java Bean 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 Java Bean 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();
ElegantJ Text via HTTP Java Bean 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");
ElegantJ Text via HTTP Java Bean 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);
ElegantJ Text via HTTP Java Bean has feature of data search. Any expression can be used as search criteria. ElegantJ Text via HTTP Java 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 Java Bean 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 Java Bean 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 Java Bean 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);
Ø 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 Component 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();
ElegantJ FTP Text Data Access Component 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");
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);
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 Trees 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.