The document discusses the implementation of a Meeting class using properties to encapsulate its attributes like date, subject, and attendance. It shows how to define properties for the class, set and get property values, add change listeners to properties, and bind properties to UI elements for automatic synchronization. It also provides examples of using the property-based Meeting class for serialization, database storage via ORM, and automatic UI generation.
2. public class Meeting {
private Date when;
private String subject;
private int attendance;
public Date getWhen() {
return when;
}
public String getSubject() {
return subject;
}
public int getAttendance() {
return attendance;
}
public void setWhen(Date when) {
this.when = when;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setAttendance(int attendance) {
this.attendance = attendance;
}
}
Classic Properties
Understanding Properties
3. public class Meeting {
private Date when;
private String subject;
private int attendance;
public Date getWhen() {
return when;
}
public String getSubject() {
return subject;
}
public int getAttendance() {
return attendance;
}
public void setWhen(Date when) {
this.when = when;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setAttendance(int attendance) {
this.attendance = attendance;
}
}
Classic Properties
4. public class Meeting implements PropertyBusinessObject {
public final Property<Date,Meeting> when = new Property<>("when", Date.class);
public final Property<String,Meeting> subject = new Property<>("subject");
public final IntProperty<Meeting> attendance = new IntProperty<>("attendance");
private final PropertyIndex idx = new PropertyIndex(this, "Meeting", when,
subject, attendance);
@Override
public PropertyIndex getPropertyIndex() {
return idx;
}
}
New Properties
5. Meeting meet = new Meeting();
meet.setSubject("My Subject");
Log.p(meet.getSubject());
Usage
Meeting meet = new Meeting();
meet.subject.set("My Subject");
Log.p(meet.subject.get());
10. Seamless Serialization
// register once in the init(Object) method
new Meeting().getPropertyIndex().registerExternalizable();
// writes the object using implicit externalizable interface
writeObjectToStorage("MyMeeting", meeting);
// Loads an object instance from a storage entry
Meeting readContact = (Meeting)readObjectFromStorage("MyMeeting");
11. ORM - Database/SQL Mapping
Meeting m = new Meeting();
Database db = Display.getInstance().openOrCreate("Meeting.db");
SQLMap sm = SQLMap.create(db);
// we'll need to add a Long property id field to get auto increment
sm.setPrimaryKeyAutoIncrement(m, m.id);
sm.createTable(m);
// we can then do standard CRUD operations:
sm.insert(myMeeting);
sm.update(myMeeting);
sm.delete(myMeeting);
List<PropertyBusinessObject> meetings =
sm.select(new Meeting(), null, true, 1000, 0);
for(PropertyBusinessObject cc : contacts) {
Meeting currentMeeting = (Meeting)cc;
// ...
}
12. UI Binding & Auto Generation
UiBinding uib = new UiBinding();
// changes to subject will update the field and visa versa
uib.bind(subjectTextField, myMeeting.subject);
// Creates a container that allows us to edit the
// meeting content
Form current = new Form("Meeting", BoxLayout.y());
InstantUI iui = new InstantUI();
current.add(iui.createEditUI(new Meeting(), true));
current.show();
13. UI Binding & Auto Generation
UiBinding uib = new UiBinding();
// changes to subject will update the field and visa versa
uib.bind(subjectTextField, myMeeting.subject);
// Creates a container that allows us to edit the
// meeting content
Form current = new Form("Meeting", BoxLayout.y());
InstantUI iui = new InstantUI();
current.add(iui.createEditUI(new Meeting(), true));
current.show();
14. UI Binding & Auto Generation
UiBinding uib = new UiBinding();
// changes to subject will update the field and visa versa
uib.bind(subjectTextField, myMeeting.subject);
// Creates a container that allows us to edit the
// meeting content
Form current = new Form("Meeting", BoxLayout.y());
InstantUI iui = new InstantUI();
current.add(iui.createEditUI(new Meeting(), true));
current.show();
Thank You!