Download - ZoeFX: un framework MVC per JavaFX
![Page 1: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/1.jpg)
29 ottobre 2014
ZoeFX: un framework MVC per JavaFXdi Tiziano Lattisi
![Page 2: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/2.jpg)
indice
✤ ripasso rapido JavaFX (vecchie slide)
✤ come JavaFX intende il pattern MVC
✤ esempio pratico
✤ come ZFX implementa il pattern MVC
✤ esempio pratico
✤ discussione (spero)
![Page 3: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/3.jpg)
scorriamo le “vecchie”slide
http://www.slideshare.net/lattisi/javafx2-una-panoramica
![Page 4: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/4.jpg)
ultimo capitolo della storia
✤ JavaFX8: integrato in Java8, Oracle lo indica come successore di Swing
✤ Nuove caratteristiche:
✤ grafica 3D
✤ supporto sensori
✤ sistema di stampa
✤ tema Modena
✤ DatePicker e TreeTable
✤ Supporto: Windows, Linux, OS X, ma anche iOS e Android (port in sviluppo da Oracle, ma anche http://javafxports.org), ARM, Raspberry Pi…
![Page 5: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/5.jpg)
MVC
✤ un pattern per disaccoppiare la vista dal modello
✤ model: permette l’accesso ai dati
✤ view: visualizza i dati esposti dal model
✤ controller: reagisce ai comandi dell’utente, e cambia gli stati di model e view
M
V
C
eventimetodi
![Page 6: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/6.jpg)
view
il file fxml prodotto con Scene Builder:
✤ indicata la classe controller
✤ definite le proprietà fx:id per i nodi che conterranno dati
✤ definiti i nomi per gli handle alle azioni sui nodi
![Page 7: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/7.jpg)
model
un FXBeanModel:
✤ i campi sono incapsulati in Property
✤ getter e setter
✤ getter aggiuntivo per il Property
public class BeanModel {
StringProperty caption = new SimpleStringProperty(this, "caption", "");
public String getCaption() { return caption.get(); }
public void setCaption(String caption) { this.caption.set(caption); }
public StringProperty captionProperty() { return caption; }
}
![Page 8: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/8.jpg)
controller
una classe che (opzionalmente) implementa Initializable:
✤ nodi iniettati con @FXML
✤ metodi azione con il nome definito in view
public class Controller implements Initializable{
@FXML private TextField myField;
@FXML private Label myLabel;
@FXML private Button myButton;
@Override public void initialize(URL l, ResourceBundle r) {
}
}
![Page 9: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/9.jpg)
ed infine arriva ZFX
![Page 10: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/10.jpg)
dive in
// il codice Database db = new NoPersistenceDatabaseImpl(); Utilities.registerUtility(db, Database.class);
Manager<Book> manager = db.createManager(Book.class);
manager.commit(new Book("Anna Karerina", "A long book...")); manager.commit(new Book("War and peace", "Another long book..."));
primaryStage.setScene(ZSceneBuilder .create(Book.class) .url(getClass().getResource(“book.fxml")) .manager(manager) .build().getScene());
primaryStage.show();
// la classe entità public class Book {
public String title; public String description;
public Book(String title, String description) { this.title = title; this.description = description; } }
// la view book.fxml (da Scene Builder) <AnchorPane> <children> <Label text="Title" /> <Label text="Description" /> <TextField fx:id="title" /> <TextArea fx:id="description" /> </children> </AnchorPane>
![Page 11: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/11.jpg)
dive in
// il codice Database db = new NoPersistenceDatabaseImpl(); Utilities.registerUtility(db, Database.class);
Manager<Book> manager = db.createManager(Book.class);
manager.commit(new Book("Anna Karerina", "A long book...")); manager.commit(new Book("War and peace", "Another long book..."));
primaryStage.setScene(ZSceneBuilder .create(Book.class) .url(getClass().getResource(“book.fxml")) .manager(manager) .build().getScene());
primaryStage.show();
// la classe entità public class Book {
public String title; public String description;
public Book(String title, String description) { this.title = title; this.description = description; } }
// la view book.fxml (da Scene Builder) <AnchorPane> <children> <Label text="Title" /> <Label text="Description" /> <TextField fx:id="title" /> <TextArea fx:id="description" /> </children> </AnchorPane>
![Page 12: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/12.jpg)
architettura
BeanAccess<E>
Persistence
Model
Controller
Manager<E>
Database
DataSet<E>
FXML UI file
BeanClassAccess
ZoeFXProperty<P> (ItemStringProperty, ItemBooleanProperty, etc)
view {controller {
model {
![Page 13: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/13.jpg)
jpa (zoefx-persistence)
✤ interfacce Database e Manager per l’accesso al data layer implementate con JPA2
✤ l’implementazione utilizzata deve essere registrata
Database db = new JPADatabaseImpl(); db.open("Library"); Utilities.registerUtility(db, Database.class);
Manager<Book> manager = db.createManager(Book.class);
ZScene zscene = ZSceneBuilder.create(Book.class) .url(getClass().getResource("book.fxml")) .manager(manager) .build();
![Page 14: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/14.jpg)
properties
✤ attraverso un file properties si possono definire caratteristiche di comportamento di una scena
✤ le properties devono essere dichiarate nel builder
# book.properties title=My book’s shelf searchcolumns=title searchcriteria=title,description author.lookup=surname
ZScene zscene = ZSceneBuilder.create(Book.class) .url(getClass().getResource("book.fxml")) .properties(getClass().getResource("book.properties")) .manager(manager) .build();
![Page 15: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/15.jpg)
many-to-one
✤ una campo di relazione con l’entità (Author author;)
✤ una ChoiceBox sulla scena, con fx:id uguale al campo nell’entità
✤ indicazione di lookup nel file proferite (alternativamente viene usato il toString)
<ChoiceBox fx:id=“author” />
author.lookup=surname
![Page 16: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/16.jpg)
one-to-many
✤ un campo Collection sull’entità (Collection<Book> books;)
✤ un TableView con TableColumn (e relativi fx:id)
✤ anche nelle colonne vale il lookup
<TableView fx:id="books"> <columns> <TableColumn fx:id="title"/> <TableColumn fx:id="description"/> </columns> </TableView>
![Page 17: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/17.jpg)
SceneBuilders
✤ meccanismo per registrare i builder di scene
✤ quando serve visualizzare un entità, si utilizza uno SceneBuilder
SceneBuilders.registerSceneBuilder(Book.class, SceneBuilder.create(Book.class) .url(getClass().getResource("book.fxml")) .properties(getClass().getResource("book.properties")) .manager(bookManager));
![Page 18: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/18.jpg)
Skins
✤ una skin è un package con un css e delle risorse
✤ gli skin sono registrati nell’utilità Skins
Skins.registerSkin(new FamFamFam());
![Page 19: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/19.jpg)
Validators
✤ i validatori sono per entità o per campo
✤ possono contenere codice (JS o Groovy, o…)
✤ sono registrati in Validators
Validators.bindValidator(Book.class, "description", ValidatorBuilder.create() .minLength(12) .code("return value.charAt(0)==value.charAt(0).toUpperCase();”) .build());
![Page 20: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/20.jpg)
Groovy engine (zoefx-groovy)
✤ implementazione alternativa di ScriptEngine
✤ utilizzabile anche in zoefx-console
Utilities.registerUtility(new GroovyEngineImpl(), ScriptEngine.class);
Validators.bindValidator(Book.class, "description", ValidatorBuilder.create() .minLength(12) //.code("return value.charAt(0)==value.charAt(0).toUpperCase();") .code("value[0]==value[0].toUpperCase()") .build());
![Page 21: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/21.jpg)
reports (zoefx-jasperreports)
✤ implementazione delle interfacce ReportEngine e ReportTemplate
✤ template JasperReport (es. da iReport) registrati in Reports
✤ esportazione pdf e stampa
Utilities.registerUtility(new JRReportEngine(), ReportEngine.class);
Reports.addReportTemplate(Book.class, new JRReportTemplate(getClass().getResource("report.jrxml"), "Library report"));
![Page 22: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/22.jpg)
application (zoefx-application)
✤ è un top level container per scene
✤ menù ad albero multi livello
✤ supporto skin
![Page 23: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/23.jpg)
componenti
zoefx-core
zoefx-persistence
zoefx-jasperreports
zoefx-alfresco
zoefx-ooops
zoefx-groovy
zoefx-restful
zoefx-js?
zoefx-application
![Page 24: ZoeFX: un framework MVC per JavaFX](https://reader033.vdocuments.pub/reader033/viewer/2022052508/5599e3db1a28ab2f668b4658/html5/thumbnails/24.jpg)
Grazie a tutti!
–Tiziano Lattisi
ZoeFX Application Framework Open Source
licenza: GPL
uscita: presto…
informazioni: [email protected]