lunes, 15 de mayo de 2017

FXTableViewUtil: An utility class for JavaFX to create columns easily in a TableView

I had to move a desktop application in VB6 because the customer needed to run their app in Windows, Mac and Linux so, we decided to use Java with JavaFX. SceneBuilder help me a lot to build user interfaces. Most of the screens are only tho show information in a TableView component.

Usually to create columns in a TableView you have to code something like this:

    private TableView table;

    public static void main(String[] args) {

    public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        stage.setTitle("Table View Sample");

        final Label label = new Label("Address Book");
        label.setFont(new Font("Arial", 20));


        // Create Columns
        TableColumn firstNameCol = new TableColumn("First Name");
        firstNameCol.setCellValueFactory(new PropertyValueFactory<>("firstName"));

        TableColumn lastNameCol = new TableColumn("Last Name");
        lastNameCol.setCellValueFactory(new PropertyValueFactory<>("lastName"));

        TableColumn emailCol = new TableColumn("Email");
        emailCol.setCellValueFactory(new PropertyValueFactory<>("email"));

        // add columns to TableView
        table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);

As you can see you have to write several lines of code to add columns.

I wrote an utility class to create columns easly in a TableView, so now you only need to write something like this:

    public void initialize(URL url, ResourceBundle rb) {
        tableViewUtil.createColumns(Person.class, tableView, headers, personList);

FXTableViewUtil has this methods


Creates columns at runtime, you only need to add a TableView with no columns in your FXML file and pass the POJO class to be used and the object list to populate the TableView.  Columns added have a default width.

Check that this screen has a TableView without columns

TableView with no columns
Once you call method createColumns columns are added to TableView (using same with for all columns)
TableView after call createColumns method


Use this method if you already designed you TableView with columns. The important this to use this method is to assign the property name to Id in FXML file.

This screen already have TableColumns with custom with for each column (and different order)

TableView with columns at design time

Once you call method assignColumns FXTableViewUtil uses current design and assign the data to corresponding columns
TableView with data after call assignColumns

You can download project from Github at

viernes, 14 de abril de 2017

Generating a script for FirebirdSQL from MySQLWorkbench

 MySQLWorkbench allows to design database model easily and also provides an option to generate the SQL script.   By default script is generated for MySQL, but, what if you need to generate a SQL script for FirebirdSQL?.

Using Python you cand create custom plugins to access to model properties  (table and columns definitions for example) please visit this link for more info Scripting and Plugin Development

So, I decided to write a plugin to generate a SQL Script for FirebirdSQL. My goal it's just to show how can we access to schemas, tables and columns properties using classes already defined by MySQLWorkbench.

Script can be downloaded from github:

Once script is downloaded do following:

1. Go to menu: Script / Install Plugin Module...
2. In Select Module to Install select and clic on Open
 3. Clic on OK button on Plugin Installed dialog and Restart MySQL
4. Open your model and go to menu Tools / Catalog / Database schema to Firebird Script
5. Provide an filename for the script in the Save Dialog and clic Save Button
6. Once script was generated clic OK button on following dialog

That's all, I hope this can help you to generate Firebird scripts and to write your own plugins.

miércoles, 13 de mayo de 2015

Using @GeneratedValue with Firebird and JPA (EclipseLink)

If you need to manage generated values in a Java application that uses JPA (Java Persistence API) and FirebirdSQL as database you can use @GeneratedValue annotation according to EclipseLink.

All you need to do is follow these steps:

1. Create your FIREBIRD generator

-- create your generator

If you are using FirebirdSQL 2.0 you can use CREATE SEQUENCE

-- For Firebird 2.x

2.Use @SequenceGenerator and   @GeneratedValue in your Entity class

  • Specify a name for your Sequence
     @SequenceGenerator( name = "YOUR_SEQUENCE_NAME", sequenceName = "YOUR_GENERATOR", allocationSize = 1 )
  • Use GeneratedValue and assign previous name to generator property
 @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "YOUR_SEQUENCE_NAME" )   
For example to use Firebird generator defined in Step 1 use this lines:

    @SequenceGenerator( name = "ORDER_SEQUENCE", sequenceName = "GEN_ORDER", allocationSize = 1 ) 
    @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "ORDER_SEQUENCE" )     

Finally your java class looks like this:

I hope this can help you.

jueves, 26 de marzo de 2015

HTML Report from MySQLWorkbench 6.x Schema Model

This begun in 2010 when I started to create a Lua script to generate an HTML report from MySQLWorkbench 5.x (

Lua support has been removed from MySQLWorkbench and now we can use Python to generate plugins.

I updated the script to use phyton. Script is available here for download.
To Install the plugin go to Scripting / Install Plugin/Module then select file and restart MySQL Workbench

Open your model and go to Tools / Catalog and select "Database schema in HTML format" and provide a file name in save dialog.

Once document has been generated you will see following message:

Then open your HTML document and see the report:

Finally I want to thank all readers for their contributions, specially to Rodrigo Schmidt who started script python.

viernes, 15 de noviembre de 2013

Reporte actualizado del modelo de la base de datos en MYSQL Workbench

Ha pasado algo de tiempo desde el último post.

Era el mes de Julio de 2010 cuando compartí con ustedes como generar un  Reporte en HTML de un modelo en MySQLWorkBench 5.2.25  utilizando un script LUA en MySQLWorkbench.

A partir de esa publicación, varias personas han contribuido forma valiosa para mejorar el script.

En esta ocasión agradezco a Paco Mora las mejoras que le ha hecho y pongo a la disposición de  ustedes el código que él me ha enviado.

De nueva cuenta reitero mi agradecimiento a todos los que han contribuido para mejorar éste script.

No se diga más, he aquí el código:

--[[Guardamos el esquema de la base de datos en la variable schema]] local schemata= grtV.getGlobal("/wb/doc/physicalModels/0/catalog/schemata/tables") local i--Varible para iterar el esquema. local j--Variable para iterar las tablas base de datos local k--Variable para iterar los campos de las tablas. print("<!DOCTYPE html>\n" ) print("<html>\n" ) print("<head>\n" ) print("<style>\n" ) print(" #customers\n" ) print(" {\n" ) print(" font-family:'Trebuchet MS', Arial, Helvetica, sans-serif;\n" ) print(" width:100%;\n" ) print(" border-collapse:collapse;\n" ) print(" }\n" ) print(" #customers td, #customers th \n" ) print(" {\n" ) print(" font-size:1em;\n" ) print(" border:1px solid #98bf21;\n" ) print(" padding:3px 7px 2px 7px;\n" ) print(" }\n" ) print(" #customers th \n" ) print(" {\n" ) print(" font-size:1.1em;\n" ) print(" text-align:left;\n" ) print(" padding-top:5px;\n" ) print(" padding-bottom:4px;\n" ) print(" background-color:#A7C942;\n" ) print(" color:#ffffff;\n" ) print(" }\n" ) print(" #customers tr.alt td \n" ) print(" {\n" ) print(" color:#000000;\n" ) print(" background-color:#EAF2D3;\n" ) print(" }\n" ) print(" </style>\n" ) print("\n" ) print("</head>" ) print("<body>" ) print("<table border='1' style='width:100%'> \n" ) for i=1, grtV.getn(schemata) do print("<tr id='customers'> \n" ) print("<td colspan='5'> NOMBRE DE LA BASE DE DATOS: " .. schemata[i].name .. "</td> \n") print("</tr> \n" ) print("<tr> \n" ) print("<td colspan='5'> </td> \n") print("</tr> \n" ) print("<tr> \n" ) print("<td colspan='5'>Tablas de la base de datos</td> \n") print("</tr> \n" ) for j=1, grtV.getn(schemata[i].tables) do print("<tr> \n" ) print("<td colspan='5'> <A href='#" .. schemata[i].tables[j].name .. "'>" .. schemata[i].tables[j].name .. "</A></td> \n") print("</tr> \n" ) end print("<tr> \n" ) print("<td colspan='5'>&nbsp;</td> \n") print("</tr> \n" ) print("<tr> \n" ) print("<td>COLUMN_NAME</td> \n") print("<td>TYPE</td> \n") print("<td>NULLABLE?</td> \n") print("<td>AUTO_INCREMENT?</td> \n") print("<td>COMMENTS</td> \n") print("</tr> \n" ) --Recorremos las tablas de la base de datos for j=1, grtV.getn(schemata[i].tables) do print("<tr> \n" ) print("<td colspan='5'>&nbsp;</td> \n") print("</tr> \n" ) print("<tr> \n" ) print ( " <td ><A name='" .. schemata[i].tables[j].name .. "'>" .. schemata[i].tables[j].name .. "</A></td> \n" )--Obtenemos el nombre de la tabla. print ( " <td colspan='4'>" .. schemata[i].tables[j].comment .. "/td> \n" )--Obtenemos el nombre de la tabla. print("</tr> \n" ) for k=1, grtV.getn(schemata[i].tables[j].columns) do print("<tr> \n" ) print ( " <td>" .. schemata[i].tables[j].columns[k].name .. "</td> \n" ) print ( " <td>" .. schemata[i].tables[j].columns[k].formattedType .. "</td> \n" ) if (schemata[i].tables[j].columns[k].isNotNull == 1) then print (" <td>" .. "NOT NULL" .. "</td> \n" ) else print ( " <td>" .. "NULL" .. "</td> \n" ) end if (schemata[i].tables[j].columns[k].autoIncrement == 1) then print (" <td>" .. "AUTO_INCREMENT" .. "</td> \n" ) else print (" <td>" .. " - " .. "</td> \n" ) end print ( " <td>" .. schemata[i].tables[j].columns[k].comment .. "</td> \n" ) print("</tr> \n" ) end end end print("</table> " ) print(" </body>" ) print("</html>" ) print ( "\n" )

viernes, 10 de febrero de 2012

IceFaces copia código de PrimeFaces línea por línea

Hace tiempo cuanto tuve que desarrollar sistemas en Web con Java estuve buscando un framework que soportara Ajax de forma transparente y encontré el framework ICEFaces el cual desde mi punto de vista es bueno.

Tiempo después encontré el excelente framework PrimeFaces cuya característica principal es que soportaba JSF 2.0. Este framework tiene excelentes componentes que permiten generar aplicaciones Web que mejoran la experiencia del usuario, si no me creen, denle un vistazo a los demos: y estoy seguro de que les va a gustar.

Leyendo el blog de PrimeFaces me encuentro noticia de que "IceFaces Copies PrimeFaces LineByLine", ---aclaro que desde el punto de vista legal, no es delito ya que primeFaces es open source---, lo que destacan en blog de primefaces es que no son tan "claros" dando el crédito a quien en verdad lo merece.

We have looked in detail of all IceFaces Ace Components and more than 90% of IceFaces components are like Panel. They are copied line by line, only difference is the change of package names from prime to ice. This duplication applies to java renderers, components codes, javascripts and css files as well.

Ustedes que opinan?

martes, 23 de agosto de 2011

Criteria: Combinando AND y OR en Hibernate

Seguramente en tus sistemas te has encontrado que tienes que hacer consultas con Hibernate que impliquen tener fija una condición y agregar varios criterios OR.

Vamos a suponer que tenemos una tabla con los siguientes campos

Producto(idProducto, nombreProducto, idProveedor, precio, categoria)

Y necesitas obtener los productos del proveedor "PR001" Y que el nombreProducto contenga "Computadora" O que el precio sea mayor a 1000 O que la categoria sea "PC", para lograrlo puedes hacer lo siguiente:

// creamos el criterio
Criteria criteria = session.createCriteria(Producto.class);

// Primero creamos el criterio fijo
Criterion critIdProveeodr = Restrictions.eq("idProveedor", "PR001");

// luego preparamos los OR
Disjunction disjunctionOrs = Restrictions.disjunction();

// y agregamos cada uno

// creamos la combinación AND y OR
criteria.add( Restrictions.and(cridIdProveedor,disjunctionOrs));

// y por último los listamos

Espero les sea de utilidad