|
|
|
Last
revision of this document: |
Till
now, the application was only able to store data into the database.
To see, what data is already gathered, this step implements
functionality to display all existing Project/Language combinations
in a 'table'.
The definition 'table' refers to a list with several
columns and a header.
Overview:This
document covers the following steps:
* Create
a method (redisplayProject())
within the 'ActionHandler',
* Create
the class for DataBaseAccess to get a list of all valid
Projects,
* Create
all derivations of the classes for the Business Object holding the
list of valid Projects,
* Define
a variable for the just created BOC with the set of
'Project's,
* Retrieve
the list of valid Projects in the method redisplayProject(),
* Create
a method to fill a JTable with the data from the vector and call this
method,
* Extend
the XML-structure for language dependant text-elements to hold text
for table-headers,
* Run
and verify the result.
Preface:*
First, a set of classes for a Business Object, that is able to read a
set of data, is developed – and the suitable DBA object too.
*
Then, the data retrieved from the Business Object is parsed into a
Vector for a later display in the 'table'.
Those two subtasks
follow the scheme of the Tasks
JS_FC01k
– Develop the General Class for the Business Object
'Project',
JS_FC01l – Develop
the Client-Side Class for the Business Object 'Project',
JS_FC01m –
Data-Base-Access (DBA) Object for the table'Project' and
JS_FC01o
– Develop the Server-Side Class for the Business Object
'Project'.
From
then on, the code gets more sophisticated.
The historic reason is,
that I had the classes alredy developed before I started to write
this tutorial.
I had a lot of discussion with friends if I should
write more simplified classes for the tutorial.
Finally, I
decided to keep the already written classes.
I think, this
solution is closer to 'real life': there you also have to use
libraries with classes you might not know in detail ;-) .
To
fill a JTable with a headline and data – both provided in the
structure of a 'Vector', a method is developed in the base .class
JSBS_XML_DisplayStrings
The
language-dependant text for the header of the table is read from a
file with XML-structure; please refer to XML-Structure
for language dependant text-elements for the user-interface for a
detailed description.
Credits:Too
numerous to mention; the idea is available in dozens of versions –
I refined a lot of ideas into my system.
JS_FC01q – React to the 'Store' button and save the data into the database has to be completed (and its prerequisites too) as there have to be some data in the database to display it as a list.
Create
a method (redisplayProject())
within the ActionHandler:As
the class JS_ErrDB_Project__ActionHandler
holds per definition all the methods that carry out actions, a method
called redisplayProject()is
added to this class.
For
now, this method is only a skeleton which will be filled with calls
of other methods as this step progresses./* }
*
Method to store the data from the GUI-elements to the database.
*/
protected
static void redisplayProject(JS_ErrDB_Project parmTF) {/*
* Get all actual 'Project/Language' combinations from
the database
* and display them as list. */
This
method is called within two other methods.
* First, when the
frame is constructed, then all Project/Language combinations are
displayed.
This call is in
class JS_ErrDB_Project
within the method initialize_after_frame():
private
void initialize_after_frame()
{
JSBS_GUIServices.processLanguageDependantElements(this); JS_ErrDB_Project__ActionHandler.redisplayProject( }this);
*
Second, after a dataset is stored.
This call is
in
clasithin the method store():
s
JS_ErrDB_Project__ActionHandler
w protected
static void store(JS_ErrDB_Project parmTF) { }; .
. . . . . . .
. . . . . .
System.out.println("StatusMsg:
"
+
parmTF.);structJS_ErrDB_Project_BOC_Processed.StatusMsg/*
* Redisplay the list with all Project/Language
combinations. */
redisplayProject(parmTF);
}
Create
the class for DataBaseAccess to get a list of all valid ProjectsFirst
of all, a base-class is developed.
This class holds
* a
vector which will later be filled with the data read from the
database-table,
* some variables and
* methods
to be used
by derived classes.
Please refer to class JSBS_DBA_Set
for explanations of the code.
In
detail, the class JS_ErrDB_Project_Set_DBA
holds the code that reads the set of records from the database.
For
an explanation of the code, please refer to the comments.
Create
all derivations of the classes for the Business Object holding the
list of valid ProjectsAs
like for the DBA object, a base-class for holding a 'set of Business
Objects' is developed too.
This class holds
* a vector which
will later be filled with the data read from the database-table,
*
a vector which holds formatted data for later display,
* some
variables and
* methods
to be used by derived classes.
Please
refer to class JSBS_BO_Set
for explanations of the code.
And
now to the individual Business Object (BO) modelling a set of
'Project's.
As lined out in the document Using
Business Objects to handle data-storage and retrieval, a Business
Object is implemented using 3 classes.
The
general steps to develop such a class-triangle for a BO where
documented in detail for the BO 'Project', so it is not repeated
here.
Please refer to the classes JS_ErrDB_Project_Set_BO,
JS_ErrDB_Project_Set_BOS
and JS_ErrDB_Project_Set_BOC
for an explanation of the code.
Main Differences (compared to the
classes to manipulate a single BO) are:
* In the
general-class, the method to transfer the data from one object to
another is slightly different.
There is a loop within each element
of the vector is transferred with the method developed for a BO.
* In
the server-side-derivation, a 'store()' method
is not implemented as it would be to complicated and intransparent to
update or store a whole set of BO.
* In the
client-side-derivation, a method is introduced that generates a
'raw-data-vector'. This vector helds the data in the form of
strings.
This is a preparation for a later display of the data in
a JTable.
Please
note that the class JS_ErrDB_Project_Set_BOC
shows an error as the method to fill a JTable
using the raw-data is not implemented yet – this implementation
is documented two steps later.
Define
a variable for the just created BOC with the set of 'Projects':That
the classwith the set of
'Projects' can be accessed, a variable has to be defined.
JS_ErrDB_Project_Set_BOC
This is
done in the class
JS_ErrDB_Project
:
First
check that the whole directory is imported; from previous steps just
one class might be specified: import
javax.swing.table.DefaultTableColumnModel;
import
js_base.frame.*;
import
js_errdb.boc.*;
/**
*
* @author kurt@javascout.biz
/*The
definition as variable:
private
DefaultTableColumnModel
pnl_SelectionListDefaultTableColumnModel=null;
* Business
Objects maintained within this task. */ protected
JS_ErrDB_Project_BOC structJS_ErrDB_Project_BOC_Read; protected
JS_ErrDB_Project_BOC structJS_ErrDB_Project_BOC_Processed;/*
* Set
of Business Objects for display of selection choice.
*/ protected
JS_ErrDB_Project_Set_BOC structJS_ErrDB_Project_Set_BOC;/*
*
-------------------------------
* Constructor of the class
*/public
JS_ErrDB_Project(JSBS_StartFrame parmCC)
Additionally,
the object has to be initialized: /*
*/
private
void initialize_before_frame()
{ }/*
Construct the Business Objects maintained by this task.
*/
structJS_ErrDB_Project_BOC_Read
= new
JS_ErrDB_Project_BOC(this); structJS_ErrDB_Project_BOC_Processed
= new
JS_ErrDB_Project_BOC(this);/*
*/
structJS_ErrDB_Project_Set_BOC
= new
JS_ErrDB_Project_Set_BOC(this);
private
void initialize_frame()
{
Retrieve
the list of valid Projects in the method redisplayProject()As
this step has a pretty long todo-list until a result is visible, you
might now use the debugger to verify if the implementation works till
now.
Otherwise you may skip this paragraph and forward to Create
a method to fill a JTable with the data from the vector and call this
method.
To
do so, the method
redisplayProject() in JS_ErrDB_Project__ActionHandler
is extended to use the JS_ErrDB_Project_Set_BO created in the
paragraphs before.
Add
the bold-printed code to the existing method:/* }
* Method
to retrieve the list of valid Project/Language combinations
* and
display it in the JTable GUI-element. */
protected
static void redisplayProject(JS_ErrDB_Project parmTF) {/*
* Get all actual 'Project/Language' combinations from
the database. */ parmTF.structJS_ErrDB_Project_Set_BOC
=
new
JS_ErrDB_Project_Set_BOC(parmTF); /*
parmTF.structJS_ErrDB_Project_Set_BOC.getAllValidProjectLanguageCombinations();
* Check for errors. */ if
(parmTF.structJS_ErrDB_Project_Set_BOC.StatusCode
!=
JSBS_BO.)
{CONST_OK
System.out.println(
"Error
in gettAllProjectLanguageCombinations() of JS_ErrDB_Project_BOC; "
);+
"class
JS_ErrDB_Project__ActionHandler /
redisplayProject()." System. out.println("StatusCode:
"
+
Integer.toString(parmTF.));structJS_ErrDB_Project_Set_BOC.StatusCode System.out.println("StatusMsg:
"
+
parmTF.);structJS_ErrDB_Project_Set_BOC.StatusMsg};
You
might start the debugger now and watch the result of the
database-operation.
If you are not familiar with debugging, please
refer to React
to the 'Store' button and save the data in the database | Use the
debugger to track down programming errors .
Create
a method to fill a JTable with the data from the vector and call this
method:For
some theory about the the structure of the XML-file with language
dependant text please refer to Structure
of the XML-file with language-dependant text-elements for the
user-interface.
Please
refer to the method processJTable()
of class JSBS_XML_DisplayStrings
for an explanation of the code.
Extend
the XML-structure for language dependant text-elements to hold text
for table headers:The
language-dependant text for the headers of the table is defined in
the file DisplayStrings.xml
too.
Additionally, this XML-structure defines the sort-order of
the columns.
By omitting the xml-element for a column, this column
is not displayed.
As
the structure of the file was described in detail in steps JS_FC01g
– Setting the properties of the GUI-Elements (particular
the "JFrame") and JS_FC01h –
Setting the properties of the GUI-Elements, Part 2 (particular
"JLabel" and "JTextField", here is just
documented which additional elements have to be inserted to set the
properties of a "JTable".public
class JSBS_StartFrame
extends
{JFrame
implements
ActionListener,
KeyListener, FocusListener /*/*
*
Constants for the Run-Version.
* StandAlone: Database is
on the same machine as the application. *
FatClient: Data is on a Java-Application-Server (JAS); multiple
clients possible. *
MobileClient: Data from the JAS is mirrored t a local databas on a
mobile-client (notebook); public
static final
* Data-entry
can be done on the mobile-client and data is
synchronized
* when
a connection to the JAS is established again. */int
CONST_StandAlone=
1; public
static final int
CONST_FatClient=
2; public
static final int
CONST_MobileClient =
3;
/* Variable
for the run-version to be delivered. */ public
int RunVersion;/*
* Connection-Manager
for access to the database.
*/ public
JSBS_DB_ConnectionManager
structJSBS_DB_ConnectionManager;
*
Structure with a variety of parameters;
* please see
description for eacht variable at the class of the structure.
*/public
JSBS_UniversalParameters
structJSBS_UniversalParameters;
.
. . . . . . .
. . . . . . . .
Run
and verify the result:The
implemented code does not lead to any visible result till now.
A
verification that can be done, is to check against absence of errors
when constructing the ConnectionManager.
To
see the result of the just typed code, run the application again by
selecting
>Run>Run....
Select 'JS_ErrDB_CommandCenter'
(in the left column under 'Java
Application') and click the button [ Run ].
A
good sign is, if the usual frame appears and the 'Console' section
stays empty.
A
sign of an error is, if there is something printed out in the
'Console' section.
Next
Step:Finally,
data will be stored in the database.
JS_FC01q
– React to the 'Store' button and save the data in the
database.