1. GWT Frameworky
Ujorm 1.20 v prosted鱈 Ext GWT
(Sencha)
Google User Groups, Praha 9.6.2011, Autor: Pavel Ponec
2. vod
Ujorm je "lehko-ton叩転n鱈" framework se silnou typovou
kontrolou postavenou na Java <generik叩ch>, kter箪 nab鱈z鱈
(prostednictv鱈m sv箪ch modul哲) slu転by:
perzitence objekt哲 do rela鱈ch datab叩z鱈 (ORM slu転by)
integrace s Ext GWT projektu Sencha (d叩le jen GXT)
API + serializace objekt哲 do/z textov箪ch form叩t哲
Ujorm pracuje s objekty implementuj鱈c鱈 2 interface:
Ujo + Property
3. Motivace
Pro pou転鱈t Ujorm ?
v箪et Properties (podoba s Enum + PropertyDescriptor)
peklepy odhal鱈 kompil叩tor
dostupn叩 meta-data
vhodn辿 pro data binding
nadstandardn鱈 typov叩 kontrola
bezpen箪 refactoring zdrojov辿ho k坦du
snadn叩 tvorba generick箪ch komponent
pou転鱈v叩n鱈 UjoProperty je z叩bavn辿 :)
spora zdroj哲:
炭spora asu
炭spora finann鱈ch n叩klad哲
vy邸邸鱈 produktivita
4. Ujorm pro GXT
Dva moduly:
Ujo-gxt-core
nabz鱈 klientskou verzi UJO objekt哲 (Cujo)
cache Property vlastnost鱈 (mandatory, length)
podpora pro mapov叩n鱈 klientsk箪ch UJO objekt哲 na serverov辿
n叩stroj pro automatizovanou konverzi klientsk箪ch objekt哲
na serverov辿 (dom辿nov辿 objekty, db dotazy)
5. Ujorm pro GXT
Dva moduly:
Ujo-gxt-core
nabz鱈 klientskou verzi UJO objekt哲 (Cujo)
cache Property vlastnost鱈 (mandatory, length)
podpora pro mapov叩n鱈 klientsk箪ch UJO objekt哲 na serverov辿
n叩stroj pro automatizovanou konverzi klientsk箪ch objekt哲
na serverov辿 (dom辿nov辿 objekty, db dotazy)
Ujo-gxt-crud
grafick辿 komponenty podporuj鱈c鱈 DB operace:
Create
Read
Update
Delete
6. Class model Ujo + Property
Instance Ujo
obsahuje data
nab鱈z鱈 seznam Properties
m哲転e splovat specifikaci
JavaBeans (ale nemus鱈)
7. Class model Ujo + Property
Instance Ujo
...
Instance UjoProperty
poskytuje meta-data
n叩zev a
typ property
defaultn鱈 hodnotu
defaultn鱈 smr azen鱈
nab鱈z鱈 etzen鱈 s jinou UjoProperty
a r哲zn辿 u転iten辿 metody
vetn metod pro ten鱈 a z叩pis
statick叩 nemnn叩 instance
(immutable object)
8. GXT: ModelData
ModelData je datov箪 model grafick箪ch GXT komponent
- jedna instance reprezentuje nap鱈klad: jeden 叩dek tabulky
9. GXT: ModelData
ModelData je datov箪 model grafick箪ch GXT komponent
- p鱈kladem pou転it鱈 je jeden 叩dek tabulky
Ujorm: Cujo
Cujo je klientsk叩 verze rozhran鱈 Ujo pro GXT
Cujo je potomkem ModelData !
10. P鱈klad implementace Cujo/Ujo
Uk叩zka implementace Cujo pomoc鱈 abstraktn鱈 t鱈dy:
public class Employee extends AbstractCujo implements Serializable {
/** Property List */
private static final CujoPropertyList pList = list(Employee.class);
@Override public CujoPropertyList readProperties() {
return pList;
}
11. P鱈klad implementace Cujo/Ujo
Uk叩zka implementace Cujo pomoc鱈 abstraktn鱈 t鱈dy:
public class Employee extends AbstractCujo implements Serializable {
/** Property List */
private static final CujoPropertyList pList = list(Employee.class);
/** Unique key */
public static final CujoProperty<Employee, Long> ID = pList.newProperty("id", Long.class);
/** User name */
public static final CujoProperty<Employee, String> NAME
= pList.newProperty("name", String.class);
/** Hourly wage */
public static final CujoProperty<Employee, Double> WAGE = pList.newPropertyDef("wage", 0.0);
/** A reference to Company */
public static final CujoProperty<Employee, Company> COMPANY
= pList.newProperty("company", Company.class);
@Override public CujoPropertyList readProperties() {
return pList;
}
12. Uk叩zka pr叩ce s daty
Jak zapsat hodnoty ?
GXT: ModelData
ModelData person = new ModelData();
// Write:
person.set("ID", 7L);
person.set("NAME", "Pavel");
person.set("WAGE", 20.00);
person.set("COMPANY", new Company());
13. Uk叩zka pr叩ce s daty
Jak zapsat hodnoty ?
GXT: ModelData Ujorm: Cujo
import static Employee.*
import static Company.CITY;
ModelData person = new ModelData(); Employee person = new Employee();
// Write: // Write:
person.set("ID", 7L); person.set(ID, 7L);
person.set("NAME", "Pavel"); person.set(NAME, "Pavel");
person.set("WAGE", 20.00); person.set(WAGE, 20.00);
person.set("COMPANY", new Company()); person.set(COMPANY, new Company());
14. Uk叩zka pr叩ce s daty
Jak na鱈st data ?
GXT: ModelData Ujorm: Cujo
import static Employee.*
import static Company.CITY;
ModelData person = new ModelData(); Employee person = new Employee();
// Write: // Write:
person.set("ID", 7L); person.set(ID, 7L);
person.set("NAME", "Pavel"); person.set(NAME, "Pavel");
person.set("WAGE", 20.00); person.set(WAGE, 20.00);
person.set("COMPANY", new Company()); person.set(COMPANY, new Company());
// Read:
Ujorm:
Long id = person.get("ID");
String name = person.get("NAME");
double wage = person.get("WAGE");
Company address = person.get("COMPANY");
15. Uk叩zka pr叩ce s daty
Jak na鱈st data ?
GXT: ModelData Ujorm: Cujo
import static Employee.*
import static Company.CITY;
ModelData person = new ModelData(); Employee person = new Employee();
// Write: // Write:
person.set("ID", 7L); person.set(ID, 7L);
person.set("NAME", "Pavel"); person.set(NAME, "Pavel");
person.set("WAGE", 20.00); person.set(WAGE, 20.00);
person.set("COMPANY", new Company()); person.set(COMPANY, new Company());
// Read: // Read:
Long id = person.get("ID"); Long id = person.get(ID);
String name = person.get("NAME"); String name = person.get(NAME);
double wage = person.get("WAGE"); double wage = person.get(WAGE);
Company address = person.get("COMPANY"); Company address = person.get(COMPANY);
16. Uk叩zka pr叩ce s daty
Jak na atributy relan鱈ch objekt哲 ?
GXT: ModelData Ujorm: Cujo
import static Employee.*
import static Company.CITY;
ModelData person = new ModelData(); Employee person = new Employee();
// Write: // Write:
person.set("ID", 7L); person.set(ID, 7L);
person.set("NAME", "Pavel"); person.set(NAME, "Pavel");
person.set("WAGE", 20.00); person.set(WAGE, 20.00);
person.set("COMPANY", new Company()); person.set(COMPANY, new Company());
person.set("COMPANY.CITY", "Prague"); // No
// Read: // Read:
Long id = person.get("ID"); Long id = person.get(ID);
String name = person.get("NAME"); String name = person.get(NAME);
double wage = person.get("WAGE"); double wage = person.get(WAGE);
Company address = person.get("COMPANY"); Company address = person.get(COMPANY);
String cn = person.get("COMPANY.CITY"); // No
17. Uk叩zka pr叩ce s daty
Jak na atributy relan鱈ch objekt哲 ?
GXT: ModelData Ujorm: Cujo
import static Employee.*
import static Company.CITY;
ModelData person = new ModelData(); Employee person = new Employee();
// Write: // Write:
person.set("ID", 7L); person.set(ID, 7L);
person.set("NAME", "Pavel"); person.set(NAME, "Pavel");
person.set("WAGE", 20.00); person.set(WAGE, 20.00);
person.set("COMPANY", new Company()); person.set(COMPANY, new Company());
person.set("COMPANY.CITY", "Prague"); // No person.set(COMPANY.add(CITY), "Prague";
// Read: // Read:
Long id = person.get("ID"); Long id = person.get(ID);
String name = person.get("NAME"); String name = person.get(NAME);
double wage = person.get("WAGE"); double wage = person.get(WAGE);
Company address = person.get("COMPANY"); Company address = person.get(COMPANY);
String cn = person.get("COMPANY.CITY"); // No String cn = person.get(COMPANY.add(CITY);
18. Kopie hodnot
Jak pepsat hodnoty
z jednoho objektu do druh辿ho
?
19. Kopie hodnot
Jak pepsat hodnoty do druh辿ho objektu ?
ModelData (GXT):
ModelData emplA = findEmployee();
ModelData emplB = new ModelData();
for (String p : emplA.getPropertyNames())
{
Object o = emplA.get(p);
emplB.set(p, o);
}
GWT.log("Employee B: " + emplB);
20. Kopie hodnot
Jak pepsat hodnoty do druh辿ho objektu ?
ModelData (GXT): Cujo (Ujorm):
ModelData emplA = findEmployee(); Cujo emplA= findEmployee();
ModelData emplB = new ModelData(); Cujo emplB= employee1.createInstance();
for (String p : emplA.getPropertyNames()) for (CujoProperty p : emplA.readProperties())
{ {
Object o = emplA.get(p); p.copy(emplA, emplB);
emplB.set(p, o); }
}
GWT.log("Employee B: " + emplB); GWT.log("Employee B: " + emplB);
27. Criterion v datab叩zov辿m dotazu
Jak sestavit DB dotaz pro GRID na stran klienta ?
import static CEmployee.*;
CujoProperty[] gridColumns = new CujoProperty[]
{ NAME
, WAGE
, COMPANY.add(CCompany.NAME)
, COMPANY.add(CCompany.CITY)
};
CQuery<CEmployee> query = CQuery.newInstance(CEmployee.class, gridColumns);
query.setCriterion(CCriterion.where(COMPANY.add(CCompany.CITY), "Prague"));
grid = new Grid<CUJO>(createStore(query) query.getColumnModel();
30. GWT Frameworky: Ujorm
Dkuji za pozornost
Odkazy:
Ujorm: http://ujorm.org
Ext GWT: http://www.sencha.com/products/extgwt/
Referenn鱈 demo aplikace: http://inspectime.com
Tato prezentace: http://ujorm.org/gxt
Download: http://sourceforge.net/projects/ujoframework/
Maven repository: groupId=org.ujoframework,artifactId:ujo-*
Google User Groups, Praha 9.6.2011, Autor: Pavel Ponec