Tutorial - 3 - GUI
Tutorial - 3 - GUI
Subject BasicTutorial
Version ADK 244
Issue date 16/07/2005
Beneficiaries Developers
File Tutorial - 3 - GUI.doc
Status Final
Checked by Asycuda World - Lyon Competence center
Copyrights United Nations Conference on Trade and Development
Developer Guide
Version ADK 244
3 - Graphical User Interface
Table of contents
1. DOM MODIFICATION...................................................................................... 7
2. CLIENT MODIFICATION .............................................................................. 10
2.1. USER FORM ................................................................................................... 11
2.2. PERSONAL INFORMATION FORM .................................................................... 13
2.2.1. Identity page ............................................................................................ 14
2.2.2. Coordinate page ...................................................................................... 15
3. SERVER MODIFICATION ............................................................................. 18
4. PROPERTIES FILES........................................................................................ 18
4.1. TUTORIAL3 PROPERTIES FILES ....................................................................... 18
4.2. XML DATABASE TABLE MANAGEMENT ......................................................... 18
4.3. BINDER AND SHORTCUT DEFINITION.............................................................. 18
4.4. EXPORTING THE DATABASE ........................................................................... 18
Figures
FIGURE1 - THIS IS AN EXAMPLE OF FIGURE........................................................................... 4
FIGURE2 - FIRST PAGE OF THE FORM « PERSONAL INFORMATION »...................................... 5
FIGURE3 - SECOND PAGE OF THE FORM « PERSONAL INFORMATION » ................................. 6
FIGURE4 - PAGE OF THE FORM « USER INFORMATION » ....................................................... 6
FIGURE5 - NEW DOM TO CREATE ........................................................................................ 7
FIGURE6 - THE DIFFERENT TABS OF A DOCUMENT .............................................................. 10
FIGURE7 - XML IMPORT TOOL ............................................................................................ 18
Source code
SOURCE 1 - THIS IS AN EXAMPLE OF SOURCE CODE ................................................................ 4
SOURCE 2 - ADDING DATA MODEL CONSTANTS IN THE C_TUTORIAL3 CLASS ....................... 7
SOURCE 3 - D_TUTORIAL3 CLASS MODIFICATIONS ............................................................... 8
SOURCE 4 - DATA INFORMATION DEFINITION IN THE D_TUTORIAL3 CLASS ........................... 9
SOURCE 5 - ADDING FORMS IN THE VD_TUTORIAL3 CLASS................................................. 10
SOURCE 6 - VF_TUTORIAL3USER NEW FORM ...................................................................... 11
SOURCE 7 - OLD BACKGROUND IN VP_TUTORIAL3USER CLASS........................................... 12
SOURCE 8 - IMAGE BACKGROUND IN VP_TUTORIAL3USER CLASS ...................................... 12
SOURCE 9 - VP_TUTORIAL3USER: A PAGE CONTAINING A PASSWORD FIELD ....................... 12
SOURCE 10 - MODIFICATION OF THE VF_TUTORIAL3 FORM .................................................. 13
SOURCE 11 - VP_TUTORIAL3IDE CLASS MODIFICATIONS ..................................................... 14
SOURCE 12 - VP_TUTORIAL3COO MODIFICATIONS .............................................................. 16
SOURCE 13 - FORMAT DECLARATION IN THE TEXTFORMAT.PROPERTIES FILE ........................ 17
SOURCE 14 - TABLE CONNECTORS DECLARATION IN THE TC_TUTORIAL3 CLASS .................. 18
SOURCE 15 - UN.ASYTUTORIAL.TUTORIAL3.PROPERTIES FILE................................................ 18
SOURCE 16 - UN.ASYTUTORIAL.PROPERTIES .......................................................................... 18
SOURCE 17 - ASYUTORIAL_CREATE.XML MODIFICATIONS ..................................................... 18
SOURCE 18 - ASYTUTORIAL_INSERT.XML MODIFICATIONS .................................................... 18
SOURCE 19 - ADDING BINDER AND SHORTCUT IN THE INSTALL_SRC.XML FILE ...................... 18
Keyword Definition
Source 1 -
This is an example
of source code Source code.
Objective
In this document you will learn
How to use the different visual components available
How to declare new formats.
Required element
Tutorial2 e-Document
The main goal of this tutorial is to present the different kinds of visual components that can be
used to create an e-Document.
The organization of an e-Document will also be presented throughout the use of multiple
forms and pages.
1. DOM Modification
The new DOM has 3 segments and should look like as follow:
IDE
Visual field Data element
FNA First name FNA
USR
LOG
PWD
Source 2 -
Adding Data Model ….
constants in the /**
C_Tutorial3 class * Data Model.
*
*/
//Key
// Segment Identity
public static final String IDE = "IDE";
// First name
public static final String FNA = "FNA";
// Last name
public static final String LNA = "LNA";
// Birth date
public static final String BDA = "BDA";
// Picture
public static final String PIC = "PIC";
// Sex
public static final String SEX = "SEX";
// Segment Coordinate
public static final String COO = "COO";
// Address
public static final String ADR = "ADR";
// Postal code
public static final String CPO = "CPO";
// City
public static final String CIT = "CIT";
// Telephone
public static final String TEL = "TEL";
// Segment User
public static final String USR = "USR";
// login name
public static final String LOG = "LOG";
// Password
public static final String PWD = "PWD";
….
Source 3 -
D_Tutorial3 class …
modifications public void define_DataModel() {
// Normal data
DataSet ide = seg(IDE); // Identity
ide.add(FNA); // firstname
ide.add(LNA); //lastname
ide.add(BDA); //birth date
ide.add(PIC); // picture
ide.add(SEX); // sex
define_DataInformation();
}
Source 4 -
Data information public void define_DataInformation() {
definition in the
D_Tutorial3 class setHumanName(lng("Tutorial 3"));
//Segment Identity
ds(IDE).setHumanName(lng("Identity"));
ds(IDE).de(FNA).setHumanName(lng("Firstname"));
ds(IDE).de(LNA).setHumanName(lng("Lastname"));
ds(IDE).de(BDA).setHumanName(lng("Birthdate"));
ds(IDE).de(PIC).setHumanName(lng("Picture"));
ds(IDE).de(SEX).setHumanName(lng("Sex"));
// Segment Coordinate
ds(COO).setHumanName(lng("Coordinate"));
ds(COO).de(ADR).setHumanName(lng("Address"));
ds(COO).de(CPO).setHumanName(lng("Postal code"));
ds(COO).de(CIT).setHumanName(lng("City"));
ds(COO).de(TEL).setHumanName(lng("Telephone"));
// Segment User
ds(USR).setHumanName(lng("User"));
ds(USR).de(LOG).setHumanName(lng("Login"));
ds(USR).de(PWD).setHumanName(lng("Password"));
2. Client modification
A visual document can contain different sorts of tabs representing forms and pages. A form
can have multiple pages.
Tabs representing
a form
In this tutorial, the main changes are in the client part. This tutorial has 2 forms:
• One describing the personal information of a person. This form contains 2 pages:
A page for a short presentation of the person.
A page for the coordinate of the person.
• One giving information about the user associated to the person.
These forms have to be added to the document in the VD_Tutorial3 class as shown below.
Source 5 -
Adding forms in the package un.asytutorial.tutorial3.client;
VD_Tutorial3 class
import so.kernel.client.*;
import un.asytutorial.tutorial3.C_Tutorial3;
super();
setTitle(lng("Document title"));
}
/**
* Retrieves a property string in the current working language.
*
*/
public static String lng(String property) {
return so.i18n.IntlObj.createMessage("Tutorial", property);
}
}
At this step, the document contains 2 forms, which is represented by the 2 tabs at the bottom
of the document.
Source 6 -
VF_Tutorial3User package un.asytutorial.tutorial3.client;
new form
import so.kernel.client.VisualForm;
/**
* Retrieves a property string in the current working language.
*
*/
public static String lng(String property) {
return so.i18n.IntlObj.createMessage("Tutorial", property);
}
}
The next step is to define the visual components of the page and the facets associated. In this
page, the only newness is the password field which has the particularity of masking what the
user is typing.
We changed also the background by an image. We have to replace these two lines in
initVisualPage() function:
Source 7 -
old background in …
VP_Tutorial3User setBackgroundFilter(new Color(0, 0, 0, 255), true);
class setBackgroundGradientFilter(200, 200, new Color(255, 255, 255, 255), 0, 0,
new Color(0, 0, 102, 255), 2);
…
by:
Source 8 -
Image background …
in setBackgroundImage(so.swing.IconResourcer.getIcon("img/aw2t.gif"),KPanel.ST
VP_Tutorial3User RETCH);
class …
Source 9 -
VP_Tutorial3User: package un.asytutorial.tutorial3.client;
a page containing a
password field 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.kernel.core.client.facets.VisualFacetJTextComponent;
import so.swing.KPanel;
import so.swing.KPasswordField;
import un.asytutorial.tutorial3.C_Tutorial3;
// Label
// syntax: add( X, Y, Width, Height, lng("label caption"));
add(20,50,80,24,lng("Login"));
add(20,100,80,24,lng("Password"));
/**
* Retrieves a property string in the current working language.
*
*/
public static String lng(String property) {
return so.i18n.IntlObj.createMessage("Tutorial", property);
}
}
Source 10 -
Modification of the package un.asytutorial.tutorial3.client;
VF_Tutorial3 form
import so.kernel.client.VisualForm;
addPage(pageIDE);
addPage(pageCOO);
}
/**
* Retrieves a property string in the current working language.
*/
public static String lng(String property) {
return so.i18n.IntlObj.createMessage("Tutorial", property);
}
}
The two new pages replace the one of the preceding tutorial: VP_Tutorial3IDE and
VP_Tutorial3COO. The first one is a modification of the VP_Tutorial2 from tutorial 2
and can be thus reused.
Source 11 -
VP_Tutorial3IDE package un.asytutorial.tutorial3.client;
class modifications
import java.awt.Color;
import java.awt.Font;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import so.kernel.client.KVisualPage;
import so.kernel.client.elf.ElfField;
import so.kernel.client.elf.ElfVisualPage;
import so.swing.KPanel;
import un.asytutorial.tutorial3.C_Tutorial3;
public VP_Tutorial3IDE() { …. }
// Label
// syntax: add( X, Y, Width, Height, lng("label caption"));
add(20,50,200,20,lng("Sex"));
add(20,100,80,24,lng("First name"));
add(20,150,80,24,lng("Last name"));
add(20,200,80,24,lng("Birth date"));
add(20,250,80,24,lng("Piture"));
Source 12 -
VP_Tutorial3COO …….
modifications public class VP_Tutorial3COO extends ElfVisualPage implements C_Tutorial3 {
public VP_Tutorial3COO() { … }
setBackgroundImage(so.swing.IconResourcer.getIcon("img/aw2t.gif"),KPan
el. STRETCH);
…..
}
// Label
// syntax: add( X, Y, Width, Height, lng("label caption"));
add(20,50,200,20,lng("Address"));
add(20,150,80,24,lng("Zip code"));
add(20,200,80,24,lng("City"));
add(20,250,80,24,lng("Phone"));
Source 13 -
format declaration Address=X50
in the Address.name=Address
TextFormat.propert
ies file
About formats, when using facets in the SOClass system, four types of facets are
available: text, numeric, date and lookup. However, the lookup format does not
specify a data type, but is a source of layout information.
Although the system makes the predefined formats directly accessible, customised
formats can be defined within properties files.
Using predefined formats consists in using the formats presented in these tables:
Text formats:
Code Description
X<number> This pattern allows upper and lower case letters, numbers and the
next characters: + ~ " * ç % & / ( ) = ? ` ¦ @ # ° § ¬ | ¢ ´ ~ >\ [ ] } { ,
.;:-_ .
UN<number> This pattern allows only upper case letters, numbers and the next
characters: " * Ç & / ( ) # \.
A<number> This pattern allows upper case and lower case letters and next
marks: " * ç & / ( ) # \.
AN<number> This pattern allows upper and lower case letters, numbers and
next characters: " * ç & / ( ) \.
Where <number> represents the upper limit of characters that can be inserted.
Numeric formats:
However, using numeric formats is slightly more complex and requires that a strict
syntax be followed:
12345.67 $###,###.### $12,345.67 The first character in the pattern is the dollar
sign ($). Note that it immediately precedes the
leftmost digit in the formatted output.
12345.67 \u00A5###,###.# ¥12,345.67 The pattern specifies the currency sign for
## Japanese yen (¥) with the Unicode value
00A5.
Symbol Description
0 a digit
# a digit, zero shows as absent
. placeholder for decimal separator
, placeholder for grouping separator
E separates mantissa and exponent for exponential formats
; separates formats
- default negative prefix
% multiply by 100 and show as percentage
? multiply by 1000 and show as per thousand
currency sign; replaced by currency symbol; if doubled,
replaced by international currency symbol; if present in a
pattern, the monetary decimal separator is used instead of the
decimal separator
X any other characters can be used in the prefix or suffix
' used to quote special characters in a prefix or suffix
Date formats:
Characters that are not letters are treated as quoted text. In other words, they will
appear in the formatted text even if they are not enclosed within single quotes.
The number of symbol letters specified also determines the format. For example, if the
"zz" pattern results in "PDT," then the "zzzz" pattern generates "Pacific Daylight
Time." The following table summarizes these rules:
3. Server modification
The modification required on the server concerns the table connector. The only things to do
are defining the connectors between DOM elements and table columns.
Source 14 -
Table connectors package un.asytutorial.tutorial3.server;
declaration in the
TC_Tutorial3 class import un.asytutorial.tutorial3.C_Tutorial3;
import java.sql.Types;
import so.kernel.server.ConnectionManager;
import so.kernel.server.GCFServerBinder;
import so.kernel.server.GCFTableConnector;
import so.kernel.server.ServerBinder;
super(serverBinder,connectionManager,S_Tutorial3.getPERSON_TAB());
serverBinder.setInstanceIdField(this,INSTANCE_ID,INSTANCE_ID);
4. Properties files
In this chapter you will learn
Source 15 -
Un.asytutorial.tutor un.asytutorial.tutorial3.server.S_Tutorial3#TUTORIAL_PERSON_DataBaseURL=$[un.asytut
ial3.properties file orial_URL]
un.asytutorial.tutorial3.server.S_Tutorial3#TUTORIAL_PERSON_DataBaseUser=$[un.asytu
torial_User]
un.asytutorial.tutorial3.server.S_Tutorial3#TUTORIAL_PERSON_DataBasePassword=$[un.
asytutorial_Password]
un.asytutorial.tutorial3.server.S_Tutorial3#TUTORIAL_PERSON_TAB=TUTORIAL3_PERS
ON_TAB
Also add the following line in the un.asytutorial.properties to take into account
the property file created:
Source 16 -
Un.asytutorial.prop @include un.asytutorial.tutorial2.properties
erties @include un.asytutorial.tutorial3.properties
….
Source 17 -
Asyutorial_create.x …….
ml modifications <create>
……
<table name="TUTORIAL3_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>
</create>
Source 18 -
Asytutorial_insert.x <insert>
ml modifications <table name="TUTORIAL2_PERSON_TAB">
</table>
<table name="TUTORIAL3_PERSON_TAB">
</table>
</insert>
Source 19 -
Adding binder and …….
shortcut in the <BU name="BUasytutorial">asytutorial BU</BU>
install_src.xml file ……
<binder name="B_TUTORIAL_3" status="">
<field name="server" value="un.asytutorial.tutorial3.server.S_Tutorial3"/>
<field name="dom" value="un.asytutorial.tutorial3.D_Tutorial3"/>
<field name="client" value="un.asytutorial.tutorial3.client.DC_Tutorial3"/>
<access bu="BUasytutorial">
<full/>
</access>
</binder>
…
<DL>
<folder name="Tutorial" icon="">
……..
<item name="Tutorial 3: Graphic User Interface" icon="">
<field name="binder" value="B_TUTORIAL_3"/>
<field name="skin" value="un.asytutorial.tutorial3.client.VD_Tutorial3"/>
<access bu="BUasytutorial">
<full/>
</access>
</item>
</folder>
</DL>
Now you can compile and deploy your module with Ant tools.