Tutorial - 5 - Iterative segment
Tutorial - 5 - Iterative segment
5 - Iterative segment
Subject BasicTutorial
Version ADK 244
Issue date 16/07/2005
Beneficiaries Developers
File Tutorial - 5 - Iterative segment.doc
Status Final
Checked by Asycuda World - Lyon Competence center
Copyrights United Nations Conference on Trade and Development
Developer Guide
Version ADK 244
5 - Iterative segment
Table of contents
1. MODIFICATION OF THE DATA OBJECT MODEL: SHARED SIDE...... 5
1.1. DEFINITION OF DOM CONSTANTS ................................................................... 5
1.2. CREATION OF THE ITERATIVE PAGE’S DATA MODEL ....................................... 6
1.3. MODIFICATION OF THE DOCUMENT DATA MODEL .......................................... 7
2. SERVER MODIFICATION ............................................................................... 9
2.1. DATABASE CONNECTION ................................................................................. 9
2.2. OPERATION MODIFICATIONS............................................................................ 9
2.3. CREATION OF A TABLE CONNECTOR .............................................................. 10
2.4. ADDING THE SUB TABLE CONNECTOR ............................................................ 11
3. CLIENT MODIFICATION .............................................................................. 12
3.1. CREATE THE ITERATIVE VISUAL PAGE ........................................................... 12
3.2. ADD THE VISUAL PAGE TO THE DOCUMENT ................................................... 13
3.3. ITERATIVE SEGMENT MANAGEMENT .............................................................. 14
3.3.1. Associating events to rules in the client document.................................. 14
3.3.2. Creating the appropriate rules................................................................ 14
4. PROPERTIES FILES........................................................................................ 18
4.1. TUTORIAL5 PROPERTIES FILES ....................................................................... 18
4.2. XML DATABASE TABLE MANAGEMENT ......................................................... 19
4.3. BINDER AND SHORTCUT DEFINITION.............................................................. 20
Figures
FIGURE1 - THIS IS AN EXAMPLE OF FIGURE........................................................................... 3
FIGURE2 - THE CHILD PAGE THAT CAN BE REPEATED ........................................................... 4
FIGURE3 - DOM OF THE ITERATIVE PAGE ............................................................................ 5
FIGURE4 - BUTTONS ASSOCIATED TO THE EVENTS ............................................................. 10
Source code
SOURCE 1 - THIS IS AN EXAMPLE OF SOURCE CODE ................................................................ 3
SOURCE 2 - ADDING THE CONSTANTS OF THE DOM IN C_TUTORIAL5 CLASS......................... 5
SOURCE 3 - IMPLEMENTATION OF THE DS_TUTORIAL5CHILD CLASS .................................... 6
SOURCE 4 - RULE DECLARATION IN THE D_TUTORIAL5 CLASS .............................................. 7
SOURCE 5 - DECLARATION OF EVENTS IN THE C_TUTORIAL5 CLASS ..................................... 8
SOURCE 6 - DATABASE TABLE ALIAS DECLARATION IN THE S_TUTORIAL5 CLASS ................. 9
SOURCE 7 - ADDING VISIBLE EVENTS TO OPERATIONS IN S_TUTORIAL5 CLASS ..................... 9
SOURCE 8 - ADDING EVENTS CONSTANTS IN C_TUTORIAL5 ................................................. 10
SOURCE 9 - CREATION OF THE SUB TABLE CONNECTOR IN THE TC_TUTORIAL5CHILD CLASS
10
SOURCE 10 - SUB TABLE CONNECTOR DECLARATION IN THE TC_TUTORIAL5 CLASS ............ 11
SOURCE 11 - VP_TUTORIAL5CHILD CLASS............................................................................ 12
SOURCE 12 - IMPLEMENTATION OF THE VF_TUTORIAL5CHILD CLASS .................................. 13
SOURCE 13 - ADDING NEW FORM IN THE VD_TUTORIAL5 CLASS .......................................... 13
SOURCE 14 - ADDING RULES IN THE DC_TUTORIAL5 CLASS.................................................. 14
SOURCE 15 - R_PAGE_NEW RULE CLASS ............................................................................... 15
SOURCE 16 - R_PAGE_DELETE RULE CLASS .......................................................................... 15
SOURCE 17 - R_MANAGECHILDVISUALEVENTS RULE CLASS................................................. 16
SOURCE 18 - ADDING RULE IN THE DC_TUTORIAL5 CLASS ................................................... 17
SOURCE 19 - UN.ASYTUTORIAL.TUTORIAL5.PROPERTIES FILE................................................ 18
SOURCE 20 - UN.ASYTUTORIAL.PROPERTIES .......................................................................... 18
SOURCE 21 - ASYUTORIAL_CREATE.XML MODIFICATIONS ..................................................... 19
SOURCE 22 - ASYTUTORIAL_INSERT.XML MODIFICATIONS .................................................... 19
SOURCE 23 - ADDING BINDER AND SHORTCUT IN THE INSTALL_SRC.XML FILE ...................... 20
Keyword Definition
Source 1 -
This is an example
of source code Source code.
Objective
In this document you will learn
How to implement an iterative page in an e-Document
Required element
Tutorial4 e-Document
The iterative page that will be created in this tutorial, represent the children of a person. An
undefined number of children can be attached to a person.
Infinite iteration groups of data that can repeat an infinite number of times: they are
dynamically created by the e-document’s user.
An infinite iteration is identified by a rank and requires the creation of a class extending
KNumberedSubDocument to implement the iteration segment. This class is then linked to
the main data model using the numberedItm() method.
A new iteration segment and a new visual page are created dynamically by the user by
generating a visual event (i.e. clicking on a button). This event will then trigger two rules.
One of these rules is responsible for generating a dynamic page and is actually managed by a
new visual form class extending the KVisualFormWithNumberedPages class. The
constructor of this new class refers (through its parameters) to the events fired by the client
when creating the new dynamic page. These events objects contain as a source, the form from
where they where generated.
Source 2 -
adding the …
constants of the // Segment Child
DOM in public static final String CHD = "CHD";
// child first name
C_Tutorial5 class public static final String CFN = "CFN";
// child Birth date
public static final String CBD = "CBD";
…
Source 3 -
Implementation of package un.asytutorial.tutorial5;
the import so.kernel.core.KNumberedSubDocument;
DS_Tutorial5Child
public class DS_Tutorial5Child extends KNumberedSubDocument implements
class C_Tutorial5 {
/**
* Constructor without parameter is required for desktop persistence
*/
public DS_Tutorial5Child() {
super();
}
/**
* Definition of the Data Model
*/
public void define_DataModel() {
add(CFN); // Child name
add(CBD); // Child age
define_DataInformation();
}
/**
* Definition of the Data Information
*/
public void define_DataInformation() {
setHumanName(lng("Child"));
de(CFN).setHumanName(lng("child first name"));
de(CBD).setHumanName(lng("child birth date"));
}
/*
* Method to indicate if the document is empty. Here a child document is empty
* if there is no child name specified.
*/
public boolean isEmpty() {
return (de(CFN).getString("").trim().equals(""));
}
/**
* Definition of the Client Business Rules
*/
public void define_ClientBusinessRule() { }
/**
* Retrieves a property string in the current working language.
*/
public static String lng(String property) {
return so.i18n.IntlObj.createMessage("Tutorial", property);
}
}
Source 4 -
Rule declaration in …
the D_Tutorial5 import so.kernel.core.rules.KR_NumberedSubDocumentManager;
class …
Public void define_DataModel() {
.. ..
// Child numbered sub-document
numberedItm(CHD, new DS_Tutorial5Child());
.. ..
}
…
public void define_ClientBusinessRule() {
KR_NumberedSubDocumentManager rule =
new KR_NumberedSubDocumentManager(ds(CHD),
ACT_CHILD_NEW,
ACT_CHILD_DEL);
addRule(rule, ACT_CHILD_NEW);
addRule(rule, ACT_CHILD_DEL);
}
….
Source 5 -
Declaration of …
events in the // Visual middle events
C_Tutorial5 class public static final int ACT_CHILD_NEW = KernelEvent.INTERNAL_EVENTS_MAX +12;
public static final int ACT_CHILD_DEL = KernelEvent.INTERNAL_EVENTS_MAX + 13;
…
2. Server modification
Source 6 -
Database table …
alias declaration in // Name of the resource table identifier for the Customs database tables
the S_Tutorial5 public static final String PERSON_TAB = "TUTORIAL_PERSON_TAB";
public static final String CHILD_TAB = "TUTORIAL_CHILD_TAB";
class …
Source 7 -
Adding visible …
events to operations protected Operations createValidOperations() {
in S_Tutorial5 ….
Operation op_Create =
class OperationFactory.makeCreateOperation(OI_CREATE, OP_CREATE);
op_Create.addVisibleEventID( MEN_CHILD_NEW,
"Add child",
lng("Add child"),
"img/Btn_New_Normal.gif");
op_Create.addVisibleEventID( MEN_CHILD_DEL,
"Delete child",
lng("Delete child"),
"img/Btn_No_Normal.gif");
ops.add(op_Create);
Operation op_Update =
OperationFactory.makeUpdateOperation(OI_UPDATE, OP_UPDATE);
op_Update.addVisibleEventID( MEN_CHILD_NEW,
"Add child",
lng("Add child"),
"img/Btn_New_Normal.gif");
op_Update.addVisibleEventID( MEN_CHILD_DEL,
"Delete child",
lng("Delete child"),
"img/Btn_No_Normal.gif");
ops.add(op_Update);
….
}
This buttons are associated with visible events (names are starting with MEN_). These events
must be declared in the C_Tutorial5 interface.
Source 8 -
adding events // Visual middle events
constants in public static final int MEN_CHILD_NEW = KernelEvent.INTERNAL_EVENTS_MAX +10;
C_Tutorial5 public static final int MEN_CHILD_DEL = KernelEvent.INTERNAL_EVENTS_MAX + 11;
Source 9 -
Creation of the sub package un.asytutorial.tutorial5.server;
table connector in
the import java.sql.Types;
import so.kernel.core.KNumberedSubDocument;
TC_Tutorial5Child import so.kernel.server.ConnectionManager;
class import so.kernel.server.KNumberedSubTableConnector;
import so.kernel.server.TableConnector;
import un.asytutorial.tutorial5.C_Tutorial5;
setParticipateInSearch(true);
}
}
Source 10 -
Sub table connector ....
declaration in the public TC_Tutorial5( GCFServerBinder serverBinder, ConnectionManager
TC_Tutorial5 class connectionManager) {
super(serverBinder, connectionManager, S_Tutorial5.getPERSON_TAB());
serverBinder.setInstanceIdField(this, INSTANCE_ID, INSTANCE_ID);
…
3. Client modification
Source 11 -
VP_Tutorial5Child package un.asytutorial.tutorial5.client;
class
import java.awt.Color;
import java.awt.Font;
import so.kernel.client.KVisualPage;
import so.kernel.client.elf.ElfField;
import so.kernel.client.elf.ElfVisualPage;
import so.swing.KPanel;
import un.asytutorial.tutorial5.C_Tutorial5;
public VP_Tutorial5Child() {
super();
initVisualPage();
initVisualControls();
}
// Label
add( 20, 50, 100, 24, lng("First name"));
add( 20, 100, 100, 24, lng("Birth date "));
/**
* Retrieves a property string in the current working language.
*/
public static String lng(String property) {
return so.i18n.IntlObj.createMessage("Tutorial", property);
}
}
Source 12 -
Implementation of package un.asytutorial.tutorial5.client;
the
VF_Tutorial5Child import so.kernel.client.KVisualFormWithNumberedPages;
import so.kernel.client.KVisualPage;
class import un.asytutorial.tutorial5.C_Tutorial5;
/**
* Constructor
*/
public VF_Tutorial5Child() {
super(lng("Child"), CHD, ACT_CHILD_NEW, ACT_CHILD_DEL);
}
/**
* Retrieves a property string in the current working language.
*/
public static String lng(String property) {
return so.i18n.IntlObj.createMessage("Tutorial", property);
}
}
Source 13 -
Adding new form in …
the VD_Tutorial5 public void initializeForms() {
class …
VF_Tutorial5Child formChild = new VF_Tutorial5Child();
…
addForm(formChild);
…
}
Source 14 -
Adding rules in the package un.asytutorial.tutorial5.client;
DC_Tutorial5 class
import so.kernel.client.ClientDocument;
import so.kernel.core.KernelEvent;
import so.kernel.core.KernelEventConstants;
import so.kernel.core.events.EventConstants;
import un.asytutorial.tutorial5.C_Tutorial5;
import un.asytutorial.tutorial5.D_Tutorial5;
import un.asytutorial.tutorial5.client.rules.R_Page_Delete;
import un.asytutorial.tutorial5.client.rules.R_Page_New;
In this tutorial, rules are briefly presented. More explanations about rules are
given in tutorial 8.
Source 15 -
R_Page_New rule package un.asytutorial.tutorial5.client.rules;
class
import so.kernel.core.*;
import un.asytutorial.tutorial5.*;
/**
* Handle a "new child" visible event, and fire the CHILD_NEW event.
*/
public class R_Page_New extends Rule implements C_Tutorial5 {
cmp.fire(new KernelEvent(ACT_CHILD_NEW));
}
}
}
The second rule, R_Page_Delete, is a bit more complex because verifications are done
to be sure to delete the good form. But the main thing to remember here is the firing of
event for the triggering of actions declared on the sub segment of the DOM.
Source 16 -
R_Page_Delete rule package un.asytutorial.tutorial5.client.rules;
class
import java.text.MessageFormat;
import so.util.DebugOutput;
import so.kernel.core.Rule;
import so.kernel.core.*;
import so.kernel.client.*;
import so.swing.KOptionPane;
import un.asytutorial.tutorial5.*;
import un.asytutorial.tutorial5.client.VD_Tutorial5;
/**
* Handle a "delete child" visible event, requests user confirmation, and eventually
* fire the CHILD_DEL event to delete the current child.
*/
public class R_Page_Delete extends Rule implements C_Tutorial5 {
private VD_Tutorial5 vd;
if (cmp != vd.getDocument()) {
DebugOutput.error("The rule has been added to a doc that is not attached to given
skin");
return;
}
KVisualDynamicForm vf = (KVisualDynamicForm)vd.getSelectedForm();
KVisualPage vp = (KVisualPage)vf.getSelectedPage();
We implement one last rule which allows to access the button add and delete child only on
the child form.
Source 17 -
R_manageChildVis package un.asytutorial.tutorial5.client.rules;
ualEvents rule
class import so.kernel.core.Rule;
import so.kernel.core.events.client.*;
import so.kernel.core.*;
import so.kernel.client.*;
import un.asytutorial.tutorial5.C_Tutorial5;
import un.asytutorial.tutorial5.client.*;
GUIFormGainFocusEvent ev = (GUIFormGainFocusEvent)e;
Document doc = (Document)ev.getSource();
VisualForm vf = ev.getForm();
Source 18 -
Adding rule in the …
DC_Tutorial5 class import un.asytutorial.tutorial5.client.rules.R_manageChildVisualEvents;
…
void initRules(D_Tutorial5 doc, VD_Tutorial5 vd) {
// Manage add, delete logic and user dialog
doc.addRule(new R_page_new(), new KernelEvent(MEN_CHILD_NEW));
doc.addRule(new R_page_delete(vd), new KernelEvent(MEN_CHILD_DEL));
//Enable and disable the new (MEN_CHILD_NEW) and delete (MEN_CHILD_DEL) contact
events according to the form that has the focus.
doc.addRule(new R_ManageChildVisualEvents(),
EventConstants.GUI_FORM_GAIN_FOCUS);
}
…
4. Properties files
In this chapter you will learn
Source 19 -
Un.asytutorial.tutor un.asytutorial.tutorial5.server.S_Tutorial5#TUTORIAL_PERSON_DataBaseURL=
ial5.properties file $[un.asytutorial_URL]
un.asytutorial.tutorial5.server.S_Tutorial5#TUTORIAL_PERSON_DataBaseUser=
$[un.asytutorial_User]
un.asytutorial.tutorial5.server.S_Tutorial5#TUTORIAL_PERSON_DataBasePassword=
$[un.asytutorial_Password]
un.asytutorial.tutorial5.server.S_Tutorial5#TUTORIAL_PERSON_TAB=
TUTORIAL5_PERSON_TAB
un.asytutorial.tutorial5.server.S_Tutorial5#TUTORIAL_CHILD_TAB=
TUTORIAL5_CHILD_TAB
Also add the following line in the un.asytutorial.properties to take into account
the property file created:
Source 20 -
Un.asytutorial.prop @include un.asytutorial.tutorial2.properties
erties @include un.asytutorial.tutorial3.properties
@include un.asytutorial.tutorial4.properties
@include un.asytutorial.tutorial5.properties
….
Source 21 -
Asyutorial_create.x <create>
ml modifications ……
<table name="TUTORIAL5_PERSON_TAB">
<column name= "INSTANCE_ID" type="INTEGER" null="false"/>
<column name= "IDE_FNA" type="VARCHAR" size="35"/>
<column name= "IDE_LNA" type="VARCHAR" size="35"/>
<column name= "IDE_BDA" type="TIMESTAMP"/>
<column name= "IDE_PIC" type="LONGVARBINARY"/>
<column name= "IDE_SEX" type="INTEGER"/>
<column name= "COO_ADR" type="VARCHAR" size="50"/>
<column name= "COO_CPO" type="VARCHAR" size="6"/>
<column name= "COO_TEL" type="VARCHAR" size="20"/>
<column name= "COO_CIT" type="VARCHAR" size="25"/>
<column name= "USR_LOG" type="VARCHAR" size="25"/>
<column name= "USR_PWD" type="VARCHAR" size="20"/>
<primary_key>
<column name= "INSTANCE_ID"/>
</primary_key>
</table>
<table name="TUTORIAL5_CHILD_TAB">
<column name="INSTANCE_ID" type="INTEGER" null="false"/>
<column name="RNK" type="INTEGER" null="false"/>
<column name="CHD_NAM" type="VARCHAR" size="35" />
<column name="CHD_BDA" type="TIMESTAMP"/>
</table>
</create>
Source 22 -
Asytutorial_insert.x <insert>
ml modifications <table name="TUTORIAL2_PERSON_TAB">
</table>
<table name="TUTORIAL3_PERSON_TAB">
</table>
<table name="TUTORIAL4_PERSON_TAB">
</table>
<table name="TUTORIAL5_PERSON_TAB">
</table>
<table name="TUTORIAL5_CHILD_TAB">
</table>
</insert>
Source 23 -
Adding binder and …….
shortcut in the <BU name="BUasytutorial">asytutorial BU</BU>
install_src.xml file ……
<binder name="B_TUTORIAL_5" status="">
<field name="server" value="un.asytutorial.tutorial5.server.S_Tutorial5"/>
<field name="dom" value="un.asytutorial.tutorial5.D_Tutorial5"/>
<field name="client" value="un.asytutorial.tutorial5.client.DC_Tutorial5"/>
<access bu="BUasytutorial">
<full/>
</access>
</binder>
…
<DL>
<folder name="Tutorial" icon="">
……..
<item name="Tutorial 5: Iterative Segment" icon="">
<field name="binder" value="B_TUTORIAL_5"/>
<field name="skin" value="un.asytutorial.tutorial5.client.VD_Tutorial5"/>
<access bu="BUasytutorial">
<full/>
</access>
</item>
</folder>
</DL>
Now you can compile and deploy your module with Ant tools.
Summary