The EntityEditModel interface defines the CRUD business logic used by the EntityEditPanel class when entities are being edited. The EntityEditModel works with a single entity instance, which can be retrieved and set via the EntityEditor instance accessible via the editor() method. EntityEditor exposes a number of methods for manipulating as well as querying the state of the entity being edited.
public class CustomerEditModel extends SwingEntityEditModel {
public CustomerEditModel(EntityConnectionProvider connectionProvider) {
super(Customer.TYPE, connectionProvider);
}
}
EntityConnectionProvider connectionProvider =
EntityConnectionProvider.builder()
.domainType(Store.DOMAIN)
.user(User.parse("scott:tiger"))
.clientType("StoreMisc")
.build();
CustomerEditModel editModel = new CustomerEditModel(connectionProvider);
EntityEditor editor = editModel.editor();
editor.value(Customer.ID).defaultValue()
.set(() -> UUID.randomUUID().toString());
//sets the defaults
editor.defaults();
//set the values
editor.value(Customer.FIRST_NAME).set("Björn");
editor.value(Customer.LAST_NAME).set("Sigurðsson");
editor.value(Customer.ACTIVE).set(true);
//inserts and returns the inserted entity
Entity customer = editModel.insert();
//modify some values
editor.value(Customer.FIRST_NAME).set("John");
editor.value(Customer.LAST_NAME).set("Doe");
//updates and returns the updated entity
customer = editModel.update();
//deletes the active entity
editModel.delete();