Exploiting Runtime User Interfaces
Abstract
This paper describe the Merlin software, a first Java runtime GUI generator that aims to produce a completeness CRUD user interfaces from a self-contained domain models.
Keywords
Model-based, GUI, generator, java, user interface ACM Classification Keywords
H5.2 Information interfaces and presentation (e.g. HCI): User Interfaces Management Systems (UIMS). D1.2 Programming Techniques: Automatic
Programming.
D2.13 Software Engineering: Domain Engineering; Reuse Models.
Introduction
After 30 years of research, the automatic generation of the User Interfaces (UI) remains like an instigate challenge. Although the User Interfaces Management Systems (UIMS) has been expanded to a well known Model-Based User Interface Development Environments (MB-UIDE), many difficulties still present in this area [13].
Copyright is held by the author/owner(s). CHI 2008, April 5 – April 10, 2008, Florence, Italy ACM 978-1-60558-012-8/08/04.
First Author Mrack, Marcelo. 3Layer Tenologia. Porto Alegre, Brazil [email protected]
Not only proprietary languages or special formalisms are problems, but a wide range of models associated to a complicated and massive number of configurations came to invalidating the adoption of this emerging technology in professional scenarios [12].
Starting from a smaller project launched in 2002 [5], the software called Merlin is an open source initiative that aims to minimize these problems. With three years of research at master degree level [6] and a many positive community feedbacks [8, 9], the current implementation has a well defined architecture and is being prepared for a commercial version that can be available in 2010.
The following sections explain the basic ideas in the Merlin and exposes the future directions of the project. Characteristics
Although many further attributes still present, the main characteristics in Merlin are:
Focus on CRUD interfaces: Since the Create, Retrieve, Update and Delete (CRUD) interfaces cover 18 to 30% of any database application [5], the framework focus on full automation of these IU. Reuse of standards: Focused in a commercial teams, many industry standards are supported. See [6] for more details.
Runtime UI generation: Avoiding any type of code production, all generation process occur at runtime. Simple interfaces, like the example below, can be produced in order of 200ms to 400ms in a medium PC. If multithreading and caching techniques are used,
the final process does not have differences if compared to a normal (manual) programming.
Self-contained models: Using annotations [2], the only dependency is a compiled version of the persistent classes application (the .class file), which is always present in any case.
Agents for binding: With an exclusive and extended implementation of Eiffel Agents [4], all configurations can be performed without syntax level dependencies.
Textual assistance edition: As tendency in moderns IDE (e.g. Eclipse and Netbeans), all configurations are done by enhanced and embedded text editors. Neither visual tool or wizard are used. Automatic and customizable layout: Looking for full automation, the layout of the IU controls is
automatically. If customizations are needed,
annotations, renderers or template files can be used. Historical configuration: Using the Configuration by Exception (CBE) premise, the system computes the historical developments an infer new results, be exactly or by approximation. If the result are not good, the developer assign the expected result using the respective annotation. This information go to the historical mechanism that, using average hits, computes new values for the next generation. General architecture
Merlin is a typical MB-UIDE that, although be focused in a full automation of CRUD interfaces, can be used like an assistance driving tool. It is possible due to a multi-layered architecture, that can be expressed in ways of its components:
Models: Acting as essential parts of any MB-UIDE [10, 13], these elements stores all information needed to generation process. Merlin support five types of model [6]. The first, and unique mandatory, is a Domain Model, represented by a simple Java class. Around it, four optional models coexist. The
Presentation Model, with Abstract (AIO) or Concrete Information Objects (CIO) [13], contains elements to refine appearance and layout of the UI. The Task Model, contain or indicate the actions (business rules) of the final system. The Dialog Model, connect the models above and, if necessary, add some restrictions using constraints objects in the form of Object Constraint Language (OCL) [11] or Java Expression Language (EL) [3]. The last model is the User Model, used when specific UI must be created for some user roles or under special conditions.
Annotations: Java Annotations [2] are used to compound and refine all application models. Essentially, they are decorators (identified by the @ character) over the Domain Model. Like them are compiled with the final application classes, a self-contained structured is formed. This is an important architectural difference upon others MB-UIDE.
Renderers: Renderers are pluggable algorithms responsible for translate model information into the UI components. Merlin come with a basic implementation for a Java Swing GUI toolkit, but can be extended easily for other platforms, including web-based frameworks.
Runtime engine: An extensible and reusable group of classes and interfaces that represent the core of the system. At runtime, it receive as input an annotated domain model and produce, with the
renderers assistance, a complete CRUD interface. For most purpose uses, a simple call to a
createIU(aDomainObject) method is sufficient.
Development process
The development process with Merlin consist in two phases, that accomplish with any evolutional
methodology and advocates the Domain-Driven Design (DDD) premises [1].
In first phase, the developer creates a domain model of the application (e.g. the persistent classes of the application), using any approach. After it, the generator can be used without any problem. The resultant IU at this moment can be poor, but is functional for most purpose uses.
Using annotations and, eventually, creating new renderers, the domain model is enhanced, forming the others models, if necessary. These tasks can be executed many times until the expected UI appear. Like Java support the runtime class reloading, this process can be performed with the final application in use. It is an interesting feature for prototyping or visualizer tools, for example.
Simple example
This section show a simple use of Merlin. The example starts with a generated UI and, then, the respective annotated domain model and main code application are presented.
figure 1. A simple user interface generated by Merlin.
The respective Domain Model for IU on figure 1 is: //Sexo.java
1
public enum Sexo { 2
NAO_DECLARADO, MASCULINO, FEMININO 3 } 4 5 //Pessoa.java 6
public class Pessoa { 7
8
@Agent(event = { "focusLost" }, action = 9
{ "proposeEmail" }) 10
@NotNull 11
String nome = "marcelo"; 12
13
public Sexo sexo = Sexo.MASCULINO; 14
15
This screenshot show the resultant CRUD interface for an simple domain model. At the top, the message pane area, with useful messages for the user. These messages are automatically generated and support internationalization transparently. At the center, in a simple tabular layout, the controls (at right) and the respective label descriptors (at left). Note the orthographical correctness of the label “Observações” (line 41). It is possible due to integration of the Merlin with native orthographical correctors (if available under runtime environment). The types of the controls are functions of the associated default computed renderers (line 14) or explicit annotations (line 38) in the class attributes. Some presentation properties, like colors, position or contents are functions of other annotations (line 40). Finally, note “Descrição” field, disabled due to a dependency agent for “Observações” control (line 39).
@Agent(property = { 16 "foreground=Color.blue" }, binder = 17 DateToTextComponent.class) 18
Date dataDeNascimento = new Date(1977-19 1900,9,02); 20 21 } 22 23 //Cliente.java 24 @Caption("Cadastro de Clientes") 25
public class Cliente extends Pessoa { 26 27 @Agent( 28 event = { "focusLost" }, 29 action = { "isVip" } 30 ) 31 @Caption("Salário (R$)") 32 int salario; 33 34 @Order(after = "observacoes") 35 String descricao; 36 37 @RenderAs(JCheckBox.class) 38 @Dependence("descricao") 39 @Agent(property = { "selected=true" }) 40 String observacoes; 41 42 @Dependence(":all") 43 @Order(Order.FIRST) 44 @Agent(property = { "selected=true;" }) 45 boolean ativo; 46 47 @RenderAs(value = JTextField.class, 48 binder = BooleanToTextComponentBinder.class) 49 @Order(LAST) 50
boolean vip = true; 51 52 @Order(after = "nome") 53 @NotNull 54 @Length(min=12) 55 String email; 56 57
public void isVip() { 58
59
JTextField salario = (JTextField) 60
MerlinUtil.getInstance().getControle("Cliente.s 61
alario"); 62
JTextField vip = (JTextField) 63 MerlinUtil.getInstance().getControle("Cliente.v 64 ip"); 65 66 if (new 67 Long(salario.getText()).longValue() > 1500) { 68 vip.setText("SIM"); 69 } else { 70 vip.setText("NÃO"); 71 } 72 } 73 74
public void proposeEmail() { 75
76
JTextField nome = (JTextField) 77
MerlinUtil.getInstance().getControle("Cliente.n 78
ome"); 79
JTextField email = (JTextField) 80 MerlinUtil.getInstance().getControle("Cliente.e 81 mail"); 82 83 email.setText(nome.getText() + 84 "@merlin.com"); 85 } 86 } 87
Once de domain model is done, the only necessary task is create the code of the client application, like it:
//TesteMinimoDoMerlin.java 1
public class TesteMinimoDoMerlin { 2
3
private static IMerlin merlin = 4
Factory.getMerlin(Implementation.SWING); 5
6
public static void main(String[] args) { 7
JPanel crud = (JPanel) merlin.createIU(new 8
Cliente(), true); 9
JFrame frame = new JFrame("Simple user 10
interface with Merlin"); 11
frame.add(crud,BorderLayout.CENTER); 12
showIU(frame); //put buttons and show IU 13
} 14
} 15
In the final application, a Merlin instance is declared, pointing to a specific GUI toolkit, in this case, a Java Swing. After this, a simple call to createUI method, passing the given domain model instance, retrieve a complete CRUD panel. This panel is inserted on a generic form, and then, showed to the user. Current State & Future Works
At this moment, the project contain a well defined architecture and several examples with an unstable code, it because most effort was conduced to “prove” the underling concepts. A wide range of studies has been performed and the scope of work has delimited. Code, documentation and discussions can be found at
http://merlin.dev.java.net (archival) and
http://code.google.com/p/merlin (active).
Three main areas would be explored in the next four years. The first is the master-details UI, where some initial work has been done [7]. As of 2009, the historical configuration mechanism would be explored at PhD level. And finally, like practical task, a
commercial (but cost-free) release would be available in first half of 2010.
Acknowledgments
Thanks for the maintainer 3Layer Tecnologia
(www.3layer.com.br), a small brazilian softwarehouse
focused in “revolutionary” technologies for Java. References
[1] EVANS, E. Domain-Driven Design – Tackling Complexity in the Hearth of Software. California, EUA, 2003.
[2] JAVA COMMUNUITY PROCESS (JCP). JSR 175 - A Metadata Facility for the Java™ Programming Language (Java Annotations), 2004.
[3] JAVA COMMUNUITY PROCESS (JCP). JSR 252 – JavaServer Faces 1.2, 2006.
[4] MEYER, B. Eiffel : The Language. 1.ed. Prentice Hall, 1991.
[5] MOREIRA, D., MRACK, M. Sistemas Dinâmicos Baseados em Metamodelos. University of Santa Cruz do Sul, Santa Cruz do Sul, Brazil, 2003.
[6] MRACK, M. Geração Automática e Assistida de Interfaces de Usuário. Federal University of Rio Grande do Sul, Porto Alegre, Brazil, 2007.
[7] MRACK, M. Interfaces de Usuário em Tempo de Execução. Federal University of Rio Grande do Sul, Porto Alegre, Brazil, 2005.
[8] MRACK, M. Merlin : Um Novo Horizonte na Criação das Telas de Cadastro. 8 Fórum Internacional de Software Livre (FISL), Porto Alegre, Brazil, 2007. [9] MRACK, M.; MOREIRA, A. F.; PIMENTA, M. S.; Merlin: Interfaces CRUD Em Tempo de Execução. XX Simpósio Brasileiro de Engenharia de Software (SBES’06), Florianópolis, Brazil, 2006.
[10] MYERS, A. B. User Interface Software Tools. ACM Transactions on Computer-Human Interaction (TOCHI’95), New York, v. 3, n.1, p. 64-103, 1995. [11] OBJECT MANAGEMENT GROUP (OMG). Object Constraint Language Specification, version 2.0.
http://www.omg.org/cgi-bin/apps/doc?formal/06-05-01.pdf.
[12] PUERTA, A., ANGEL, R.; ERIKSSON, H., GENNARY, J. H., MUSEN, M. Beyond Data Models for Automated User Interface Generation. Stanford University, California, USA, 1996.
[13] SCHULUNGBAUM, E. Model-based User Interface Software Tools Current State of Declarative Models, 1996.