A user that is editing an expression for a report, with language set to Groovy or Java, can see this interface:
A navigator tree (on the left) was already available and also features like "User Defined Expressions" and "Recent Expressions". What is really new is the concept of "Built-in Functions". Something that we introduced only in Jaspersoft Studio in order to help the final users to write their expression in a simple and quicker way in respect to what they were used to do in the past.
The new main feature in the Expression Editor is the support for the so-called "Built-in Functions". The basic idea behind this implementation is that Java (and also Groovy) is powerful enough to mimic Excel-like expressions. We decided to produce a library of simple functions like Microsoft Excel and OpenOffice do. This way, the user feels writing an expression in JSS is similar to what he/she would do in one of these programs, plus it's more easy to make calculations that would otherwise be hard to write in a single expression (i.e date range calculation). On the UI side, the user will be able to create an expression without actually writing it, simply using a "point-and-click" approach. In fact, a convenient UI, similar to the OpenOffice one, will allow the user to write an entire expression just using basic functions and the functions forms. This is the typical UI that is shown when a user decide to use an expression function.
The main parts that make up the editor dialog are the followings:
In order to provide features like syntax highlighting, errors validation and content assist, the expression editor has been implemented using Xtext framework. This Eclipse modeling project is widely used in order to provide an easy way to develop programming languages and domain specific languages. We wrote our Java-like grammar in order to support report that can be written with Java or Groovy based expressions. But the main goal, as mentioned, is to provide to the user a rich set of functions (that can be extended), in order to write less complicated and shorter expressions as possible. As seen, the functions are grouped in categories and every function has (at least) these two characteristics:
The function details panel is therefore created starting from the function metadata. However reflection was not good enough until we couldn't create a rich-enough function descriptor. We decided to use Java Annotations, in order to add to the functions and parameters enough information that could be later exposed to the end user. At report level, JRXML source code, what changes is the inclusion of the needed "static imports" necessary for compiling the expressions containing the Built-in functions.
More in depth details about the practical implementation of the functions library will be exposed in another tutorial where we will see also how to contribute custom new functions and how to write the necessary code to do that.
Inside Jaspersoft Studio a custom page has been created in the Preferences in order to allow the user to configure some information regarding the Expression Editor itself. The user can access this page via the menu item Window > Preferences > Jaspersoft Studio > Expression Editor, in Windows and Linux, or Jaspersoft Studio > Preferences > Jaspersoft Studio > Expression Editor, in MacOsX.
From this page the user can create his custom expressions in order to be quickly ready to use from the "User Defined Expressions" node in the Object Navigator of the editor dialog. This functionality is similar to the iReport one available in the "Report Editor" section of the iReport Preferences. The option provided to "Include static imports used for functions library" can be used in order to ensure that when saving a report no static import related to the functions library will be used. This facility was introduced to mitigate a problem when saving reports that did not contain expression functions in JRXML. Right now this kind of check on saving has been improved, so actually only the minimum imports required are added. If no function is used in one of the report expressions, no (useless) import is added.