Dienstag, 24. September 2013

Java 9 and GPU?

Donnerstag, 19. September 2013

CDI Callback<TableColumn, TableCell> cellFactory - from FXML

How to get a full managed JavaFX-element declared in the fxml-file?
Let´s say we have something like the following:
This looks like a normal definition of a TableView with some cell-factories. The intressting part is the instantiating of the cellFactory elements. They are created from the JavaFX part. How to get them as full managed bean?
Based on my blog entry about (CDI-JavaFX bootstrapping) I wanted to have full cdi managed JavaFX elements but defined in my fxml-file.
How to get this with a ComboBoxCell you can see here (cdi comboboxcell how to reduce 80 of code)
The aproach was to define an element that is able to associate itself as CellFactory. Only two line of code are used during the init - phase:
BUT: the definition inside the fxml-file is
You only could (implicit)define a normal CellFactory, because the creation of this element would be done by JavaFX.
Now I want to write a more precise fxml file.
Now you could see, the CellFactory is well defined. Here an EditingAutoCompleteStringCellFactory. This is an element with injected autocomplete functions/data.
Inside this class you can use all cdi features.
The missing part is: How to get this as managed instance?
The short answer is.. make it managed by yourself ;-)
Let´s say the controller is a managed instance, you can get the BeanManager with
Now I started to get during the init-phase the right column
After you found the right column, start with the CDI-stuff Ready.. but this code is not nice... and done for every column this is toooooo much code.
So I started to reduce it.
- reducing the generics..
- getting the class from the instance itself
Done.. OK, this is short and easy.. and you can do it for every column..
or more generic...
Now you can use CDI-managed elements as CellFactories and define them inside your fxml.
Nice, Managed and TypeSave

Mittwoch, 11. September 2013

11 lines of code for optimal col size (TableView)

To combine the property tableMenuButtonVisible="true" from the TableView with the column.prefWidthProperty() you need not more than 11 lines of code. The result will be a TableView with automatic resizing columns if you are hiding one ore more columns and reverse.

Dienstag, 10. September 2013

FullText - SearchBox for TableView Part I

How to combine a FullTextSearch with a TableView?
I would say, you will need 30 min max ;-) But How?
Short version :

  • implementing 2 small methods
  • put a SearchBox element to the fxml file
  • combine the TableView with the SearchBox 

Long version:
Let´s start with the correspondings jUnit.

As described (here) we will start with a small demo - jUnit, containing a TableView.
To make the example smaller I will use a default TableView.

The full code and demo jUnit you will find under : BitBucket Repo - RapidPM - Modules - javafx-searchbox 
Please use  a commit after 59237d3

The application based on the SearchBoxDemoPane
with the SearchBoxDemoPaneController.

and the transient data for the TableView TransientDemoDataRow
The importand part is the implementation of the Interface SearchBoxDataElement, this will make the connection between the index and the full-text search later.

Now we will put the SearchBox to the fxml.
This is only one line 
 <SearchBox fx:id="SearchBox" visible="true" minHeight="24.00" prefWidth="1024.0" maxWidth="-Infinity"/>

Finally we are implementing the jUnit Test (more info about cdi javaFX bootstraping)
like this one.

After this we have a full funktional combination between a full-text SearchBox and a TableView.
The SearchBox itself is working in this version with a transient Lucene-Index.

Where to find the cdi-commons and javafx modules ?

Since RapidPM-Modules is available at the central repo (Thanks SonarType), we are using the following repositories.

For development: (no stable builds/ development branch ci )

For Releases and Snapshots from the release-branches/master-branch

Freitag, 6. September 2013

CDI - ComboBoxCell - How to reduce 80% of code

The full code and demo jUnit you will find under : BitBucket Repo - RapidPM - Modules - javafx-filtered-tableview 
Please use the develop branch and a commit after aec4f95 

Today I had a TableView with the following function.
- In one column there was a ComboBoxCell.
- The values of this ComboBox was calculated / loaded at the moment the combobox was used.
- Each ComboBox will have different values based on the context of this row.

The first version was something like this:
A ComboBoxCell:
and the code called from the controller:

This is to much boilerplate code. So I started to reduce it.

First step was reducing the generics..
This is shorter, but not better... 

The solution is the abstract GenericComboBoxCell. (part of the javafx-filtered-tableview module)

Iterating over the columns are now part of the GenericComboBoxCell, and here will be the typesave code.

The developer must extend this class and has to implement the following methods only:
- protected abstract GenericComboBoxCell getComboBoxCellRef(); 
- public abstract boolean disableComboBox(final RT row); (optional) 
- public abstract List createComboBoxValues(final RT row); 
- public abstract void workOnRowItself(final RT row); (optional) 

A demo implementation is shown here: 

The controlle will need a piece of code like this: 

With this you can test the context logic indepentend from the javafx stuff. 
All initializations inside a ComboBoxCell must be done in a PostConstruct - method. 

With the GenericComboBoxCell you can activate/deactivate the combobox, modify the row cell values, and create the combobox values. 

This implementation is based on the JavaFX/CDI bootstrap from cdi-commons-fx. (blog entry JavaFX/CDI bootstrap )

UML of this demo:

Full CDI dependicies

Dienstag, 3. September 2013

MultiLevel DrillDownPieChart in less then 30min as component for TableViews

The full code and demo jUnit you will find under : BitBucket Repo - RapidPM - Modules - javafx-chart-pie-drilldown 
Please use the develop branch and a commit after 265b5f5 

Sometimes you want to have a drill down pi chart for a tableview. This code often looks like the following
(example from the oracle side)

What you can see, is the direct way of putting the data together for each drilldown-level.
But if you want to drill down more than one level.. the code will be long.
For this example I am using the following demo data table.

What I want to reach is a short way for a developer to aggregate from one row to an other (in both directions)
Here the pie–chart for this demo data and clicking the following steps:
Rows: Vorname->Nachname->Datum->Betrag
Data: Holger->Hoppel->2013.10.01->122.0
You can see, that for each level you will get the aggregated data from the table..  But how to do it?
The basic is the Aggregator-Class

With this you can aggregate a collection to a map. The key is the aggregated value from the collection elements.
For this example: A Collection of the TransientDemoDataRow (Collection) aggregated over the attribute vorname.
With our demo data table you will get a map with two collections.
a) Holger –> List of 6 elements
b) Willi –> List of 4 elements
This is the data for the first level of the DrillDownPieChart. (first pic of the pie charts see above)
For our DrillDownPieChart we are using the following aggregator extending the MapAggregator.

We are holding the reference to the next level aggregator and the reference to the parent aggregator.
To implement the aggregator for each col. we want to use for our DrillDownPieChart we have to write code like the following

The method getLevelName is to label the PieChart for the user.
The method getKeyElement is the value used for the aggregation.
The method aggregateValue is to calculate the double, used by the pie chart as value.
After this you have to put all together… the logic-part is done now..
The gui part looks like this: Extending the DrillDownPieChart with the type you need as data holder, here the TransientDemoDataRow.
and putting it to a fxml file.

The steps for a developer are:
1) writing the transient data holder for an row –> TransientDemoDataRow
2) extending the DrillDownPieChart –> DemoDrillDownPieChart extends
3) extending the DrillDownPieChartMapAggregator –> NachnameAggregator extends DrillDownPieChartMapAggregator
4) putting all aggregator implementations together –> Controller – Class
5) add the element to the fxml file,
6) init() and ready
For a normal TableView with a handfull of rows you will need less than 30 min.

The basic classes to use for an developer:

All classes from the jUnit demo available at the javafx-chart-pie-drilldown module.

Introducing Vaadin: Validation

Let's talk about validation in Vaadin.


We want to have a textfield which is marked as a "required" field and which expects integer values from 0 - 99. The user should get feedback right after he entered something into the field.


Here's the complete code of the module:

public class MyVaadinUI extends UI
    protected void init(VaadinRequest request) {
        final TextField textField = new TextField("Enter an Integer value (0-99)");
        final FormLayout mainLayout = new FormLayout(textField);
        textField.addValidator(new IntegerRangeValidator("only integer, 0-99", 0, 99));
1 Class
7 Lines of active code
4 lines of code configuring the TextField (!)


A red asterisk marks the field as required. After the user entered something into the field and the focus on the field is lost there is immediate feedback for the user.

Does it look pretty? meh..
Does it work at a minimum of spent work and time? 4 lines of code?! Yea!