To display a first generic user interface, you simply need a pure Java bean (a “POJO” if you like that term).
package quickstart.hello; public class Car { String licenseNumber; Brand brand; int mileage;
public String getLicenseNumber() { return licenseNumber; } public void setLicenseNumber(String ln) { this.licenseNumber = ln; } public Brand getBrand() { return brand; } public void setBrand(Brand brand) { this.brand = brand; } public int getMileage() { return mileage; } public void setMileage(int mileage) { this.mileage = mileage; }
@Override public String toString() { return licenseNumber; } } |
Although it doesn't make much sense yet, you may immediately bring a Car editing mask on the screen by the following command:
java gengui.infonode.RootFrame quickstart.hello.Car
Clicking on the Car icon causes the following screen to come up:
The icon click caused the framework to instanciate a Car and visualize it in a straight-forward way without a single line of GUI code implementation. Clicking on Car a second time creates another Car object displayed in a second window. The two masks allow to display and enter data for the two cars now.
The main routine of the RootFrame class accepts only the names of classes with default constructors which therefore can be instanciated from scratch when pressing an appropriate button in the main menu. The constructor of RootFrame also allows passing already instantiated objects rather than classes. Some other parameters are supported as well (check the Javadocs if you want to know more) but most of the application configuration is placed in the file gengui.properties.
The windows are initially stacked on top of each other, but the RootFrame allows to rearrange the windows by clicking the title bar and drag them around. You may as well undock the windows from the root frame - either by the buttons in the upper right corner or by dragging a sub window out of the main window.
Type a value into the input field License Number and leave the field by pressing the Tab key. You will see that the window's title bar now displays the entered license number. What happened in fact is that leaving the field caused the framework to automatically update the appropriate Car's property with the input value. Every object's update causes an immediate update of its graphical representation. Now guess what the window title is made of: it is the result of the object's toString() method, so you see the license number there as well.
Click the Mileage field, clear the initially displayed 0 value, and leave the field by pressing the Tab key. You will see the field displayed in red with an error icon in the upper right corner as in the following screen shot:
Moving the mouse over the error icon shows an error message that the field expects an input and must not be empty. An empty field is interpreted as a null value by the framework. But as the mileage property is defined with type int, a null value is not allowed. The property type also implies some edit constraints. E.g. you can't type anything else but digits and not more than 10 of them.
What you just got to know is the construction of UIs following the so-called Naked Objects architecture approach (see [NOA]). The idea is that a clean object-oriented design of domain objects (like the Car class) is a suitable basis for an object-oriented UI for these objects. The UI is automatically derived from the domain object definition - either by generic or generative techniques. The gengui framework uses a combination of both. The Naked Objects concept is probably the fastest way to produce UIs. However, it comes with a few tricky challenges which were very hard to master when the idea was publically demonstrated for the first time at the OOPSLA conference in 2001. But times have changed and brought new live to this approach.
Before you go on, the following screen shots should clarify the most important question for beginners: Is a Naked Objects architecture also a serious option for professional applications or will it fail outside the minimalistic examples of this manual?
It will definitely work! Although the framework didn't appear open-source before 2014, it is already in use for years. So the official, publically available 1.0 open-source release is already a stable version which you can build rich UI applications for various purposes from. In general it is worth to know that the framework was originally developed in an enterprise-world with a strong relation to customer relationship management. gengui is especially useful for form-oriented UIs. You may enrich any UI by individual graphical representations of domain objects (or parts of them) but this leads to typical MVC programming without the tremendous efficiency boost of the Naked Objects approach. Form-based UIs is what gengui is perfect for.
Created with the Personal Edition of HelpNDoc: Free EPub and documentation generator