-
Notifications
You must be signed in to change notification settings - Fork 5
Presentation Model
The presentation model is the logical part of the user interface. It is a tree-like combination of presentation model components. It represents the state of your application's user interface in a manner that is independent from a concrete GUI framework like Swing or SWT.
Let's see how to create the presentation model for the following login dialog (see class Login_LoginDialog).
Create a new class named Login_LoginPM. Give the source file the following contents:
public class LoginPM extends AbstractPM {
TextPM username = new TextPM();
TextPM password = new TextPM();
OperationPM login = new OperationPM();
public LoginPM() {
username.setMandatory(true);
password.setMandatory(true);
PMManager.setup(this);
}
@Operation
public void login() {
System.out.println(
"sending username="
+username.getText()
+", password="
+password.getText());
}
@Validation(path="login")
public boolean isLoginValid() {
return username.isValid()
&& password.isValid();
}
}
This simple class is the root node of the presentation model for the LoginDialog. It is a subclass of AbstractPM which implements the PresentationModel interface.
This class defines 3 properties: username, password and login. These three fields are instances of PresentationModel. They will be detected by the PMManager (see PMManager.setup( this)) and can be bound to view components. The fields username and password are instances of TextPM. This is the standard presentation model for text values (java.lang.String). Both fields are configured as mandatory which tells Beanfabrics to mark them as invalid when they contain no value. The field login is an instance of OperationPM which is the standard presentation model for an action that can be invoked from the GUI.
This class also defines two methods: login() and isLoginValid(). The login() method is annoteded with @Operation to tell the PMManager to bind it as an ExecutionMethod to the login field. This method will be called when the user clicks on the "Login" button. The isLoginValid() method is annotated with @Validation to tell the PMManager to bind it as an ValidationRule to the login field. This method will be called whenever this presentation model changes. The result defines if this operation is enabled or not.