Gwt frameworky GXT + UJORM

  • View
    588

  • Download
    3

Embed Size (px)

Transcript

  • 1. GWT FrameworkyUjorm 1.20 v prosted Ext GWT (Sencha) Google User Groups, Praha 9.6.2011, Autor: Pavel Ponec

2. vodUjorm je "lehko-tonn" framework se silnou typovoukontrolou postavenou na Java , kter nabz(prostednictvm svch modul) sluby: perzitence objekt do relach databz (ORM sluby) integrace s Ext GWT projektu Sencha (dle jen GXT) API + serializace objekt do/z textovch formtUjorm pracuje s objekty implementujc 2 interface:Ujo + Property 3. MotivacePro pout Ujorm ? vet Properties (podoba s Enum + PropertyDescriptor) peklepy odhal kompiltor dostupn meta-data vhodn pro data binding nadstandardn typov kontrola bezpen refactoring zdrojovho kdu snadn tvorba generickch komponent pouvn UjoProperty je zbavn :)spora zdroj: spora asu spora finannch nklad vy produktivita 4. Ujorm pro GXTDva moduly: Ujo-gxt-core nabz klientskou verzi UJO objekt (Cujo) cache Property vlastnost (mandatory, length) podpora pro mapovn klientskch UJO objekt na serverov nstroj pro automatizovanou konverzi klientskch objekt na serverov (domnov objekty, db dotazy) 5. Ujorm pro GXTDva moduly: Ujo-gxt-core nabz klientskou verzi UJO objekt (Cujo) cache Property vlastnost (mandatory, length) podpora pro mapovn klientskch UJO objekt na serverov nstroj pro automatizovanou konverzi klientskch objekt na serverov (domnov objekty, db dotazy) Ujo-gxt-crud grafick komponenty podporujc DB operace: Create Read Update Delete 6. Class model Ujo + PropertyInstance Ujo obsahuje data nabz seznam Properties me splovat specifikaciJavaBeans (ale nemus) 7. Class model Ujo + PropertyInstance Ujo...Instance UjoProperty poskytuje meta-data nzev a typ property defaultn hodnotu defaultn smr azen nabz etzen s jinou UjoProperty a rzn uiten metody vetn metod pro ten a zpis statick nemnn instance(immutable object) 8. GXT: ModelDataModelData je datov model grafickch GXT komponent- jedna instance reprezentuje napklad: jeden dek tabulky 9. GXT: ModelDataModelData je datov model grafickch GXT komponent- pkladem pouit je jeden dek tabulkyUjorm: CujoCujo je klientsk verze rozhran Ujo pro GXTCujo je potomkem ModelData ! 10. Pklad implementace Cujo/UjoUkzka implementace Cujo pomoc abstraktn tdy:public class Employee extends AbstractCujo implements Serializable { /** Property List */ private static final CujoPropertyList pList = list(Employee.class); @Override public CujoPropertyList readProperties() { return pList; } 11. Pklad implementace Cujo/UjoUkzka implementace Cujo pomoc abstraktn tdy:public class Employee extends AbstractCujo implements Serializable { /** Property List */ private static final CujoPropertyList pList = list(Employee.class); /** Unique key */ public static final CujoProperty ID = pList.newProperty("id", Long.class); /** User name */ public static final CujoProperty NAME = pList.newProperty("name", String.class); /** Hourly wage */ public static final CujoProperty WAGE = pList.newPropertyDef("wage", 0.0); /** A reference to Company */ public static final CujoProperty COMPANY = pList.newProperty("company", Company.class); @Override public CujoPropertyList readProperties() { return pList; } 12. Ukzka prce s datyJak zapsat hodnoty ? GXT: ModelDataModelData person = new ModelData();// Write:person.set("ID", 7L);person.set("NAME", "Pavel");person.set("WAGE", 20.00);person.set("COMPANY", new Company()); 13. Ukzka prce s datyJak 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. Ukzka prce s datyJak nast data ? GXT: ModelDataUjorm: Cujoimport 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. Ukzka prce s datyJak nast data ? GXT: ModelDataUjorm: Cujoimport 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. Ukzka prce s datyJak na atributy relanch objekt ? GXT: ModelData Ujorm: Cujoimport 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. Ukzka prce s datyJak na atributy relanch objekt ? GXT: ModelData Ujorm: Cujoimport 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"); // Noperson.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 hodnotyz jednoho objektu do druhho ? 19. Kopie hodnotJak pepsat hodnoty do druhho 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 hodnotJak pepsat hodnoty do druhho 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); 21. Obnova defaultnch hodnotJak obnovit defaultn hodnoty v objektu? 22. Obnova defaultnch hodnotJak obnovit defaultn hodnoty objektu ?ModelData (GXT):ModelData employee = findEmployee();for (String p : employee1.getPropertyNames()){ Object o = employee1.get(p); p.set(p, null); // ??}GWT.log("Employee: " + employee); 23. Obnova defaultnch hodnotJak obnovit defaultn hodnoty objektu ?ModelData (GXT):ModelData employee = findEmployee();for (String p : employee1.getPropertyNames()){ Object o = employee1.get(p); p.set(p, null); // ?? p.set(p, getDefaultForProperty(p));}GWT.log("Employee: " + employee); 24. Obnova defaultnch hodnotJak obnovit defaultn hodnoty objektu ?ModelData (GXT): Cujo (Ujorm):ModelData employee = findEmployee(); Cujo employee = findEmployee();for (String p : employee1.getPropertyNames()) for (CujoProperty p : employee.readProperties()){{ Object o = employee1.get(p); p.set(p, p.getDefault()); p.set(p, null); // ?? p.set(p, getDefaultForProperty(p)); }}GWT.log("Employee: " + employee);GWT.log("Employee: " + employee); 25. CriterionTest platnosti (validace) objektu v run-timeModelData (GXT):Cujo (Ujorm):import static org.ujorm.gxt.client.cquery.COperator.*;CCriterion validWage, validStreet,validator;validWage = CCriterion.where(WAGE, GT, 10.0);validStreet = CCriterion.where(COMPANY.add(CITY), "Prague"); ?validator = validWage.or(validStreet);Employee employee = findEmployee();boolean isValid = validator.evaluate(employee);GXT.log("Is valid: " + isValid + " for " + employee); 26. Mapovn klientskch objektServerov strana: Ujo Klientsk strana: Cujo 27. Criterion v databzovm dotazuJak 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 query = CQuery.newInstance(CEmployee.class, gridColumns);query.setCriterion(CCriterion.where(COMPANY.add(CCompany.CITY), "Prague"));grid = new Grid(createStore(query) query.getColumnModel(); 28. Referenn aplikace Ujorm: eCall ZEI Inspectime (funkn demo: http://inspectime.com) 29. Dotazy ? 30. GWT Frameworky: UjormDkuji 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 Pone